auth for pg
This commit is contained in:
parent
19115d50fe
commit
49a9251426
@ -18,7 +18,7 @@ export class AuthController {
|
||||
|
||||
@Post('1/login')
|
||||
@HttpCode(200)
|
||||
async loginClient(@Body() body: AuthLoginOnlyDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) {
|
||||
async loginClienta(@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, 1);
|
||||
|
||||
@ -41,22 +41,79 @@ export class AuthController {
|
||||
return { statusCode: 200, message: "Logged-In Successfully", email: k.email }
|
||||
}
|
||||
|
||||
@Post('2/login')
|
||||
@HttpCode(200)
|
||||
async loginClientb(@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, 2);
|
||||
|
||||
if (k.access_token) {
|
||||
res.cookie('access_token', k.access_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
if (k.refresh_token) {
|
||||
res.cookie('refresh_token', k.refresh_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
return { statusCode: 200, message: "Logged-In Successfully", email: k.email }
|
||||
}
|
||||
|
||||
// @UseGuards(RegisterGuard)
|
||||
@Post('1/register')
|
||||
async register(@Body() body: AuthLoginDTO) {
|
||||
async registera(@Body() body: AuthLoginDTO) {
|
||||
return this.authService.registerUser(body, 1);
|
||||
}
|
||||
|
||||
@Post('2/register')
|
||||
async registerb(@Body() body: AuthLoginDTO) {
|
||||
return this.authService.registerUser(body, 1);
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('1/forgot-password')
|
||||
async forgotPassword(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
async forgotPassworda(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('2/forgot-password')
|
||||
async forgotPasswordb(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@UseInterceptors(LogoutInterceptor)
|
||||
@HttpCode(200)
|
||||
@Post('1/logout')
|
||||
async logout(@Req() req: any, @Res() res: Response) {
|
||||
async logouta(@Req() req: any, @Res() res: Response) {
|
||||
const refreshToken = req.user?.refreshToken;
|
||||
let rst: any = await this.authService.logoutUser(refreshToken);
|
||||
if (rst.statusCode === 200) {
|
||||
res.clearCookie('access_token', {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none'
|
||||
});
|
||||
res.clearCookie('refresh_token', {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none'
|
||||
});
|
||||
}
|
||||
res.json({ ...rst })
|
||||
}
|
||||
|
||||
@UseInterceptors(LogoutInterceptor)
|
||||
@HttpCode(200)
|
||||
@Post('2/logout')
|
||||
async logoutb(@Req() req: any, @Res() res: Response) {
|
||||
const refreshToken = req.user?.refreshToken;
|
||||
let rst: any = await this.authService.logoutUser(refreshToken);
|
||||
if (rst.statusCode === 200) {
|
||||
@ -75,7 +132,34 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Get('1/refresh-tokens')
|
||||
async getTokenFromRefreshToken(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
async getTokenFromRefreshTokena(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
let k: any = await this.authService.getTokenFromRefreshToken(req)
|
||||
|
||||
if (k.access_token) {
|
||||
res.cookie('access_token', k.access_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none',
|
||||
maxAge: 8 * 60 * 60 * 1000,
|
||||
path: '/'
|
||||
});
|
||||
}
|
||||
|
||||
if (k.refresh_token) {
|
||||
res.cookie('refresh_token', k.refresh_token, {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'none',
|
||||
maxAge: 8 * 60 * 60 * 1000,
|
||||
path: '/'
|
||||
});
|
||||
}
|
||||
|
||||
return { statusCode: 200, message: "Tokens refreshed successfully" }
|
||||
}
|
||||
|
||||
@Get('2/refresh-tokens')
|
||||
async getTokenFromRefreshTokenb(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
let k: any = await this.authService.getTokenFromRefreshToken(req)
|
||||
|
||||
if (k.access_token) {
|
||||
@ -112,7 +196,7 @@ export class AuthController {
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('sa')
|
||||
@Roles('psa')
|
||||
@Post('2/sendmail')
|
||||
@HttpCode(200)
|
||||
async sendMailb(@Body() body: SendMailDTO) {
|
||||
|
||||
@ -278,7 +278,7 @@ export class AuthService {
|
||||
let ROLE = "";
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
switch ((emailVerifyResponse[0].SOURCE + "".toUpperCase())) {
|
||||
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;
|
||||
@ -286,9 +286,9 @@ export class AuthService {
|
||||
}
|
||||
|
||||
const isValidCombo =
|
||||
(applicationName === 'policy' && ROLE === 'ua') ||
|
||||
(applicationName === 'service-provider' && ROLE === 'sa') ||
|
||||
(applicationName === 'client' && ROLE === 'ca');
|
||||
(applicationName === 'policy' && ROLE === (dbtype === 1 ? 'ua' : dbtype === 2 ? 'pua' : null)) ||
|
||||
(applicationName === 'service-provider' && ROLE === (dbtype === 1 ? 'sa' : dbtype === 2 ? 'psa' : null)) ||
|
||||
(applicationName === 'client' && ROLE === (dbtype === 1 ? 'ca' : dbtype === 2 ? 'pca' : null));
|
||||
|
||||
if (!isValidCombo) {
|
||||
throw new UnauthorizedException("Authentication failed")
|
||||
@ -584,7 +584,7 @@ export class AuthService {
|
||||
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
switch ((emailVerifyResponse[0].SOURCE + "".toUpperCase())) {
|
||||
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;
|
||||
|
||||
@ -7,8 +7,8 @@ import { RegionService } from './region.service';
|
||||
import { InsertRegionsDto, SPID_DTO, UpdateRegionDto } from 'src/dto/property.dto';
|
||||
|
||||
@ApiTags('Regions - PG')
|
||||
// @UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('sa', 'ua')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles('psa', 'pua')
|
||||
@Controller('2')
|
||||
export class RegionController {
|
||||
constructor(private readonly regionService: RegionService) { }
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { RegionController } from './region.controller';
|
||||
import { RegionService } from './region.service';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [forwardRef(() => AuthModule)],
|
||||
controllers: [RegionController],
|
||||
providers: [RegionService]
|
||||
})
|
||||
export class RegionModule {}
|
||||
export class RegionModule { }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user