api modified for auth
This commit is contained in:
parent
7b8e595a92
commit
c4e4546c4b
@ -8,11 +8,12 @@ import { ConfigModule } from '@nestjs/config';
|
||||
import { MailModule } from './mail/mail.module';
|
||||
import { PaypalModule } from './paypal/paypal.module';
|
||||
import { PgModule } from './pg/pg.module';
|
||||
import { CommonModule } from './common/common.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }), PgModule,
|
||||
AuthModule, DbModule, OracleModule, MailModule, PaypalModule
|
||||
AuthModule, DbModule, OracleModule, MailModule, PaypalModule, CommonModule
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
||||
@ -10,17 +10,17 @@ import { Roles } from 'src/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@Controller("1")
|
||||
@Controller()
|
||||
export class AuthController {
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
) { }
|
||||
|
||||
@Post('login')
|
||||
@Post('1/login')
|
||||
@HttpCode(200)
|
||||
async loginClient(@Body() body: AuthLoginOnlyDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) {
|
||||
|
||||
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req);
|
||||
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req, 1);
|
||||
|
||||
if (k.access_token) {
|
||||
res.cookie('access_token', k.access_token, {
|
||||
@ -42,9 +42,15 @@ export class AuthController {
|
||||
}
|
||||
|
||||
// @UseGuards(RegisterGuard)
|
||||
@Post('register')
|
||||
@Post('1/register')
|
||||
async register(@Body() body: AuthLoginDTO) {
|
||||
return this.authService.registerUser(body);
|
||||
return this.authService.registerUser(body, 1);
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('1/forgot-password')
|
||||
async forgotPassword(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@UseInterceptors(LogoutInterceptor)
|
||||
@ -68,12 +74,6 @@ export class AuthController {
|
||||
res.json({ ...rst })
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('forgot-password')
|
||||
async forgotPassword(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@Get('refresh-tokens')
|
||||
async getTokenFromRefreshToken(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
let k: any = await this.authService.getTokenFromRefreshToken(req)
|
||||
|
||||
@ -6,9 +6,10 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { OracleModule } from 'src/oracle/oracle.module';
|
||||
import { MailModule } from 'src/mail/mail.module';
|
||||
import { PgModule } from 'src/pg/pg.module';
|
||||
|
||||
@Module({
|
||||
imports: [DbModule,MailModule, forwardRef(() => OracleModule)],
|
||||
imports: [DbModule,MailModule, forwardRef(() => OracleModule), forwardRef(() => PgModule)],
|
||||
providers: [
|
||||
AuthService,
|
||||
{
|
||||
|
||||
@ -11,9 +11,10 @@ import { UnauthorizedException } from 'src/exceptions/unauthorized.exception';
|
||||
import { ConflictException } from 'src/exceptions/conflict.exception';
|
||||
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { UserMaintenanceService } from 'src/oracle/user-maintenance/user-maintenance.service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { MailService } from 'src/mail/mail.service';
|
||||
import { UserMaintenanceService as OracleUserMaintenanceService } from 'src/oracle/user-maintenance/user-maintenance.service';
|
||||
import { UserMaintenanceService as PgUserMaintenanceService } from 'src/pg/user-maintenance/user-maintenance.service';
|
||||
|
||||
|
||||
interface DecodedToken {
|
||||
@ -44,7 +45,8 @@ export class AuthService {
|
||||
private readonly oracleDBService: OracleDBService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly mailService: MailService,
|
||||
private readonly userMaintenanceService: UserMaintenanceService,
|
||||
private readonly oracleUserMaintenanceService: OracleUserMaintenanceService,
|
||||
private readonly pgUserMaintenanceService: PgUserMaintenanceService,
|
||||
@Inject("REGISTER_SIGN_JWT") readonly REGISTER_SIGN_JWT: JwtService,
|
||||
@Inject("REGISTER_VERIFY_JWT") readonly REGISTER_VERIFY_JWT: JwtService
|
||||
) {
|
||||
@ -245,7 +247,7 @@ export class AuthService {
|
||||
return verified;
|
||||
}
|
||||
|
||||
async loginUser(username: string, password: string, applicationName: string, req: Request): Promise<any> {
|
||||
async loginUser(username: string, password: string, applicationName: string, req: Request, dbtype: number): Promise<any> {
|
||||
|
||||
const access_token = req.cookies?.access_token;
|
||||
const refresh_token = req.cookies?.refresh_token;
|
||||
@ -260,7 +262,14 @@ export class AuthService {
|
||||
try {
|
||||
const userSession = await this.getUserSession(username)
|
||||
|
||||
const emailVerifyResponse: any = await this.userMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
let emailVerifyResponse: any;
|
||||
|
||||
if (dbtype === 1) {
|
||||
emailVerifyResponse = await this.oracleUserMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
}
|
||||
else if (dbtype === 2) {
|
||||
emailVerifyResponse = await this.pgUserMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
}
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && emailVerifyResponse[0].ERRORMESG) {
|
||||
throw new BadRequestException();
|
||||
@ -270,9 +279,9 @@ export class AuthService {
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
case "USCIB": ROLE = 'ua'; break;
|
||||
case "SP": ROLE = 'sa'; break;
|
||||
case "CLIENT": ROLE = 'ca'; break;
|
||||
case "USCIB": ROLE = dbtype === 1 ? 'ua' : dbtype === 2 ? 'pua' : ''; break;
|
||||
case "SP": ROLE = dbtype === 1 ? 'sa' : dbtype === 2 ? 'psa' : ''; break;
|
||||
case "CLIENT": ROLE = dbtype === 1 ? 'ca' : dbtype === 2 ? 'pca' : ''; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,7 +447,6 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async forgotPassword(body: AuthLoginDTO, req: Request) {
|
||||
|
||||
let det = await req['user'];
|
||||
@ -512,13 +520,21 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async registerUser(body: AuthLoginDTO) {
|
||||
async registerUser(body: AuthLoginDTO, dbtype: number) {
|
||||
// let det = await req['user'];
|
||||
// if (det?.email !== body.P_EMAILADDR) {
|
||||
// throw new BadRequestException();
|
||||
// }
|
||||
|
||||
const emailVerifyResponse: any = await this.userMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
let emailVerifyResponse: any;
|
||||
|
||||
if (dbtype === 1) {
|
||||
emailVerifyResponse = await this.oracleUserMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
}
|
||||
else if (dbtype === 2) {
|
||||
emailVerifyResponse = await this.pgUserMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
}
|
||||
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && emailVerifyResponse[0].ERRORMESG) {
|
||||
throw new BadRequestException();
|
||||
@ -569,9 +585,9 @@ export class AuthService {
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
case "USCIB": ROLE = 'ua'; break;
|
||||
case "SP": ROLE = 'sa'; break;
|
||||
case "CLIENT": ROLE = 'ca'; break;
|
||||
case "USCIB": ROLE = dbtype === 1 ? 'ua' : dbtype === 2 ? 'pua' : ''; break;
|
||||
case "SP": ROLE = dbtype === 1 ? 'sa' : dbtype === 2 ? 'psa' : ''; break;
|
||||
case "CLIENT": ROLE = dbtype === 1 ? 'ca' : dbtype === 2 ? 'pca' : ''; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,8 +734,6 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getTokenFromRefreshToken(req: Request) {
|
||||
|
||||
const refreshToken = req.cookies['refresh_token'];
|
||||
|
||||
@ -7,6 +7,6 @@ import { AuthModule } from 'src/auth/auth.module';
|
||||
imports: [forwardRef(() => AuthModule)],
|
||||
controllers: [UserMaintenanceController],
|
||||
providers: [UserMaintenanceService],
|
||||
exports: [UserMaintenanceService, AuthModule]
|
||||
exports: [UserMaintenanceService]
|
||||
})
|
||||
export class UserMaintenanceModule { }
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ParamTableModule } from './param-table/param-table.module';
|
||||
import { DbModule } from 'src/db/db.module';
|
||||
import { UscibManagedSpModule } from './uscib-managed-sp/uscib-managed-sp.module';
|
||||
import { UserMaintenanceModule } from './user-maintenance/user-maintenance.module';
|
||||
import { ManageFeeModule } from './manage-fee/manage-fee.module';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [DbModule, ParamTableModule, UscibManagedSpModule, UserMaintenanceModule, ManageFeeModule],
|
||||
providers: [],
|
||||
exports: [UserMaintenanceModule]
|
||||
})
|
||||
export class PgModule { }
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { UserMaintenanceController } from './user-maintenance.controller';
|
||||
import { UserMaintenanceService } from './user-maintenance.service';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [forwardRef(() => AuthModule)],
|
||||
controllers: [UserMaintenanceController],
|
||||
providers: [UserMaintenanceService]
|
||||
providers: [UserMaintenanceService],
|
||||
exports: [UserMaintenanceService]
|
||||
})
|
||||
export class UserMaintenanceModule {}
|
||||
export class UserMaintenanceModule { }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { CreateClientLoginsDTO, CreateSPLoginsDTO, CreateUSCIBLoginsDTO, EMAIL_DTO, SPID_CLIENTID_DTO, SPID_DTO, SPID_EMAIL_DTO, USERID_DTO } from 'src/dto/property.dto';
|
||||
import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper';
|
||||
|
||||
@ -15,7 +15,7 @@ export class UserMaintenanceService {
|
||||
|
||||
constructor(
|
||||
private readonly pgDBService: PgDBService,
|
||||
// @Inject(forwardRef(() => AuthService))
|
||||
@Inject(forwardRef(() => AuthService))
|
||||
private readonly authService: AuthService
|
||||
) { }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user