Example #1
0
 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;
 }
Example #2
0
 /**
  * Authenticate Routes
  *
  */
 public function authenticate()
 {
     $app = Slim::getInstance();
     $token = $app->request->headers->get('Authorization');
     $response = $app->response();
     $response->header("Content-Type", "application/json");
     if (!isset($token)) {
         return Auth::deny_access("Authorization Token is not set. Please login");
     }
     //Get user by token;
     try {
         $token = htmlentities(trim($token));
         $user = User::findByToken($token);
         if ($user->token_expire < date('Y-m-d H:i:s')) {
             return Auth::deny_access("Authorization Token has expired. Please login again.");
         }
         $user->token_expire = date('Y-m-d H:i:s', strtotime('+1 hour'));
         $user->save();
     } catch (ModelNotFoundException $e) {
         return Auth::deny_access("Authorization Token is invalid.");
     }
 }
Example #3
0
 public static 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];
 }
Example #4
0
 /**
  * Return User Model where the token is given.
  *
  * @param  string $token
  *
  * @throws \Bendozy\ORM\Exceptions\ModelNotFoundException
  *
  * @return User
  */
 public static function findByToken($token)
 {
     return User::where('token', $token);
 }