Skip to content

Commit

Permalink
Implemented initial account page
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelle-cardoso committed Nov 1, 2021
1 parent d6e3994 commit 432bf93
Show file tree
Hide file tree
Showing 29 changed files with 1,325 additions and 523 deletions.
24 changes: 24 additions & 0 deletions client/modules/impower-auth/utils/changeEmail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
EmailAuthProvider,
reauthenticateWithCredential,
updateEmail,
} from "firebase/auth";
import Auth from "../classes/auth";

const changeEmail = async (
password: string,
newEmail: string
): Promise<void> => {
const logInfo = (await import("../../impower-logger/utils/logInfo")).default;
logInfo("Auth", "UPDATING EMAIL");
const user = Auth.instance.internal.currentUser;
try {
await updateEmail(user, newEmail);
} catch {
const credential = EmailAuthProvider.credential(user.email, password);
await reauthenticateWithCredential(user, credential);
await updateEmail(user, newEmail);
}
};

export default changeEmail;
24 changes: 24 additions & 0 deletions client/modules/impower-auth/utils/changePassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
EmailAuthProvider,
reauthenticateWithCredential,
updatePassword,
} from "firebase/auth";
import Auth from "../classes/auth";

const changePassword = async (
oldPassword: string,
newPassword: string
): Promise<void> => {
const logInfo = (await import("../../impower-logger/utils/logInfo")).default;
logInfo("Auth", "UPDATING PASSWORD");
const user = Auth.instance.internal.currentUser;
try {
await updatePassword(user, newPassword);
} catch {
const credential = EmailAuthProvider.credential(user.email, oldPassword);
await reauthenticateWithCredential(user, credential);
await updatePassword(user, newPassword);
}
};

export default changePassword;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { SettingsDocument } from "../..";
import { Inspector } from "../../../impower-core";
import createSettingsDocument from "../../utils/createSettingsDocument";

export class SettingsDocumentInspector implements Inspector<SettingsDocument> {
private static _instance: SettingsDocumentInspector;

public static get instance(): SettingsDocumentInspector {
if (!this._instance) {
this._instance = new SettingsDocumentInspector();
}
return this._instance;
}

createData(data?: Partial<SettingsDocument>): SettingsDocument {
return createSettingsDocument(data);
}

isPropertyDisabled(propertyPath: string, data: SettingsDocument): boolean {
if (propertyPath === "nsfwBlurred") {
return !data.nsfwVisible;
}
return undefined;
}

getPropertyLabel(propertyPath: string, _data: SettingsDocument): string {
if (propertyPath === "nsfwVisible") {
return "Show NSFW content (I'm over 18)";
}
if (propertyPath === "nsfwBlurred") {
return "Blur NSFW images";
}
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ export class UserDocumentInspector implements Inspector<UserDocument> {
return createUserDocument(data);
}

getPropertyLabel(propertyPath: string, _data: UserDocument): string {
if (propertyPath === "username") {
return "Your username";
}
if (propertyPath === "bio") {
return "Your bio";
}
if (propertyPath === "icon") {
return "Your profile image";
}
return undefined;
}

getPropertyCharacterCountLimit(
propertyPath: string,
_data: UserDocument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ import { DataDocument } from "../../../impower-core";
export interface SettingsDocument extends DataDocument<"SettingsDocument"> {
_documentType: "SettingsDocument";
emailMarketing: boolean;
emailNotifications: boolean;
appNotifications: boolean;
nsfwVisible: boolean;
nsfwBlurred: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ const createSettingsDocument = (
doc?: Partial<SettingsDocument>
): SettingsDocument => ({
_documentType: "SettingsDocument",
emailMarketing: false,
nsfwVisible: false,
nsfwBlurred: false,
emailMarketing: false,
emailNotifications: false,
appNotifications: false,
...doc,
});

Expand Down
Loading

1 comment on commit 432bf93

@vercel
Copy link

@vercel vercel bot commented on 432bf93 Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.