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);
|
||||
|
||||
@ -2,11 +2,11 @@ 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 { User } from "Entity";
|
||||
import Joi from "joi";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Language } from "../langs/lang";
|
||||
import { Paging } from "../types/paging";
|
||||
import { Paging } from "Entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import * as fastcsv from 'fast-csv';
|
||||
import dayjs from "dayjs";
|
||||
|
||||
@ -5,12 +5,12 @@ import { OrmHelper } from "../helpers/orm";
|
||||
import Joi from "joi";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Language } from "../langs/lang";
|
||||
import { Paging } from "../types/paging";
|
||||
import { Paging } from "Entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import { ActivityType } from "../types/action";
|
||||
import { UserActivity } from "../entity/user_activity";
|
||||
import { ActivityType } from "Entity";
|
||||
import * as fastcsv from 'fast-csv';
|
||||
import dayjs from "dayjs";
|
||||
import { UserActivity } from "Entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[UserActivityController]', type: 'pretty' });
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@ import { OrmHelper } from "../helpers/orm";
|
||||
import Joi from "joi";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Language } from "../langs/lang";
|
||||
import { Paging } from "../types/paging";
|
||||
import { Paging } from "Entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import { UserRefreshToken } from "../entity/user_refresh_token";
|
||||
import { UserRefreshToken } from "Entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[UserRefreshTokenController]', type: 'pretty' });
|
||||
|
||||
|
||||
@ -4,13 +4,13 @@ import { OrmHelper } from "../helpers/orm";
|
||||
import Joi from "joi";
|
||||
import { ILogObj, Logger } from "tslog";
|
||||
import { Language } from "../langs/lang";
|
||||
import { Paging } from "../types/paging";
|
||||
import { Paging } from "Entity";
|
||||
import CommonHelper from "../helpers/common";
|
||||
import { Status } from "../types/status";
|
||||
import { UserRole } from "../entity/users_roles";
|
||||
import { RoleList } from "../types/role";
|
||||
import { Status } from "Entity";
|
||||
import { RoleList } from "Entity";
|
||||
import * as fastcsv from 'fast-csv';
|
||||
import dayjs from "dayjs";
|
||||
import { UserRole } from "Entity";
|
||||
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[UserRoleController]', type: 'pretty' });
|
||||
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm';
|
||||
|
||||
import { ActivityType } from '../types/action';
|
||||
|
||||
@Entity('user_activities')
|
||||
export class UserActivity {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
type: 'uuid'
|
||||
})
|
||||
id_user: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
type: 'uuid'
|
||||
})
|
||||
refresh_token: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 512
|
||||
})
|
||||
module: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 2048
|
||||
})
|
||||
description: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 1
|
||||
})
|
||||
action: ActivityType;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 2048,
|
||||
})
|
||||
url: String;
|
||||
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true,
|
||||
})
|
||||
data_body: String;
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
created_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@UpdateDateColumn()
|
||||
updated_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@DeleteDateColumn()
|
||||
deleted_at: Date;
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm';
|
||||
|
||||
@Entity('user_refresh_tokens')
|
||||
export class UserRefreshToken {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
refresh_token: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
type: 'uuid'
|
||||
})
|
||||
id_user: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 4096,
|
||||
})
|
||||
user_agent: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 128
|
||||
})
|
||||
os: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 256
|
||||
})
|
||||
device: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 64
|
||||
})
|
||||
platform: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 64
|
||||
})
|
||||
browser: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 32
|
||||
})
|
||||
remote_addr: string;
|
||||
|
||||
@Column('timestamp')
|
||||
expired_at: Date;
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
created_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@UpdateDateColumn()
|
||||
updated_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@DeleteDateColumn()
|
||||
deleted_at: Date;
|
||||
}
|
||||
@ -1,76 +0,0 @@
|
||||
import bcrypt from 'bcryptjs';
|
||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn, Index } from 'typeorm';
|
||||
|
||||
import { Status } from '../types/status';
|
||||
|
||||
@Entity('users')
|
||||
export class User {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
length: 64
|
||||
})
|
||||
email: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 64,
|
||||
select: false
|
||||
})
|
||||
password: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
length: 64
|
||||
})
|
||||
username: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 64
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'uuid'
|
||||
})
|
||||
id_role: string;
|
||||
|
||||
@Index()
|
||||
@Column({
|
||||
nullable: true,
|
||||
type: 'uuid'
|
||||
})
|
||||
reset_token: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 64
|
||||
})
|
||||
status: Status;
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
created_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@UpdateDateColumn()
|
||||
updated_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@DeleteDateColumn()
|
||||
deleted_at: Date;
|
||||
|
||||
hashPassword() {
|
||||
this.password = bcrypt.hashSync(this.password, 8);
|
||||
}
|
||||
|
||||
checkIfPasswordMatch(unencryptedPassword: string) {
|
||||
return bcrypt.compareSync(unencryptedPassword, this.password);
|
||||
}
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
|
||||
|
||||
import { Status } from '../types/status';
|
||||
import { RoleList } from '../types/role';
|
||||
|
||||
@Entity('user_roles')
|
||||
export class UserRole {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
length: 128
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
type: 'jsonb'
|
||||
})
|
||||
roles: RoleList[];
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
length: 64
|
||||
})
|
||||
status: Status;
|
||||
|
||||
@Column()
|
||||
@CreateDateColumn()
|
||||
created_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@UpdateDateColumn()
|
||||
updated_at: Date;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@DeleteDateColumn()
|
||||
deleted_at: Date;
|
||||
}
|
||||
@ -81,4 +81,14 @@ export default class CommonHelper {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
static generateTemplate(template: string, pairMap: any): string {
|
||||
for (let p in pairMap) {
|
||||
let v = pairMap[p];
|
||||
|
||||
template = template.split('{' + p + '}').join(v);
|
||||
}
|
||||
|
||||
return template
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { Response } from 'express';
|
||||
import { ErrorType, ErrorValidation } from '../../types/error';
|
||||
import { ErrorType, ErrorValidation } from 'Entity';
|
||||
|
||||
export class ReturnHelper {
|
||||
static successResponseAny(
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
import config from 'config';
|
||||
import { DataSource } from "typeorm";
|
||||
import { User } from "../entity/users";
|
||||
import { User, UserActivity, UserRefreshToken, UserRole } from "Entity";
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
import { UserActivity } from '../entity/user_activity';
|
||||
import { UserRefreshToken } from '../entity/user_refresh_token';
|
||||
import { UserRole } from '../entity/users_roles';
|
||||
|
||||
export class OrmHelper {
|
||||
static DB: DataSource = null
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
export enum ActivityType {
|
||||
"Create" = "C",
|
||||
"View" = "V",
|
||||
"Update" = "U",
|
||||
"Delete" = "D",
|
||||
"Restore" = "T",
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
export type ErrorType = 'General' | 'Raw' | 'Validation' | 'Unauthorized';
|
||||
|
||||
export type ErrorValidation = { [key: string]: string };
|
||||
@ -1,8 +0,0 @@
|
||||
export interface Paging {
|
||||
page: number,
|
||||
limit: number,
|
||||
filter: any,
|
||||
with_deleted: boolean,
|
||||
order_field: string,
|
||||
order_direction: 'ASC' | 'DESC'
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
export enum RoleList {
|
||||
"Dashboard" = "dashboard",
|
||||
"Kinerja UKLN" = "ukln",
|
||||
"Dana Pihak Ketiga" = "dpk",
|
||||
"Posisi Outstanding Pinjaman" = "outstanding_loan",
|
||||
"Presentasi NPL" = "npl",
|
||||
"PPAP Amount NPL" = "ppap_amount",
|
||||
"Report Regulator Bulanan" = "regulator_bulanan",
|
||||
"Report Regulator Triwulan" = "regulator_triwulan",
|
||||
"Report Regulator Publikasi" = "regulator_publikasi",
|
||||
"Perhitungan Simulasi Perpajakan Per Bulan" = "pajak_per_bulan",
|
||||
"Perhitungan Simulasi Perpajakan Per Tahun" = "pajak_per_tahun",
|
||||
"Data Nasabah Potensial" = "nasabah_potensial",
|
||||
"Master Data User" = "master_user",
|
||||
"Master Data Product" = "master_product",
|
||||
"Master Data Tier" = "master_tier",
|
||||
"Master Klasifikasi Ekonomi" = "master_klasifikasi_ekonomi",
|
||||
"Master District" = "master_district",
|
||||
"Master Munisipu" = "master_munisipu",
|
||||
"Master Administrativu" = "master_administrativu",
|
||||
"Master Suco" = "master_suco",
|
||||
"Master Aldeia" = "master_aldeia",
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
export enum Status {
|
||||
"Active" = "Y",
|
||||
"Not Active" = "N"
|
||||
};
|
||||
Reference in New Issue
Block a user