/** * @param \Lio\Accounts\User $user * @param \Lio\Accounts\UserUpdaterListener $listener * @param array $data * @return mixed */ private function updateUser(User $user, UserUpdaterListener $listener, array $data) { $oldEmail = $user->email; $user->fill($data); // If the email changed, the user will need to re-confirm it. if ($data['email'] !== $oldEmail) { $user->confirmed = false; // Set a confirmation code for the user. He'll need to verify his email address // with this code before he can use certain sections on the website. $confirmationCode = Str::random(30); // We'll generate a new one if we find a user with the same code. while ($this->users->getByConfirmationCode($confirmationCode) !== null) { $confirmationCode = Str::random(30); } $user->confirmation_code = $confirmationCode; } // check the model validation if (!$this->users->save($user)) { return $listener->userValidationError($user->getErrors()); } // Send a confirmation email to the user. if ($data['email'] !== $oldEmail) { $this->confirmation->send($user); } return $listener->userUpdated($user, $data['email'] !== $oldEmail); }
/** * Re-sends the confirmation email * * @param string $code * @return \Illuminate\Http\RedirectResponse */ public function getResendConfirmation($code) { $user = $this->users->getByConfirmationCode($code); if (!$user) { App::abort(404); } $this->confirmation->send($user); return Redirect::home()->with('success', 'A new email confirmation was sent to ' . $user->email); }
private function createValidUserRecord($listener, $data) { $user = $this->users->getNew($data); // Set a confirmation code for the user. He'll need to verify his email address // with this code before he can use certain sections on the website. $confirmationCode = Str::random(30); // We'll generate a new one if we find a user with the same code. while ($this->users->getByConfirmationCode($confirmationCode) !== null) { $confirmationCode = Str::random(30); } $user->confirmation_code = $confirmationCode; // check the model validation if (!$this->users->save($user)) { return $listener->userValidationError($user->getErrors()); } // Send a confirmation email to the user. $this->confirmation->send($user); return $listener->userCreated($user); }
/** * Re-sends the confirmation email * * @return \Illuminate\Http\RedirectResponse */ public function resendEmailConfirmation() { $this->confirmation->send(Auth::user()); session(['success' => 'A new email confirmation was sent to ' . Auth::user()->email]); return redirect()->home(); }