/** * 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', '/')); }
/** * Store a new user. * * @return \Illuminate\Http\Response */ public function store() { $password = Str::random(); $input = array_merge(Binput::only(['first_name', 'last_name', 'email']), ['password' => $password, 'activated' => true, 'activated_at' => new DateTime()]); $rules = UserRepository::rules(array_keys($input)); $rules['password'] = '******'; $val = UserRepository::validate($input, $rules, true); if ($val->fails()) { return Redirect::route('users.create')->withInput()->withErrors($val->errors()); } try { $user = UserRepository::create($input); $groups = GroupRepository::index(); foreach ($groups as $group) { if (Binput::get('group_' . $group->id) === 'on') { $user->addGroup($group); } } $mail = ['url' => URL::to(Config::get('credentials.home', '/')), 'password' => $password, 'email' => $user->getLogin(), 'subject' => Config::get('app.name') . ' - New Account Information']; Mail::queue('credentials::emails.newuser', $mail, function ($message) use($mail) { $message->to($mail['email'])->subject($mail['subject']); }); return Redirect::route('users.show', ['users' => $user->id])->with('success', 'The user has been created successfully. Their password has been emailed to them.'); } catch (UserExistsException $e) { return Redirect::route('users.create')->withInput()->withErrors($val->errors())->with('error', 'That email address is taken.'); } }