Пример #1
0
 /**
  * Attempt to login the specified user.
  *
  * @return \Illuminate\Http\Response
  */
 public function postLogin()
 {
     $remember = Binput::get('rememberMe');
     $input = Binput::only(['email', 'password']);
     $rules = UserRepository::rules(array_keys($input));
     $rules['password'] = '******';
     $val = UserRepository::validate($input, $rules, true);
     if ($val->fails()) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         $throttle = Credentials::getThrottleProvider()->findByUserLogin($input['email']);
         $throttle->check();
         Credentials::authenticate($input, $remember);
     } catch (WrongPasswordException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'Your password was incorrect.');
     } catch (UserNotFoundException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'That user does not exist.');
     } catch (UserNotActivatedException $e) {
         if (Config::get('credentials::activation')) {
             return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'You have not yet activated this account.');
         } else {
             $throttle->user->attemptActivation($throttle->user->getActivationCode());
             $throttle->user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
             return $this->postLogin();
         }
     } catch (UserSuspendedException $e) {
         $time = $throttle->getSuspensionTime();
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', "Your account has been suspended for {$time} minutes.");
     } catch (UserBannedException $e) {
         return Redirect::route('account.login')->withInput()->withErrors($val->errors())->with('error', 'You have been banned. Please contact support.');
     }
     return Redirect::intended(Config::get('credentials.home', '/'));
 }
Пример #2
0
 /**
  * Suspend an existing user.
  *
  * @param int $id
  *
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  *
  * @return \Illuminate\Http\Response
  */
 public function suspend($id)
 {
     try {
         $throttle = Credentials::getThrottleProvider()->findByUserId($id);
         $throttle->suspend();
     } catch (UserNotFoundException $e) {
         throw new NotFoundHttpException('User Not Found', $e);
     } catch (UserSuspendedException $e) {
         $time = $throttle->getSuspensionTime();
         return Redirect::route('users.suspend', ['users' => $id])->withInput()->with('error', "This user is already suspended for {$time} minutes.");
     } catch (UserBannedException $e) {
         return Redirect::route('users.suspend', ['users' => $id])->withInput()->with('error', 'This user has already been banned.');
     }
     return Redirect::route('users.show', ['users' => $id])->with('success', 'The user has been suspended successfully.');
 }