Cleanup, add reset password func
This commit is contained in:
parent
99a3d7ff33
commit
0d5cd1f4a5
8 changed files with 78 additions and 97 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
25
backend/src/app/controllers/user/crud/forgot.ts
Normal file
25
backend/src/app/controllers/user/crud/forgot.ts
Normal 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 });
|
||||
}
|
||||
};
|
||||
|
|
@ -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 });
|
||||
|
|
|
|||
Loading…
Reference in a new issue