@@ -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 | */ |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | $tokenId = base64_encode(mcrypt_create_iv(32)); |
| 64 | 64 | $issuedAt = time(); |
| 65 | - $notBefore = $issuedAt; //Adding 10 seconds |
|
| 65 | + $notBefore = $issuedAt; //Adding 10 seconds |
|
| 66 | 66 | $expire = $notBefore + (float) strtotime('+30 days'); // Adding 30 days expiry date |
| 67 | 67 | $serverName = 'http://sweatemoji.com/api'; // Retrieve the server name |
| 68 | 68 | |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | * Create the token params as an array |
| 72 | 72 | */ |
| 73 | 73 | $data = [ |
| 74 | - 'iat' => $issuedAt, // Issued at: time when the token was generated |
|
| 75 | - 'jti' => $tokenId, // Json Token Id: an unique identifier for the token |
|
| 76 | - 'iss' => $serverName, // Issuer |
|
| 77 | - 'nbf' => $notBefore, // Not before |
|
| 78 | - 'exp' => $expire, // Expire |
|
| 74 | + 'iat' => $issuedAt, // Issued at: time when the token was generated |
|
| 75 | + 'jti' => $tokenId, // Json Token Id: an unique identifier for the token |
|
| 76 | + 'iss' => $serverName, // Issuer |
|
| 77 | + 'nbf' => $notBefore, // Not before |
|
| 78 | + 'exp' => $expire, // Expire |
|
| 79 | 79 | |
| 80 | - 'dat' => $userData, // User Information retrieved from the database |
|
| 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 | ); |
@@ -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 | { |
@@ -74,6 +74,9 @@ |
||
| 74 | 74 | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | + /** |
|
| 78 | + * @param string $keywords |
|
| 79 | + */ |
|
| 77 | 80 | public function createEmojiKeywords($emoji_id, $keywords) |
| 78 | 81 | { |
| 79 | 82 | if ($keywords) { |
@@ -232,7 +232,7 @@ |
||
| 232 | 232 | foreach ($emojis as $key => &$value) { |
| 233 | 233 | $value['created_by'] = $value['created_by']['firstname'].' '.$value['created_by']['lastname']; |
| 234 | 234 | $value['category'] = $value['category']['category_name']; |
| 235 | - $value['keywords'] = array_map(function ($key) { return $key['keyword_name']; }, $value['keywords']); |
|
| 235 | + $value['keywords'] = array_map(function($key) { return $key['keyword_name']; }, $value['keywords']); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | return $emojis; |
@@ -254,6 +254,8 @@ |
||
| 254 | 254 | |
| 255 | 255 | /** |
| 256 | 256 | * This method authenticate and return user id |
| 257 | + * @param Request $request |
|
| 258 | + * @param Response $response |
|
| 257 | 259 | */ |
| 258 | 260 | public function getCurrentUserId($request, $response) |
| 259 | 261 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @return json $response |
| 49 | 49 | * |
| 50 | 50 | */ |
| 51 | - $this->slimApp->get('/', function (Request $request, Response $response) { |
|
| 51 | + $this->slimApp->get('/', function(Request $request, Response $response) { |
|
| 52 | 52 | return $response->withStatus(404); |
| 53 | 53 | |
| 54 | 54 | }); |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @return json $response |
| 64 | 64 | * |
| 65 | 65 | */ |
| 66 | - $this->slimApp->post('/', function (Request $request, Response $response) { |
|
| 66 | + $this->slimApp->post('/', function(Request $request, Response $response) { |
|
| 67 | 67 | return $response->withStatus(404); |
| 68 | 68 | |
| 69 | 69 | }); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return json $response |
| 79 | 79 | * |
| 80 | 80 | */ |
| 81 | - $this->slimApp->post('/auth/login', function (Request $request, Response $response) use ($auth) { |
|
| 81 | + $this->slimApp->post('/auth/login', function(Request $request, Response $response) use ($auth) { |
|
| 82 | 82 | return $auth->loginUser($request, $response); |
| 83 | 83 | |
| 84 | 84 | }); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | */ |
| 98 | 98 | |
| 99 | - $this->slimApp->get('/auth/logout', function (Request $request, Response $response, $args) use ($auth) { |
|
| 99 | + $this->slimApp->get('/auth/logout', function(Request $request, Response $response, $args) use ($auth) { |
|
| 100 | 100 | return $auth->logoutUser($request, $response, $args)->withStatus(200); |
| 101 | 101 | |
| 102 | 102 | })->add(new Middleware()); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | * @return json $response |
| 112 | 112 | * |
| 113 | 113 | */ |
| 114 | - $this->slimApp->get('/emojis', function (Request $request, Response $response) use ($emoji) { |
|
| 114 | + $this->slimApp->get('/emojis', function(Request $request, Response $response) use ($emoji) { |
|
| 115 | 115 | return $emoji->listAllEmoji($response); |
| 116 | 116 | |
| 117 | 117 | }); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @return json $response |
| 127 | 127 | * |
| 128 | 128 | */ |
| 129 | - $this->slimApp->get('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
| 129 | + $this->slimApp->get('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
| 130 | 130 | return $emoji->getSingleEmoji($response, $args); |
| 131 | 131 | |
| 132 | 132 | }); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @return json $response |
| 142 | 142 | * |
| 143 | 143 | */ |
| 144 | - $this->slimApp->post('/emojis', function (Request $request, Response $response) use ($emoji) { |
|
| 144 | + $this->slimApp->post('/emojis', function(Request $request, Response $response) use ($emoji) { |
|
| 145 | 145 | return $emoji->createEmoji($request, $response); |
| 146 | 146 | |
| 147 | 147 | })->add(new Middleware()); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return json $response |
| 161 | 161 | * |
| 162 | 162 | */ |
| 163 | - $this->slimApp->put('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
| 163 | + $this->slimApp->put('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
| 164 | 164 | return $emoji->updateEmojiByPutVerb($request, $response, $args); |
| 165 | 165 | |
| 166 | 166 | })->add(new Middleware()); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | * @return json $response |
| 178 | 178 | * |
| 179 | 179 | */ |
| 180 | - $this->slimApp->patch('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
| 180 | + $this->slimApp->patch('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
| 181 | 181 | return $emoji->updateEmojiByPatchVerb($request, $response, $args); |
| 182 | 182 | |
| 183 | 183 | })->add(new Middleware()); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * @return json $response |
| 195 | 195 | * |
| 196 | 196 | */ |
| 197 | - $this->slimApp->delete('/emojis/{id}', function (Request $request, Response $response, $args) use ($emoji) { |
|
| 197 | + $this->slimApp->delete('/emojis/{id}', function(Request $request, Response $response, $args) use ($emoji) { |
|
| 198 | 198 | return $emoji->deleteEmoji($request, $response, $args); |
| 199 | 199 | |
| 200 | 200 | })->add(new Middleware()); |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function createUser() |
| 27 | 27 | { |
| 28 | - if (! Capsule::schema()->hasTable('users')) { |
|
| 29 | - Capsule::schema()->create('users', function ($table) { |
|
| 28 | + if (!Capsule::schema()->hasTable('users')) { |
|
| 29 | + Capsule::schema()->create('users', function($table) { |
|
| 30 | 30 | $table->increments('id'); |
| 31 | 31 | $table->string('firstname'); |
| 32 | 32 | $table->string('lastname'); |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function createKeyword() |
| 45 | 45 | { |
| 46 | - if (! Capsule::schema()->hasTable('keywords')) { |
|
| 47 | - Capsule::schema()->create('keywords', function ($table) { |
|
| 46 | + if (!Capsule::schema()->hasTable('keywords')) { |
|
| 47 | + Capsule::schema()->create('keywords', function($table) { |
|
| 48 | 48 | $table->increments('id'); |
| 49 | 49 | $table->integer('emoji_id'); |
| 50 | 50 | $table->string('keyword_name'); |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function createCategory() |
| 60 | 60 | { |
| 61 | - if (! Capsule::schema()->hasTable('categories')) { |
|
| 62 | - Capsule::schema()->create('categories', function ($table) { |
|
| 61 | + if (!Capsule::schema()->hasTable('categories')) { |
|
| 62 | + Capsule::schema()->create('categories', function($table) { |
|
| 63 | 63 | $table->increments('id'); |
| 64 | 64 | $table->string('category_name'); |
| 65 | 65 | $table->timestamps(); |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function createEmoji() |
| 75 | 75 | { |
| 76 | - if (! Capsule::schema()->hasTable('categories')) { |
|
| 77 | - Capsule::schema()->create('emojis', function ($table) { |
|
| 76 | + if (!Capsule::schema()->hasTable('categories')) { |
|
| 77 | + Capsule::schema()->create('emojis', function($table) { |
|
| 78 | 78 | $table->increments('id'); |
| 79 | 79 | $table->string('name'); |
| 80 | 80 | $table->string('char'); |