Ejemplo n.º 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'] = 'required|min:6';
     $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', '/'));
 }
Ejemplo n.º 2
0
 /**
  * Attempt to register a new user.
  *
  * @return \Illuminate\Http\Response
  */
 public function postRegister()
 {
     if (!Config::get('credentials.regallowed')) {
         return Redirect::route('account.register');
     }
     $input = Binput::only(['first_name', 'last_name', 'email', 'password', 'password_confirmation']);
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.register')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         unset($input['password_confirmation']);
         $user = Credentials::register($input);
         if (!Config::get('credentials.activation')) {
             $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Welcome'];
             Mail::queue('credentials::emails.welcome', $mail, function ($message) use($mail) {
                 $message->to($mail['email'])->subject($mail['subject']);
             });
             $user->attemptActivation($user->getActivationCode());
             $user->addGroup(Credentials::getGroupProvider()->findByName('Users'));
             return Redirect::to(Config::get('credentials.home', '/'))->with('success', 'Your account has been created successfully. You may now login.');
         }
         $code = $user->getActivationCode();
         $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'link' => URL::route('account.activate', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Welcome'];
         Mail::queue('credentials::emails.welcome', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::to(Config::get('credentials.home', '/'))->with('success', 'Your account has been created. Check your email for the confirmation link.');
     } catch (UserExistsException $e) {
         return Redirect::route('account.register')->withInput()->withErrors($val->errors())->with('error', 'That email address is taken.');
     }
 }
Ejemplo n.º 3
0
 /**
  * Queue the sending of the password reset email.
  *
  * @return \Illuminate\Http\Response
  */
 public function postReset()
 {
     $input = Binput::only('email');
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.reset')->withInput()->withErrors($val->errors());
     }
     $this->throttler->hit();
     try {
         $user = Credentials::getUserProvider()->findByLogin($input['email']);
         $code = $user->getResetPasswordCode();
         $mail = ['link' => URL::route('account.password', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - Password Reset Confirmation'];
         Mail::queue('credentials::emails.reset', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::route('account.reset')->with('success', 'Check your email for password reset information.');
     } catch (UserNotFoundException $e) {
         return Redirect::route('account.reset')->with('error', 'That user does not exist.');
     }
 }
Ejemplo n.º 4
0
 /**
  * Update the user's password.
  *
  * @return \Illuminate\Http\Response
  */
 public function patchPassword()
 {
     $input = Binput::only(['password', 'password_confirmation']);
     $val = UserRepository::validate($input, array_keys($input));
     if ($val->fails()) {
         return Redirect::route('account.profile')->withInput()->withErrors($val->errors());
     }
     unset($input['password_confirmation']);
     $user = Credentials::getUser();
     $this->checkUser($user);
     $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - New Password Notification'];
     Mail::queue('credentials::emails.newpass', $mail, function ($message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
     $user->update($input);
     return Redirect::route('account.profile')->with('success', 'Your password has been updated successfully.');
 }
Ejemplo n.º 5
0
 /**
  * Delete an existing user.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $user = UserRepository::find($id);
     $this->checkUser($user);
     $email = $user->getLogin();
     try {
         $user->delete();
     } catch (\Exception $e) {
         return Redirect::route('users.show', ['users' => $id])->with('error', 'We were unable to delete the account.');
     }
     $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'email' => $email, 'subject' => Config::get('app.name') . ' - Account Deleted Notification'];
     Mail::queue('credentials::emails.admindeleted', $mail, function ($message) use($mail) {
         $message->to($mail['email'])->subject($mail['subject']);
     });
     return Redirect::route('users.index')->with('success', 'The user has been deleted successfully.');
 }