update entity type and reset password
This commit is contained in:
@ -2,18 +2,18 @@ import { Response, NextFunction, Application } from "express";
|
||||
import { Request } from 'express-jwt'
|
||||
import { ReturnHelper } from "../helpers/express/return";
|
||||
import { OrmHelper } from "../helpers/orm";
|
||||
import { User } from "../entity/users";
|
||||
import Joi from "joi";
|
||||
import config from "config";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Language } from "../langs/lang";
|
||||
import { UserRefreshToken } from "../entity/user_refresh_token";
|
||||
import { UAParser } from 'ua-parser-js';
|
||||
import dayjs from 'dayjs'
|
||||
import jwt from 'jsonwebtoken';
|
||||
import fs from 'fs';
|
||||
import { UserRole } from "../entity/users_roles";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { EmailBody, User, UserRefreshToken, UserRole } from "Entity";
|
||||
import axios from 'axios';
|
||||
import CommonHelper from "../helpers/common";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[UserController]', type: 'pretty' });
|
||||
|
||||
@ -170,8 +170,30 @@ export class AuthController {
|
||||
await userRepository.save(user);
|
||||
|
||||
//send email reset password
|
||||
const url = config.get("service.notification") + "api/email/send";
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success, {});
|
||||
console.log(url, 'url')
|
||||
|
||||
const template_raw = fs.readFileSync('assets/reset_password.html').toString();
|
||||
|
||||
const pairMap = {
|
||||
'LINK': config.get('auth.reset_password_url') + user.reset_token,
|
||||
'NAME': user.name
|
||||
}
|
||||
|
||||
const template = CommonHelper.generateTemplate(template_raw, pairMap);
|
||||
|
||||
const email: EmailBody = {
|
||||
subject: "Reset Password",
|
||||
to: [user.email],
|
||||
cc: [],
|
||||
bcc: [],
|
||||
html: template
|
||||
}
|
||||
|
||||
const { data } = await axios.post(url, email);
|
||||
|
||||
return ReturnHelper.successResponseAny(res, 200, Language.lang.success, data);
|
||||
|
||||
|
||||
// return ReturnHelper.errorResponse(res, 403, 401, Language.lang.failed_access);
|
||||
|
||||
Reference in New Issue
Block a user