Integrated the updateTOTP method into the account controller
This commit is contained in:
parent
d9f8447dd2
commit
20cd436321
@ -1,7 +1,7 @@
|
|||||||
import { Account } from "../models/Account";
|
import { Account } from "@models/Account";
|
||||||
import { genSalt, hash } from "bcrypt";
|
import { genSalt, hash } from "bcrypt";
|
||||||
import { sendMail } from "@utils/email";
|
import { sendMail } from "@utils/email";
|
||||||
import { Types } from "mongoose";
|
import { ObjectId, Types } from "mongoose";
|
||||||
import { encryptClearField } from "@utils/decryption";
|
import { encryptClearField } from "@utils/decryption";
|
||||||
|
|
||||||
export const sendVerificationEmail = async (email: string, code: number, id: string) => {
|
export const sendVerificationEmail = async (email: string, code: number, id: string) => {
|
||||||
@ -38,12 +38,25 @@ export const verifyAccount = async (configuration: { id: string, code: number })
|
|||||||
|
|
||||||
if (account === null) return { code: 1002, message: "The provided account does not exist" };
|
if (account === null) return { code: 1002, message: "The provided account does not exist" };
|
||||||
|
|
||||||
if (account.verified) return { code: 1003, message: "The provided account is already verified" }
|
if (account.verified) return { code: 1003, message: "The provided account is already verified" };
|
||||||
|
|
||||||
if (account.verificationSecret !== configuration.code) return {
|
if (account.verificationSecret !== configuration.code) return {
|
||||||
code: 1003,
|
code: 1003,
|
||||||
message: "The provided verification secret is wrong",
|
message: "The provided verification secret is wrong",
|
||||||
};
|
};
|
||||||
|
|
||||||
await Account.findByIdAndUpdate(configuration.id, {verified: true, $unset: {verificationSecret: 1}});
|
await Account.findByIdAndUpdate(configuration.id, { verified: true, $unset: { verificationSecret: 1 } });
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateTOTP = async (id: ObjectId | undefined, status: boolean) => {
|
||||||
|
const account = await Account.findById(id);
|
||||||
|
|
||||||
|
if (account === null) return { code: 1002, message: "The provided account does not exist" };
|
||||||
|
|
||||||
|
if (account.totpEnabled === status) return {
|
||||||
|
code: 1009,
|
||||||
|
message: `TOTP is already ${status ? "enabled" : "disabled"} on your account`,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Account.findByIdAndUpdate(id, { totpEnabled: status });
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user