Example #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('core.home', '/'));
 }
 /**
  * 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 = register($input);
         if (!Config::get('credentials.activation')) {
             $mail = ['url' => URL::to(Config::get('core.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - Welcome'];
             Mail::queue('emails.welcome', $mail, function ($message) use($mail) {
                 $message->to($mail['email'])->subject($mail['subject']);
             });
             $user->attemptActivation($user->getActivationCode());
             $user->addGroup(getGroupProvider()->findByName('Users'));
             return Redirect::to(Config::get('core.home', '/'))->with('success', 'Your account has been created successfully.');
         }
         $code = $user->getActivationCode();
         $mail = ['url' => URL::to(Config::get('core.home', '/')), 'link' => URL::route('account.activate', ['id' => $user->id, 'code' => $code]), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - Welcome'];
         Mail::queue('emails.welcome', $mail, function ($message) use($mail) {
             $message->to($mail['email'])->subject($mail['subject']);
         });
         return Redirect::to(Config::get('core.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.');
     }
 }
Example #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('core.name') . ' - Password Reset Confirmation'];
         Mail::queue('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.');
     }
 }
Example #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('core.home', '/')), 'email' => $user->getLogin(), 'subject' => Config::get('core.name') . ' - New Password Notification'];
     Mail::queue('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.');
 }
Example #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('core.home', '/')), 'email' => $email, 'subject' => Config::get('core.name') . ' - Account Deleted Notification'];
     Mail::queue('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.');
 }