Advertisement
onzulin

clase para loguearme

Nov 5th, 2014
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. class AuthController extends Auth
  2. {
  3.     public function loginUser()
  4.     {
  5.         $username = Request::get('username');
  6.         $password = Request::get('password');
  7.         $error = false;
  8.         $passwordhash =  password = password_hash($password,  PASSWORD_BCRYPT,  ['cost' => 12]);
  9.         if ( password_verify ($password , $passwordhash ))
  10.         {
  11.             $userdata = array(
  12.                 'username' => $username,
  13.                 'password' => $password
  14.             );
  15.  
  16.             $error = true;
  17.             $user = array();
  18.  
  19.             if (Auth::attemp($userdata)) {
  20.                 $error = false;
  21.                 $user = array(
  22.                     'id' => Auth::user()->id,
  23.                     'username' => Auth::user()->username
  24.                 );
  25.             }
  26.  
  27.             return Response::json(array(
  28.                 'error' => $error,
  29.                 'user' => $user
  30.             ), 200);
  31.         }
  32.         else
  33.         {
  34.             return Response::json(array(
  35.                 'error' => $error
  36.             ), 400);
  37.         }
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement