public function register() { $app = $this->app; $request = $app->request(); $response = $app->response(); $response->headers->set('Content-Type', 'application/json'); $username = $request->params('username'); $password = $request->params('password'); if (!isset($password) || empty($password)) { $responseArray['message'] = "password not set"; $responseArray['status'] = 400; } elseif (!isset($username) || empty($username)) { $responseArray['status'] = 400; $responseArray['message'] = "username not set"; } else { $user = new User(); $user->username = $username; $user->password = md5($password); $user->save(); $responseArray['status'] = 200; $responseArray['message'] = "Registration Successful"; } $response->body(json_encode($responseArray)); return $response; }
public function logout() { $app = Slim::getInstance(); $token = $app->request->headers->get('Authorization'); $response = $app->response(); $response->header("Content-Type", "application/json"); $user = User::findByToken($token); $user->token = ""; $user->token_expire = ""; $user->save(); $responseArray['message'] = "User is successfully logged out"; $response->status(200); $response->body(json_encode($responseArray)); return $response; }
public function authenticate() { $app = $this->app; $request = $app->request(); $response = $app->response(); $response->header("Content-Type", "application/json"); if (!$request->headers->get('Authorization')) { return Auth::deny_access("Authorization Token is not set. Please login"); } else { $key = "example_key"; $this->token = $request->headers->get('Authorization'); $decoded_jwt = JWT::decode($this->token, $key, array('HS512')); $decoded_jwt = (object) $decoded_jwt; $this->expiry = $decoded_jwt->exp; $this->auth_user = User::where('username', $decoded_jwt->data->username); $this->auth_user = json_decode($this->auth_user, true); $this->auth_user = $this->auth_user[0]; return $this->auth_user['username']; } }
public function buildResult(Emoji $emoji) { return ["id" => $emoji->id, "name" => $emoji->name, "char" => $emoji->emoji_char, "category" => $emoji->category, "keywords" => explode(",", $emoji->keywords), "date_created" => $emoji->date_created, "date_modified" => $emoji->date_modified, "created_by" => User::find($emoji->created_by)->username]; }
public static function findByToken($token) { self::$user = User::where('token', $token); }