From c71a7569022e2c7c4d3c914bda3a84f2db9244c0 Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 3 Jan 2025 15:38:47 -0800 Subject: [PATCH] DBC22-2869: FE integration in saved route and account pages --- src/backend/apps/authentication/views.py | 3 +- src/backend/apps/shared/views.py | 3 +- src/frontend/src/App.js | 4 ++ src/frontend/src/pages/AccountPage.js | 14 ++++- src/frontend/src/pages/AccountPage.scss | 21 ++++++++ src/frontend/src/pages/SavedRoutesPage.js | 22 ++++++++ src/frontend/src/pages/SavedRoutesPage.scss | 45 ++++++++++++---- src/frontend/src/pages/VerifyEmailPage.js | 59 +++++++++++++++++++++ src/frontend/src/pages/VerifyEmailPage.scss | 12 +++++ src/frontend/src/styles/variables.scss | 9 +++- 10 files changed, 176 insertions(+), 16 deletions(-) create mode 100644 src/frontend/src/pages/VerifyEmailPage.js create mode 100644 src/frontend/src/pages/VerifyEmailPage.scss diff --git a/src/backend/apps/authentication/views.py b/src/backend/apps/authentication/views.py index f55514916..d9f17ada0 100644 --- a/src/backend/apps/authentication/views.py +++ b/src/backend/apps/authentication/views.py @@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist from django.core.mail import EmailMultiAlternatives from django.db.utils import IntegrityError +from django.http import HttpResponseRedirect from django.shortcuts import reverse from django.template.loader import render_to_string from django.utils.encoding import force_bytes, force_str @@ -128,7 +129,7 @@ def get(self, request, uidb64, token): if user is not None and EmailVerificationTokenGenerator().check_token(user, token): user.verified = True user.save() - return Response({'message': 'Email verified successfully'}, status=status.HTTP_200_OK) + return HttpResponseRedirect(env("FRONTEND_BASE_URL") + 'account') # Redirect to the account page else: return Response({'error': 'Invalid token'}, status=status.HTTP_400_BAD_REQUEST) diff --git a/src/backend/apps/shared/views.py b/src/backend/apps/shared/views.py index 4153aeeba..d8cf82a1a 100644 --- a/src/backend/apps/shared/views.py +++ b/src/backend/apps/shared/views.py @@ -143,7 +143,8 @@ def get(self, request, format=None): if request.user.is_authenticated: response = JsonResponse({ "username": request.user.username, - "email": request.user.email + "email": request.user.email, + "verified": request.user.verified }) else: diff --git a/src/frontend/src/App.js b/src/frontend/src/App.js index 58056c6a3..15c035f88 100644 --- a/src/frontend/src/App.js +++ b/src/frontend/src/App.js @@ -43,6 +43,7 @@ import ScrollToTop from './Components/shared/ScrollToTop'; // FontAwesome Stylesheet import { config } from '@fortawesome/fontawesome-svg-core' import '@fortawesome/fontawesome-svg-core/styles.css' +import VerifyEmailPage from "./pages/VerifyEmailPage"; config.autoAddCss = false // Variables @@ -148,11 +149,13 @@ function App() { if (data.username) { ret.username = data.username; ret.email = data.email; + ret.verified = data.verified; } setAuthContext((prior) => { if (ret.loginStateKnown != prior.loginStateKnown) { return ret; } if (ret.username != prior.username) { return ret; } if (ret.email != prior.email) { return ret; } + if (ret.verified != prior.verified) { return ret; } return prior; }); }) @@ -199,6 +202,7 @@ function App() { } /> } /> } /> + } /> {/* Catch-all route for 404 errors */} } /> } /> diff --git a/src/frontend/src/pages/AccountPage.js b/src/frontend/src/pages/AccountPage.js index f948e5049..79d6f309e 100644 --- a/src/frontend/src/pages/AccountPage.js +++ b/src/frontend/src/pages/AccountPage.js @@ -7,7 +7,6 @@ import Container from 'react-bootstrap/Container'; // Internal imports import { AuthContext } from '../App'; -import { sendVerificationEmail } from "../Components/data/user"; import Footer from '../Footer.js'; import PageHeader from '../PageHeader'; @@ -33,7 +32,18 @@ export default function AccountPage() { - +
+

Email Address

+

{authContext.email}

+ + {!authContext.verified && +

+ This email address has not been verified. Email notifications for + saved routes will be disabled until verification + is complete. +

+ } +