/**
* Shows a notice that a user's email address has not been confirmed,
- * Also has the option to re-send the confirmation email.
+ * along with the option to re-send the confirmation email.
*/
public function showAwaiting()
{
$user = $this->loginService->getLastLoginAttemptUser();
+ if ($user === null) {
+ $this->showErrorNotification(trans('errors.login_user_not_found'));
+ return redirect('/login');
+ }
- return view('auth.user-unconfirmed', ['user' => $user]);
+ return view('auth.register-confirm-awaiting');
}
/**
/**
* Resend the confirmation email.
*/
- public function resend(Request $request)
+ public function resend()
{
- $this->validate($request, [
- 'email' => ['required', 'email', 'exists:users,email'],
- ]);
- $user = $this->userRepo->getByEmail($request->get('email'));
+ $user = $this->loginService->getLastLoginAttemptUser();
+ if ($user === null) {
+ $this->showErrorNotification(trans('errors.login_user_not_found'));
+ return redirect('/login');
+ }
try {
$this->emailConfirmationService->sendConfirmation($user);
+ } catch (ConfirmationEmailException $e) {
+ $this->showErrorNotification($e->getMessage());
+
+ return redirect('/login');
} catch (Exception $e) {
$this->showErrorNotification(trans('auth.email_confirm_send_error'));
- return redirect('/register/confirm');
+ return redirect('/register/awaiting');
}
$this->showSuccessNotification(trans('auth.email_confirm_resent'));
$resp->assertRedirect('/register/confirm');
$this->assertDatabaseHas('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
+ $resp = $this->get('/register/confirm');
+ $resp->assertSee('Thanks for registering!');
+
// Ensure notification sent
/** @var User $dbUser */
$dbUser = User::query()->where('email', '=', $user->email)->first();
$response->assertStatus(429);
}
+
+ public function test_registration_confirmation_resend()
+ {
+ Notification::fake();
+ $this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true']);
+ $user = User::factory()->make();
+
+ $resp = $this->post('/register', $user->only('name', 'email', 'password'));
+ $resp->assertRedirect('/register/confirm');
+ $dbUser = User::query()->where('email', '=', $user->email)->first();
+
+ $resp = $this->post('/login', ['email' => $user->email, 'password' => $user->password]);
+ $resp->assertRedirect('/register/confirm/awaiting');
+
+ $resp = $this->post('/register/confirm/resend');
+ $resp->assertRedirect('/register/confirm');
+ Notification::assertSentToTimes($dbUser, ConfirmEmailNotification::class, 2);
+ }
+
+ public function test_registration_confirmation_expired_resend()
+ {
+ Notification::fake();
+ $this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true']);
+ $user = User::factory()->make();
+
+ $resp = $this->post('/register', $user->only('name', 'email', 'password'));
+ $resp->assertRedirect('/register/confirm');
+ $dbUser = User::query()->where('email', '=', $user->email)->first();
+
+ $resp = $this->post('/login', ['email' => $user->email, 'password' => $user->password]);
+ $resp->assertRedirect('/register/confirm/awaiting');
+
+ $emailConfirmation = DB::table('email_confirmations')->where('user_id', '=', $dbUser->id)->first();
+ $this->travel(2)->days();
+
+ $resp = $this->post("/register/confirm/accept", [
+ 'token' => $emailConfirmation->token,
+ ]);
+ $resp->assertRedirect('/register/confirm');
+ $this->assertSessionError('The confirmation token has expired, A new confirmation email has been sent.');
+
+ Notification::assertSentToTimes($dbUser, ConfirmEmailNotification::class, 2);
+ }
+
+ public function test_registration_confirmation_awaiting_and_resend_returns_to_log_if_no_login_attempt_user_found()
+ {
+ $this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true']);
+
+ $this->get('/register/confirm/awaiting')->assertRedirect('/login');
+ $this->assertSessionError('A user for this action could not be found.');
+ $this->flushSession();
+
+ $this->post('/register/confirm/resend')->assertRedirect('/login');
+ $this->assertSessionError('A user for this action could not be found.');
+ }
}