Cleanup, add reset password func

This commit is contained in:
oitsjustjose 2022-04-15 07:58:47 -05:00
commit 0d5cd1f4a5
8 changed files with 78 additions and 97 deletions

View file

@ -1 +0,0 @@
export default [];

View file

@ -1,5 +1,4 @@
import { Request, Response } from "express";
import AdminRoutes from "./admin/routes";
import ProductRoutes from "./product/routes";
import ReviewRoutes from "./review/routes";
import UserRoutes from "./user/routes";
@ -14,7 +13,6 @@ const routes: RouteCollection[] = [
...ProductRoutes,
...UserRoutes,
...ReviewRoutes,
...AdminRoutes,
];
export default routes;

View file

@ -1,6 +1,6 @@
import EmailValidator from "email-validator";
import { Request, Response } from "express";
import Validate from "../../../email/templates/Validate";
import ValidateEmail from "../../../email/templates/ValidateEmail";
import Users from "../../../models/User";
import { LOGGER } from "../../../util/Logger";
@ -38,7 +38,7 @@ export default async (req: Request, res: Response) => {
created.password = created.hashPassword(password);
await created.save();
await Validate(created);
await ValidateEmail(created);
return res.status(200).json(created);
} catch (ex) {

View file

@ -0,0 +1,25 @@
import { Request, Response } from "express";
import Users from "../../../models/User";
import ResetPasswordEmail from "../../../email/templates/ResetPasswordEmail";
export default async (req: Request, res: Response) => {
try {
const email: string | null = req.query.email as string;
if (!email) {
return res.status(422).json({ error: "No email provided." });
}
const user = await Users.findOne({ email });
if (!user) {
return res
.status(404)
.json({ error: "User with given email not found." });
}
await ResetPasswordEmail(user);
return res.status(200).send();
} catch (ex) {
return res.status(500).json({ error: ex });
}
};

View file

@ -1,7 +1,7 @@
import { Request, Response } from "express";
import Users from "../../../models/User";
import { LOGGER } from "../../../util/Logger";
import Validate from "../../../email/templates/Validate";
import ValidateEmail from "../../../email/templates/ValidateEmail";
export default async (req: Request, res: Response) => {
try {
@ -27,7 +27,7 @@ export default async (req: Request, res: Response) => {
await user.save();
if (req.body.email) {
await Validate(user);
await ValidateEmail(user);
}
return res.status(200).json({ "Successfully Deleted": user });