From 3196de4003fd37411ab3b4bf5d5a4c66ce9b0ffd Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 28 Aug 2022 22:28:59 -0400 Subject: [PATCH] Account confirmation works (no e-mail yet) --- src/JobsJobsJobs/App/src/api/index.ts | 17 ++++- src/JobsJobsJobs/App/src/api/types.ts | 6 ++ src/JobsJobsJobs/App/src/router/index.ts | 25 ++++--- .../src/views/citizen/ConfirmRegistration.vue | 38 ++++++++++ .../App/src/views/profile/ProfileView.vue | 62 ++++++++------- .../App/src/views/so-long/DeletionOptions.vue | 75 ++++++++----------- .../App/src/views/so-long/DeletionSuccess.vue | 35 ++------- .../App/src/views/success-story/StoryEdit.vue | 49 +++++++----- .../App/src/views/success-story/StoryList.vue | 53 +++++++------ .../App/src/views/success-story/StoryView.vue | 22 +++--- src/JobsJobsJobs/JobsJobsJobs.Data/Data.fs | 35 ++++++++- src/JobsJobsJobs/Server/Handlers.fs | 8 ++ 12 files changed, 264 insertions(+), 161 deletions(-) create mode 100644 src/JobsJobsJobs/App/src/views/citizen/ConfirmRegistration.vue diff --git a/src/JobsJobsJobs/App/src/api/index.ts b/src/JobsJobsJobs/App/src/api/index.ts index f63ad6b..2f28adb 100644 --- a/src/JobsJobsJobs/App/src/api/index.ts +++ b/src/JobsJobsJobs/App/src/api/index.ts @@ -19,7 +19,8 @@ import { PublicSearchResult, StoryEntry, StoryForm, - Success + Success, + Valid } from "./types" /** @@ -110,6 +111,20 @@ export default { register: async (form : CitizenRegistrationForm) : Promise => apiSend(await fetch(apiUrl("citizen/register"), reqInit("POST", undefined, form)), "registering citizen"), + /** + * Confirm an account by verifying a token they received via e-mail + * + * @param token The token to be verified + * @return True if the token is value, false if it is not, or an error message if one is encountered + */ + confirmToken: async (token : string) : Promise => { + const resp = await apiResult( + await fetch(apiUrl("citizen/confirm"), reqInit("PATCH", undefined, { token })), "confirming account") + if (typeof resp === "string") return resp + if (typeof resp === "undefined") return false + return resp.valid + }, + /** * Log a citizen on * diff --git a/src/JobsJobsJobs/App/src/api/types.ts b/src/JobsJobsJobs/App/src/api/types.ts index b2fee50..02a6125 100644 --- a/src/JobsJobsJobs/App/src/api/types.ts +++ b/src/JobsJobsJobs/App/src/api/types.ts @@ -312,3 +312,9 @@ export interface Success { /** The success story */ story : string | undefined } + +/** Whether a check is valid */ +export interface Valid { + /** The validity */ + valid : boolean +} diff --git a/src/JobsJobsJobs/App/src/router/index.ts b/src/JobsJobsJobs/App/src/router/index.ts index 2a09773..c3fbaa7 100644 --- a/src/JobsJobsJobs/App/src/router/index.ts +++ b/src/JobsJobsJobs/App/src/router/index.ts @@ -7,7 +7,6 @@ import { } from "vue-router" import store, { Mutations } from "@/store" import Home from "@/views/Home.vue" -import LogOn from "@/views/citizen/LogOn.vue" /** The URL to which the user should be pointed once they have authorized with Mastodon */ export const AFTER_LOG_ON_URL = "jjj-after-log-on-url" @@ -35,38 +34,44 @@ const routes: Array = [ path: "/how-it-works", name: "HowItWorks", component: () => import(/* webpackChunkName: "help" */ "../views/HowItWorks.vue"), - meta: { title: "How It Works" } + meta: { auth: false, title: "How It Works" } }, { path: "/privacy-policy", name: "PrivacyPolicy", component: () => import(/* webpackChunkName: "legal" */ "../views/PrivacyPolicy.vue"), - meta: { title: "Privacy Policy" } + meta: { auth: false, title: "Privacy Policy" } }, { path: "/terms-of-service", name: "TermsOfService", component: () => import(/* webpackChunkName: "legal" */ "../views/TermsOfService.vue"), - meta: { title: "Terms of Service" } + meta: { auth: false, title: "Terms of Service" } }, // Citizen URLs { path: "/citizen/register", name: "CitizenRegistration", component: () => import(/* webpackChunkName: "register" */ "../views/citizen/Register.vue"), - meta: { title: "Register" } + meta: { auth: false, title: "Register" } }, { path: "/citizen/registered", name: "CitizenRegistered", component: () => import(/* webpackChunkName: "register" */ "../views/citizen/Registered.vue"), - meta: { title: "Registration Successful" } + meta: { auth: false, title: "Registration Successful" } + }, + { + path: "/citizen/confirm/:token", + name: "ConfirmRegistration", + component: () => import(/* webpackChunkName: "logon" */ "../views/citizen/ConfirmRegistration.vue"), + meta: { auth: false, title: "Account Confirmation" } }, { path: "/citizen/log-on", name: "LogOn", - component: LogOn, - meta: { title: "Log On" } + component: () => import(/* webpackChunkName: "logon" */ "../views/citizen/LogOn.vue"), + meta: { auth: false, title: "Log On" } }, { path: "/citizen/:abbr/authorized", @@ -150,7 +155,7 @@ const routes: Array = [ meta: { auth: true, title: "Account Deletion Options" } }, { - path: "/so-long/success/:abbr", + path: "/so-long/success", name: "DeletionSuccess", component: () => import(/* webpackChunkName: "so-long" */ "../views/so-long/DeletionSuccess.vue"), meta: { auth: false, title: "Account Deletion Success" } @@ -187,7 +192,7 @@ const router = createRouter({ // eslint-disable-next-line router.beforeEach((to : RouteLocationNormalized, from : RouteLocationNormalized) => { - if (store.state.user === undefined && (to.meta.auth || false)) { + if (store.state.user === undefined && to.meta.auth) { window.localStorage.setItem(AFTER_LOG_ON_URL, to.fullPath) return "/citizen/log-on" } diff --git a/src/JobsJobsJobs/App/src/views/citizen/ConfirmRegistration.vue b/src/JobsJobsJobs/App/src/views/citizen/ConfirmRegistration.vue new file mode 100644 index 0000000..8d80828 --- /dev/null +++ b/src/JobsJobsJobs/App/src/views/citizen/ConfirmRegistration.vue @@ -0,0 +1,38 @@ + + + diff --git a/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue b/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue index ea9d040..733a8af 100644 --- a/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue +++ b/src/JobsJobsJobs/App/src/views/profile/ProfileView.vue @@ -1,29 +1,39 @@ -