/**
  * Find a user through Sentry by their login attribute,
  * such as a username or email.
  *
  * @param string $login
  *
  * @return bool|mixed
  */
 public function findUserByLogin($login)
 {
     try {
         $user = Sentry::findUserByLogin($login);
         return $user;
     } catch (UserNotFoundException $e) {
         return false;
     }
 }
Example #2
0
 public function reminder()
 {
     $code = Str::lower(Input::get('code'));
     if (strpos($code, Session::get('code')) !== false) {
         try {
             //发送找回密码邮件
             $user = Sentry::findUserByLogin(Input::get('email'));
             $data['uid'] = $user->id;
             $data['resetCode'] = $user->getResetPasswordCode();
             Mail::send('emails.auth.reminder', $data, function ($message) use($user) {
                 $message->to($user->email, '尊敬的柚皮会员')->subject('用户密码找回');
             });
             return Response::json(['status' => true, 'email_url' => (new Uinfo())->getMail(Input::get('email'))]);
         } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
             return Response::json(['status' => false, 'msg' => '用户不存在!']);
         }
     }
     return Response::json(['status' => false, 'msg' => '验证码错误!']);
 }
 public function loginsubmit()
 {
     $input = Input::all();
     $rules = array('password' => array('required'), 'email' => array('required'));
     $validation = Validator::make(Input::all(), $rules);
     if ($validation->fails()) {
         return Redirect::to('user/login');
     }
     $credentials = array('email' => $input['email'], 'password' => $input['password']);
     try {
         $user = Sentry::findUserByLogin($input['email']);
     } catch (UserNotFoundException $e) {
         Session::flash('message', 'User or Password not match.');
         return Redirect::to('user/login');
     }
     //check password
     if (!$user->checkPassword($input['password'])) {
         Session::flash('message', 'User or Password not match.');
         return Redirect::to('user/login');
     }
     $throttle = Sentry::findThrottlerByUserId($user['id']);
     //check Suspended
     if ($suspended = $throttle->isSuspended()) {
         Session::flash('message', ' User is Suspended.');
         return Redirect::to('user/login');
     }
     //check banned
     if ($banned = $throttle->isBanned()) {
         Session::flash('message', 'User banned.');
         return Redirect::to('user/login');
     }
     //check deactive
     if (!$user->isActivated()) {
         Session::flash('message', 'User not activated.');
         return Redirect::to('user/login');
     }
     if (isset($input['rememberme']) && $input['rememberme'] == 1) {
         Sentry::authenticateAndRemember($credentials);
     } else {
         Sentry::authenticate($credentials, false);
     }
     if ($user->hasAccess('dashboard')) {
         return Redirect::to('manager/videos');
     } else {
         return Redirect::to('/');
     }
 }
 public function doActivatingUser()
 {
     $email = Input::get("email");
     $code = Input::get("code");
     $status = "error";
     if ($email && $code) {
         try {
             $user = Sentry::findUserByLogin($email);
             // Attempt to activate the user
             if ($user->attemptActivation($code)) {
                 $result = "Пользователь активирован";
                 $status = "success";
                 Sentry::login($user, false);
             } else {
                 $result = "Ошибка. Пользователя код активации не подходит";
             }
         } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
             $result = "Пользователь не найден";
         } catch (\Cartalyst\Sentry\Users\UserAlreadyActivatedException $e) {
             $result = "Пользователь уже активирован";
         }
         return View::make('registration::activatingUser', compact("result", "status"));
     } else {
         $result = "Неверные входные данные. Email или код активации неверные ";
         return View::make('registration::activatingUser', compact("result"));
     }
 }