/**
  * 动作:登录
  * @return Response
  */
 public function postSignin()
 {
     // 凭证
     $credentials = array('email' => Input::get('email'), 'password' => Input::get('password'));
     // 是否记住登录状态
     $remember = Input::get('remember-me', 0);
     // 验证登录
     if (Auth::validate($credentials)) {
         // 验证成功,确认是否已经激活
         $user = Auth::getLastAttempted();
         if (is_null($user->activated_at)) {
             // 未激活,跳回
             return Redirect::back()->withInput()->withErrors(array('attempt' => '“邮箱”未激活,请打开您邮箱中的激活邮件,完成激活操作。'));
         }
         // 已激活,手动登录,跳回之前被拦截的页面
         Auth::login($user, $remember);
         return Redirect::intended();
     } else {
         // 登录失败,跳回
         return Redirect::back()->withInput()->withErrors(array('attempt' => '“邮箱”或“密码”错误,请重新登录。'));
     }
 }
Example #2
0
 /**
  * @param array   $credentials
  * @param bool    $remember
  * @param bool    $login
  * @param integer $appId
  *
  * @return bool
  * @throws \Exception
  */
 public static function authenticate(array $credentials, $remember = false, $login = true, $appId = null)
 {
     if (\Auth::attempt($credentials, false, false)) {
         $user = \Auth::getLastAttempted();
         static::checkRole($user->id);
         if ($login) {
             $user->last_login_date = Carbon::now()->toDateTimeString();
             $user->confirm_code = 'y';
             $user->save();
             Session::setUserInfoWithJWT($user, $remember, $appId);
         }
         return true;
     } else {
         return false;
     }
 }