Skip to content

Commit

Permalink
Merge pull request #156 from CentreForDigitalHumanities/fix/confirm-e…
Browse files Browse the repository at this point in the history
…mail

Fix: confirm email flow
  • Loading branch information
XanderVertegaal authored Nov 26, 2024
2 parents 7980b4a + 1d5e36c commit 8fc4913
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions frontend/src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { SessionService } from './session.service';
import { catchError, map, of, switchMap, merge, share, startWith, withLatestFrom, shareReplay } from 'rxjs';
import { UserRegistration, UserResponse, UserLogin, PasswordForgotten, ResetPassword, KeyInfo, UserSettings } from '../user/models/user';
import { UserRegistration, UserResponse, UserLogin, PasswordForgotten, ResetPassword, KeyInfo, UserSettings, KeyInfoResult } from '../user/models/user';
import { encodeUserData, parseUserData } from '../user/utils';
import _ from 'underscore';
import { HttpClient } from '@angular/common/http';
Expand Down Expand Up @@ -32,15 +32,15 @@ export class AuthService {
this.authRoute('password/reset/confirm/'),
'post'
);
public verifyEmail = this.createRequest<string, AuthAPIResult>(
public verifyEmail = this.createRequest<KeyInfo, AuthAPIResult>(
this.authRoute('registration/verify-email/'),
'post'
);
public updateSettings = this.createRequest<Partial<UserSettings>, UserResponse>(
this.authRoute('user/'),
'patch'
);
public keyInfo = this.createRequest<string, KeyInfo>(
public keyInfo = this.createRequest<KeyInfo, KeyInfoResult>(
this.authRoute('registration/key-info/'),
'post'
)
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/app/user/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class User {
public email: string,
public firstName: string,
public lastName: string,
public isStaff: boolean,
) { }
public isStaff: boolean
) {}
}

export interface UserRegistration {
Expand All @@ -41,11 +41,15 @@ export interface PasswordForgotten {
email: string;
}

export interface KeyInfo {
export interface KeyInfoResult {
username: string;
email: string;
}

export interface KeyInfo {
key: string;
}

// Dj-rest-auth does not let you update your email address, but we need it to request the password reset form.
export type UserSettings = Pick<
User,
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/app/user/verify-email/verify-email.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { AfterViewInit, Component, DestroyRef, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { ActivatedRoute } from "@angular/router";
import { ActivatedRoute, Router } from "@angular/router";
import { AuthService } from "@services/auth.service";
import { ToastService } from "@services/toast.service";
import { map, merge, share, startWith } from "rxjs";
import { map, share } from "rxjs";
import { KeyInfo } from "../models/user";

@Component({
selector: "lc-verify-email",
templateUrl: "./verify-email.component.html",
styleUrls: ["./verify-email.component.scss"],
})
export class VerifyEmailComponent implements OnInit, AfterViewInit {
private key = this.activatedRoute.snapshot.params["key"];
private key: KeyInfo = { key: this.activatedRoute.snapshot.params["key"] };

public userDetails$ = this.authService.keyInfo.result$.pipe(
map((results) => ("error" in results ? null : results)),
Expand All @@ -22,6 +23,7 @@ export class VerifyEmailComponent implements OnInit, AfterViewInit {

constructor(
private activatedRoute: ActivatedRoute,
private router: Router,
private authService: AuthService,
private toastService: ToastService,
private destroyRef: DestroyRef,
Expand Down Expand Up @@ -51,11 +53,14 @@ export class VerifyEmailComponent implements OnInit, AfterViewInit {

this.authService.verifyEmail.success$
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.toastService.show({
header: "Email verified",
body: "Email address has been verified.",
type: "success",
}));
.subscribe(() => {
this.toastService.show({
header: "Email verified",
body: "Email address has been verified.",
type: "success",
});
this.router.navigate(['/']);
});
}

// We are subscribing to results of this call in the template, so we should
Expand Down

0 comments on commit 8fc4913

Please sign in to comment.