예제 #1
0
 public function store()
 {
     $input = Input::all();
     $validator = Validator::make($input, array('username' => array('required'), 'password' => array('required')));
     if ($validator->fails()) {
         throw new NotAuthorizedException();
     }
     $creds = call_user_func($this->credentialsFormatter, $input['username'], $input['password']);
     $token = $this->driver->attempt($creds);
     if (!$token) {
         throw new NotAuthorizedException();
     }
     $user = $this->driver->user($token);
     $this->events->fire('auth.token.created', array($user, $token));
     $serializedToken = $this->driver->getProvider()->serializeToken($token);
     return Response::json(array('token' => $serializedToken, 'user' => $user->toArray()));
 }