Advertisement
Guest User

login_api

a guest
Feb 9th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1.     public function login($data)
  2.     {
  3.         $username = $data['username'];
  4.         $password = $data['password'];
  5.  
  6.         $executive = Executive::whereRaw("username LIKE '$username' AND password='$password'")->first();
  7.  
  8.         if(is_null($executive)) {
  9.             return response()->json([
  10.                 'code' => '403',
  11.                 'app_message' => 'login unsuccessful, credentials mismatch'
  12.             ]);
  13.         }
  14.  
  15.         else {
  16.             $executive->access_token = str_random(50);
  17.             $executive->access_time = Carbon::now();
  18.             $executive->save();
  19.  
  20.             return response()->json([
  21.                 'code' => '403',
  22.                 'app_message' => 'login success',
  23.                 'access_token' => $executive->access_token,
  24.                 'access_time' => $executive->access_time
  25.             ]);
  26.         }
  27.  
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement