@@ -16,7 +16,6 @@ |
||
16 | 16 | * This method authenticate user and log them in if the supplied |
17 | 17 | * credentials are valid. |
18 | 18 | * |
19 | - * @param array $loginParams |
|
20 | 19 | * |
21 | 20 | * @return json jwt |
22 | 21 | */ |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $tokenId = base64_encode(mcrypt_create_iv(32)); |
65 | 65 | $issuedAt = time(); |
66 | - $notBefore = $issuedAt + 10; //Adding 10 seconds |
|
66 | + $notBefore = $issuedAt + 10; //Adding 10 seconds |
|
67 | 67 | $expire = $notBefore + (float) strtotime('+30 days'); // Adding 30 days expiry date |
68 | 68 | $serverName = $_SERVER['HTTP_HOST']; // Retrieve the server name |
69 | 69 | |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | * Create the token params as an array |
73 | 73 | */ |
74 | 74 | $data = [ |
75 | - 'iat' => $issuedAt, // Issued at: time when the token was generated |
|
76 | - 'jti' => $tokenId, // Json Token Id: an unique identifier for the token |
|
77 | - 'iss' => $serverName, // Issuer |
|
78 | - 'nbf' => $notBefore, // Not before |
|
79 | - 'exp' => $expire, // Expire |
|
80 | - 'dat' => $userData, // User Information retrieved from the database |
|
75 | + 'iat' => $issuedAt, // Issued at: time when the token was generated |
|
76 | + 'jti' => $tokenId, // Json Token Id: an unique identifier for the token |
|
77 | + 'iss' => $serverName, // Issuer |
|
78 | + 'nbf' => $notBefore, // Not before |
|
79 | + 'exp' => $expire, // Expire |
|
80 | + 'dat' => $userData, // User Information retrieved from the database |
|
81 | 81 | ]; |
82 | 82 | |
83 | 83 | $loadEnv = DatabaseConnection::loadEnv(); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $secretKey = base64_decode(getenv('secret')); |
86 | 86 | |
87 | 87 | $jwt = JWT::encode( |
88 | - $data, //Data to be encoded in the JWT |
|
88 | + $data, //Data to be encoded in the JWT |
|
89 | 89 | $secretKey, // The signing key |
90 | 90 | 'HS512' // Algorithm used to sign the token |
91 | 91 | ); |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -239,6 +239,7 @@ |
||
239 | 239 | |
240 | 240 | /** |
241 | 241 | * This method authenticate and return user id |
242 | + * @param Request $request |
|
242 | 243 | */ |
243 | 244 | public function getCurrentUserId($request) |
244 | 245 | { |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | namespace Laztopaz\EmojiRestfulAPI; |
7 | 7 | |
8 | 8 | use \Psr\Http\Message\ServerRequestInterface as Request; |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | |
262 | 262 | $userInfo = (array) $tokenInfo['dat']; |
263 | 263 | |
264 | - return $userInfo['id']; |
|
264 | + return $userInfo['id']; |
|
265 | 265 | |
266 | 266 | } |
267 | 267 |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | foreach ($emojis as $key => &$value) { |
232 | 232 | $value['created_by'] = $value['created_by']['firstname'].' '.$value['created_by']['lastname']; |
233 | 233 | $value['category'] = $value['category']['category_name']; |
234 | - $value['keywords'] = array_map(function ($key) { return $key['keyword_name']; }, $value['keywords']); |
|
234 | + $value['keywords'] = array_map(function($key) { return $key['keyword_name']; }, $value['keywords']); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | return $emojis; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $authHeader = $request->getHeader('token'); |
248 | 248 | |
249 | 249 | try { |
250 | - if (is_array($authHeader) && ! empty($authHeader)) { |
|
250 | + if (is_array($authHeader) && !empty($authHeader)) { |
|
251 | 251 | $jwtoken = $authHeader[0]; |
252 | 252 | |
253 | 253 | $secretKey = base64_decode(getenv('secret')); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | * |
13 | 13 | * @param $data |
14 | 14 | * |
15 | - * @return int $statuscode |
|
15 | + * @return string|null $statuscode |
|
16 | 16 | */ |
17 | 17 | public function createUser(array $data) |
18 | 18 | { |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function createUser() |
27 | 27 | { |
28 | - Capsule::schema()->create('users', function ($table) { |
|
28 | + Capsule::schema()->create('users', function($table) { |
|
29 | 29 | $table->increments('id'); |
30 | 30 | $table->string('firstname'); |
31 | 31 | $table->string('lastname'); |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function createKeyword() |
43 | 43 | { |
44 | - Capsule::schema()->create('keywords', function ($table) { |
|
44 | + Capsule::schema()->create('keywords', function($table) { |
|
45 | 45 | $table->increments('id'); |
46 | 46 | $table->integer('emoji_id'); |
47 | 47 | $table->string('keyword_name'); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function createCategory() |
56 | 56 | { |
57 | - Capsule::schema()->create('categories', function ($table) { |
|
57 | + Capsule::schema()->create('categories', function($table) { |
|
58 | 58 | $table->increments('id'); |
59 | 59 | $table->string('category_name'); |
60 | 60 | $table->timestamps(); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function createEmoji() |
68 | 68 | { |
69 | - Capsule::schema()->create('emojis', function ($table) { |
|
69 | + Capsule::schema()->create('emojis', function($table) { |
|
70 | 70 | $table->increments('id'); |
71 | 71 | $table->string('name'); |
72 | 72 | $table->string('char'); |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | namespace Laztopaz\EmojiRestfulAPI; |
7 | 7 | |
8 | 8 | use Dotenv\Dotenv; |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | $this->capsule->bootEloquent(); |
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Load Dotenv to grant getenv() access to |
|
53 | - * environment variables in .env file. |
|
54 | - */ |
|
55 | - public static function loadEnv() |
|
56 | - { |
|
57 | - if (!getenv('APP_ENV')) { |
|
58 | - $dotenv = new Dotenv(__DIR__.'/../../'); |
|
59 | - $dotenv->load(); |
|
60 | - } |
|
61 | - } |
|
51 | + /** |
|
52 | + * Load Dotenv to grant getenv() access to |
|
53 | + * environment variables in .env file. |
|
54 | + */ |
|
55 | + public static function loadEnv() |
|
56 | + { |
|
57 | + if (!getenv('APP_ENV')) { |
|
58 | + $dotenv = new Dotenv(__DIR__.'/../../'); |
|
59 | + $dotenv->load(); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | 'settings' => [ |
32 | 32 | 'debug' => true, |
33 | 33 | 'displayErrorDetails' => true, |
34 | - ],]); |
|
34 | + ], ]); |
|
35 | 35 | |
36 | 36 | $this->runEmojiRoute(); |
37 | 37 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @return json $response |
57 | 57 | * |
58 | 58 | */ |
59 | - $this->slimApp->get('/', function (Request $request, Response $response) { |
|
59 | + $this->slimApp->get('/', function(Request $request, Response $response) { |
|
60 | 60 | return $response->withJson(['status'], 404); |
61 | 61 | |
62 | 62 | }); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @return json $response |
72 | 72 | * |
73 | 73 | */ |
74 | - $this->slimApp->post('/', function (Request $request, Response $response) { |
|
74 | + $this->slimApp->post('/', function(Request $request, Response $response) { |
|
75 | 75 | return $response->withJson(['status'], 404); |
76 | 76 | |
77 | 77 | }); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return json $response |
87 | 87 | * |
88 | 88 | */ |
89 | - $this->slimApp->post('/auth/login', function (Request $request, Response $response) use ($auth) { |
|
89 | + $this->slimApp->post('/auth/login', function(Request $request, Response $response) use ($auth) { |
|
90 | 90 | return $auth->loginUser($request, $response); |
91 | 91 | |
92 | 92 | }); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * |
105 | 105 | */ |
106 | 106 | |
107 | - $this->slimApp->get('/auth/logout', function (Request $request, Response $response, $args) use ($auth) { |
|
107 | + $this->slimApp->get('/auth/logout', function(Request $request, Response $response, $args) use ($auth) { |
|
108 | 108 | return $auth->logoutUser($request, $response, $args)->withJson(['status'], 200); |
109 | 109 | |
110 | 110 | })->add(new Middleware()); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return json $response |
120 | 120 | * |
121 | 121 | */ |
122 | - $this->slimApp->get('/emojis', function (Request $request, Response $response) use ($emoji) { |
|
122 | + $this->slimApp->get('/emojis', function(Request $request, Response $response) use ($emoji) { |
|
123 | 123 | return $emoji->listAllEmoji($response); |
124 | 124 | |
125 | 125 | }); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * @return json $response |
135 | 135 | * |
136 | 136 | */ |
137 | - $this->slimApp->get('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
137 | + $this->slimApp->get('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
138 | 138 | return $emoji->getSingleEmoji($response, $args)->withJson(['status'], 200); |
139 | 139 | |
140 | 140 | }); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return json $response |
150 | 150 | * |
151 | 151 | */ |
152 | - $this->slimApp->post('/emojis', function (Request $request, Response $response) use ($emoji) { |
|
152 | + $this->slimApp->post('/emojis', function(Request $request, Response $response) use ($emoji) { |
|
153 | 153 | return $emoji->createEmoji($request, $response)->withJson(['status'], 200); |
154 | 154 | |
155 | 155 | })->add(new Middleware()); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return json $response |
169 | 169 | * |
170 | 170 | */ |
171 | - $this->slimApp->put('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
171 | + $this->slimApp->put('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
172 | 172 | return $emoji->updateEmojiByPutVerb($request, $response, $args); |
173 | 173 | |
174 | 174 | })->add(new Middleware()); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @return json $response |
186 | 186 | * |
187 | 187 | */ |
188 | - $this->slimApp->patch('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
188 | + $this->slimApp->patch('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
189 | 189 | return $emoji->updateEmojiByPatchVerb($request, $response, $args); |
190 | 190 | |
191 | 191 | })->add(new Middleware()); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return json $response |
203 | 203 | * |
204 | 204 | */ |
205 | - $this->slimApp->delete('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
205 | + $this->slimApp->delete('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
206 | 206 | return $emoji->deleteEmoji($request, $response, $args); |
207 | 207 | |
208 | 208 | })->add(new Middleware()); |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @author Temitope Olotin <[email protected]> |
|
4 | - * @license <https://opensource.org/license/MIT> MIT |
|
5 | - */ |
|
3 | + * @author Temitope Olotin <[email protected]> |
|
4 | + * @license <https://opensource.org/license/MIT> MIT |
|
5 | + */ |
|
6 | 6 | |
7 | 7 | namespace Laztopaz\EmojiRestfulAPI; |
8 | 8 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $auth = $this->auth; |
47 | 47 | $emoji = $this->emoji; |
48 | 48 | |
49 | - /* |
|
49 | + /* |
|
50 | 50 | * This verb returns error 404 |
51 | 51 | * |
52 | 52 | * @param $request |