Skip to content

Commit

Permalink
Add user email changing, and refactor activation token system (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Nov 18, 2024
1 parent 3ad64db commit 96c1f77
Show file tree
Hide file tree
Showing 40 changed files with 2,293 additions and 461 deletions.
6 changes: 4 additions & 2 deletions frontend/src/constants/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export const ROUTE_EDIT = "/edits/:id";
export const ROUTE_EDIT_UPDATE = "/edits/:id/update";
export const ROUTE_REGISTER = "/register";
export const ROUTE_ACTIVATE = "/activate";
export const ROUTE_FORGOT_PASSWORD = "/forgotPassword";
export const ROUTE_RESET_PASSWORD = "/resetPassword";
export const ROUTE_FORGOT_PASSWORD = "/forgot-password";
export const ROUTE_RESET_PASSWORD = "/reset-password";
export const ROUTE_CONFIRM_EMAIL = "/users/confirm-email";
export const ROUTE_CHANGE_EMAIL = "/users/change-email";
export const ROUTE_SEARCH = "/search/:term";
export const ROUTE_SEARCH_INDEX = "/search/";
export const ROUTE_VERSION = "/version";
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/graphql/mutations/ConfirmChangeEmail.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation ConfirmChangeEmail($token: ID!) {
confirmChangeEmail(token: $token)
}
3 changes: 3 additions & 0 deletions frontend/src/graphql/mutations/RequestChangeEmail.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation RequestChangeEmail {
requestChangeEmail
}
3 changes: 3 additions & 0 deletions frontend/src/graphql/mutations/ValidateChangeEmail.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mutation ValidateChangeEmail($token: ID!, $email: String!) {
validateChangeEmail(token: $token, email: $email)
}
26 changes: 26 additions & 0 deletions frontend/src/graphql/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ import {
DeleteDraftMutationVariables,
UnmatchFingerprintMutation,
UnmatchFingerprintMutationVariables,
ValidateChangeEmailMutation,
ValidateChangeEmailMutationVariables,
ConfirmChangeEmailMutation,
ConfirmChangeEmailMutationVariables,
RequestChangeEmailMutation,
} from "../types";

import ActivateUserGQL from "./ActivateNewUser.gql";
Expand Down Expand Up @@ -125,6 +130,9 @@ import FavoriteStudioGQL from "./FavoriteStudio.gql";
import FavoritePerformerGQL from "./FavoritePerformer.gql";
import DeleteDraftGQL from "./DeleteDraft.gql";
import UnmatchFingerprintGQL from "./UnmatchFingerprint.gql";
import ValidateChangeEmailGQL from "./ValidateChangeEmail.gql";
import ConfirmChangeEmailGQL from "./ConfirmChangeEmail.gql";
import RequestChangeEmailGQL from "./RequestChangeEmail.gql";

export const useActivateUser = (
options?: MutationHookOptions<
Expand Down Expand Up @@ -383,3 +391,21 @@ export const useUnmatchFingerprint = (
},
...options,
});

export const useValidateChangeEmail = (
options?: MutationHookOptions<
ValidateChangeEmailMutation,
ValidateChangeEmailMutationVariables
>
) => useMutation(ValidateChangeEmailGQL, options);

export const useConfirmChangeEmail = (
options?: MutationHookOptions<
ConfirmChangeEmailMutation,
ConfirmChangeEmailMutationVariables
>
) => useMutation(ConfirmChangeEmailGQL, options);

export const useRequestChangeEmail = (
options?: MutationHookOptions<RequestChangeEmailMutation>
) => useMutation(RequestChangeEmailGQL, options);
199 changes: 194 additions & 5 deletions frontend/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export type Scalars = {
};

export type ActivateNewUserInput = {
activation_key: Scalars["String"];
email: Scalars["String"];
activation_key: Scalars["ID"];
name: Scalars["String"];
password: Scalars["String"];
};
Expand Down Expand Up @@ -444,6 +443,7 @@ export type Mutation = {
cancelEdit: Edit;
/** Changes the password for the current user */
changePassword: Scalars["Boolean"];
confirmChangeEmail: UserChangeEmailStatus;
destroyDraft: Scalars["Boolean"];
/** Comment on an edit */
editComment: Edit;
Expand All @@ -462,7 +462,7 @@ export type Mutation = {
imageCreate?: Maybe<Image>;
imageDestroy: Scalars["Boolean"];
/** User interface for registering */
newUser?: Maybe<Scalars["String"]>;
newUser?: Maybe<Scalars["ID"]>;
performerCreate?: Maybe<Performer>;
performerDestroy: Scalars["Boolean"];
/** Propose a new performer or modification to a performer */
Expand All @@ -472,6 +472,8 @@ export type Mutation = {
performerUpdate?: Maybe<Performer>;
/** Regenerates the api key for the given user, or the current user if id not provided */
regenerateAPIKey: Scalars["String"];
/** Request an email change for the current user */
requestChangeEmail: UserChangeEmailStatus;
/** Removes a pending invite code - refunding the token */
rescindInviteCode: Scalars["Boolean"];
/** Generates an email to reset a user password */
Expand Down Expand Up @@ -513,6 +515,7 @@ export type Mutation = {
userCreate?: Maybe<User>;
userDestroy: Scalars["Boolean"];
userUpdate?: Maybe<User>;
validateChangeEmail: UserChangeEmailStatus;
};

export type MutationActivateNewUserArgs = {
Expand All @@ -531,6 +534,10 @@ export type MutationChangePasswordArgs = {
input: UserChangePasswordInput;
};

export type MutationConfirmChangeEmailArgs = {
token: Scalars["ID"];
};

export type MutationDestroyDraftArgs = {
id: Scalars["ID"];
};
Expand Down Expand Up @@ -721,9 +728,14 @@ export type MutationUserUpdateArgs = {
input: UserUpdateInput;
};

export type MutationValidateChangeEmailArgs = {
email: Scalars["String"];
token: Scalars["ID"];
};

export type NewUserInput = {
email: Scalars["String"];
invite_key?: InputMaybe<Scalars["String"]>;
invite_key?: InputMaybe<Scalars["ID"]>;
};

export enum OperationEnum {
Expand Down Expand Up @@ -1779,11 +1791,26 @@ export type User = {
vote_count: UserVoteCount;
};

export type UserChangeEmailInput = {
existing_email_token?: InputMaybe<Scalars["ID"]>;
new_email?: InputMaybe<Scalars["String"]>;
new_email_token?: InputMaybe<Scalars["ID"]>;
};

export enum UserChangeEmailStatus {
CONFIRM_NEW = "CONFIRM_NEW",
CONFIRM_OLD = "CONFIRM_OLD",
ERROR = "ERROR",
EXPIRED = "EXPIRED",
INVALID_TOKEN = "INVALID_TOKEN",
SUCCESS = "SUCCESS",
}

export type UserChangePasswordInput = {
/** Password in plain text */
existing_password?: InputMaybe<Scalars["String"]>;
new_password: Scalars["String"];
reset_key?: InputMaybe<Scalars["String"]>;
reset_key?: InputMaybe<Scalars["ID"]>;
};

export type UserCreateInput = {
Expand Down Expand Up @@ -4309,6 +4336,15 @@ export type ChangePasswordMutation = {
changePassword: boolean;
};

export type ConfirmChangeEmailMutationVariables = Exact<{
token: Scalars["ID"];
}>;

export type ConfirmChangeEmailMutation = {
__typename: "Mutation";
confirmChangeEmail: UserChangeEmailStatus;
};

export type DeleteDraftMutationVariables = Exact<{
id: Scalars["ID"];
}>;
Expand Down Expand Up @@ -6495,6 +6531,15 @@ export type RegenerateApiKeyMutation = {
regenerateAPIKey: string;
};

export type RequestChangeEmailMutationVariables = Exact<{
[key: string]: never;
}>;

export type RequestChangeEmailMutation = {
__typename: "Mutation";
requestChangeEmail: UserChangeEmailStatus;
};

export type RescindInviteCodeMutationVariables = Exact<{
code: Scalars["ID"];
}>;
Expand Down Expand Up @@ -12827,6 +12872,16 @@ export type UpdateUserMutation = {
} | null;
};

export type ValidateChangeEmailMutationVariables = Exact<{
token: Scalars["ID"];
email: Scalars["String"];
}>;

export type ValidateChangeEmailMutation = {
__typename: "Mutation";
validateChangeEmail: UserChangeEmailStatus;
};

export type VoteMutationVariables = Exact<{
input: EditVoteInput;
}>;
Expand Down Expand Up @@ -23279,6 +23334,51 @@ export const ChangePasswordDocument = {
ChangePasswordMutation,
ChangePasswordMutationVariables
>;
export const ConfirmChangeEmailDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "mutation",
name: { kind: "Name", value: "ConfirmChangeEmail" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "token" },
},
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "ID" } },
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "confirmChangeEmail" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "token" },
value: {
kind: "Variable",
name: { kind: "Name", value: "token" },
},
},
],
},
],
},
},
],
} as unknown as DocumentNode<
ConfirmChangeEmailMutation,
ConfirmChangeEmailMutationVariables
>;
export const DeleteDraftDocument = {
kind: "Document",
definitions: [
Expand Down Expand Up @@ -27145,6 +27245,28 @@ export const RegenerateApiKeyDocument = {
RegenerateApiKeyMutation,
RegenerateApiKeyMutationVariables
>;
export const RequestChangeEmailDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "mutation",
name: { kind: "Name", value: "RequestChangeEmail" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "requestChangeEmail" },
},
],
},
},
],
} as unknown as DocumentNode<
RequestChangeEmailMutation,
RequestChangeEmailMutationVariables
>;
export const RescindInviteCodeDocument = {
kind: "Document",
definitions: [
Expand Down Expand Up @@ -37483,6 +37605,73 @@ export const UpdateUserDocument = {
},
],
} as unknown as DocumentNode<UpdateUserMutation, UpdateUserMutationVariables>;
export const ValidateChangeEmailDocument = {
kind: "Document",
definitions: [
{
kind: "OperationDefinition",
operation: "mutation",
name: { kind: "Name", value: "ValidateChangeEmail" },
variableDefinitions: [
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "token" },
},
type: {
kind: "NonNullType",
type: { kind: "NamedType", name: { kind: "Name", value: "ID" } },
},
},
{
kind: "VariableDefinition",
variable: {
kind: "Variable",
name: { kind: "Name", value: "email" },
},
type: {
kind: "NonNullType",
type: {
kind: "NamedType",
name: { kind: "Name", value: "String" },
},
},
},
],
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "validateChangeEmail" },
arguments: [
{
kind: "Argument",
name: { kind: "Name", value: "token" },
value: {
kind: "Variable",
name: { kind: "Name", value: "token" },
},
},
{
kind: "Argument",
name: { kind: "Name", value: "email" },
value: {
kind: "Variable",
name: { kind: "Name", value: "email" },
},
},
],
},
],
},
},
],
} as unknown as DocumentNode<
ValidateChangeEmailMutation,
ValidateChangeEmailMutationVariables
>;
export const VoteDocument = {
kind: "Document",
definitions: [
Expand Down
Loading

0 comments on commit 96c1f77

Please sign in to comment.