diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 1a40a60..d8208e1 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -305,22 +305,22 @@ export class AuthService { // throw new BadRequestException("Invalid username or password") // } - if (access_token && refresh_token && userSession.length > 0) { + // if (access_token && refresh_token && userSession.length > 0) { - const getSub: any = jwt.decode(refresh_token, { complete: true }) + // const getSub: any = jwt.decode(refresh_token, { complete: true }) - const user: any = await this.getUserDetailsById(getSub?.payload.sub) + // const user: any = await this.getUserDetailsById(getSub?.payload.sub) - if (user.email !== username) { - throw new UnauthorizedException("Authentication failed") - } + // if (user.email !== username) { + // throw new UnauthorizedException("Authentication failed") + // } - let tokens = await this.getTokenFromRefreshToken(req); - const decoded = jwt.decode(access_token, { complete: true }); - const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined; - return { ...tokens, email, ApplicationName: ROLE } + // let tokens = await this.getTokenFromRefreshToken(req); + // const decoded = jwt.decode(access_token, { complete: true }); + // const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined; + // return { ...tokens, email, ApplicationName: ROLE } - } + // } const response = await axios.post(this.TOKEN_URL, params, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -842,9 +842,29 @@ export class AuthService { } } - async getMailTemplate(body: SendMailDTO, token: string, source: string, appDomain:string): Promise { + async getMailTemplate(body: SendMailDTO, token: string, source: string, appDomain: string): Promise { switch (body.P_MAIL_TYPE) { + case MailTypeDTO.REGISTER_USCIB: + return { + to: body.P_TO, + subject: `🔐 Register Your Account`, + templateName: 'a', + variables: { + to: body.P_TO, + url: `https://${appDomain.toLowerCase() === "policy" ? "policy" : appDomain.toLowerCase() === "policy-1" ? "policy-1" : appDomain.toLowerCase() === "policy-2" ? "policy-2" : ""}.alphaomegainfosys.com/register` + } + } + case MailTypeDTO.REGISTER_SP: + return { + to: body.P_TO, + subject: `🔐 Register Your Account`, + templateName: 'a', + variables: { + to: body.P_TO, + url: `https://${appDomain.toLowerCase() === "sp" ? "sp" : appDomain.toLowerCase() === "sp-1" ? "sp-1" : appDomain.toLowerCase() === "sp-2" ? "sp-2" : ""}.alphaomegainfosys.com/register` + } + } case MailTypeDTO.REGISTER_CLIENT: return { to: body.P_TO, @@ -852,7 +872,7 @@ export class AuthService { templateName: 'a', variables: { to: body.P_TO, - url: `https://${appDomain.toLowerCase() === "sp" ? "client" : appDomain.toLowerCase() === "sp-1" ? "client-1":appDomain.toLowerCase() === "sp-2"?"client-2": "" }.alphaomegainfosys.com/register` + url: `https://${appDomain.toLowerCase() === "sp" ? "client" : appDomain.toLowerCase() === "sp-1" ? "client-1" : appDomain.toLowerCase() === "sp-2" ? "client-2" : ""}.alphaomegainfosys.com/register` } } case MailTypeDTO.FORGOT_PASSWORD: @@ -864,13 +884,13 @@ export class AuthService { to: body.P_TO, url: `${appDomain.toLowerCase() === 'policy' ? `https://policy.alphaomegainfosys.com/forgot-password/${token}` : appDomain.toLowerCase() === 'policy-1' ? `https://policy-1.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'policy-2' ? `https://policy-2.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'sp' ? `https://sp.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'sp-1' ? `https://sp-1.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'sp-2' ? `https://sp-2.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'client' ? `https://client.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'client-1' ? `https://client-1.alphaomegainfosys.com/forgot-password/${token}` - : appDomain.toLowerCase() === 'client-2' ? `https://client-2.alphaomegainfosys.com/forgot-password/${token}` : ''}` + : appDomain.toLowerCase() === 'policy-2' ? `https://policy-2.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'sp' ? `https://sp.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'sp-1' ? `https://sp-1.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'sp-2' ? `https://sp-2.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'client' ? `https://client.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'client-1' ? `https://client-1.alphaomegainfosys.com/forgot-password/${token}` + : appDomain.toLowerCase() === 'client-2' ? `https://client-2.alphaomegainfosys.com/forgot-password/${token}` : ''}` } } default: diff --git a/src/guards/roles.guard.ts b/src/guards/roles.guard.ts index cd86e12..83ed376 100644 --- a/src/guards/roles.guard.ts +++ b/src/guards/roles.guard.ts @@ -37,7 +37,7 @@ export class RolesGuard implements CanActivate { try { const decoded: any = jwt.decode(token); - const roles: string[] = decoded?.resource_access?.['carnet-app']?.roles || []; + const roles: string[] = decoded?.resource_access?.[process.env.CLIENT_ID || '']?.roles || []; const hasRole = requiredRoles.some(role => roles.includes(role)); if (!hasRole) { diff --git a/src/main.ts b/src/main.ts index a152e6b..73722a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,7 +20,12 @@ async function bootstrap() { 'http://localhost:5173', 'https://policy.alphaomegainfosys.com', 'https://sp.alphaomegainfosys.com', - 'https://client.alphaomegainfosys.com' + 'https://policy-2.alphaomegainfosys.com', + 'https://client-2.alphaomegainfosys.com', + 'https://sp-2.alphaomegainfosys.com', + 'https://policy-1.alphaomegainfosys.com', + 'https://client-1.alphaomegainfosys.com', + 'https://sp-1.alphaomegainfosys.com', ], methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, diff --git a/src/pg/manage-clients/manage-clients.service.ts b/src/pg/manage-clients/manage-clients.service.ts index 3a49556..01f08e5 100644 --- a/src/pg/manage-clients/manage-clients.service.ts +++ b/src/pg/manage-clients/manage-clients.service.ts @@ -436,7 +436,7 @@ export class ManageClientsService { const pgArrayLiteral = `{${addressLiterals.join(',')}}`; const callProcQuery = ` - CALL "CARNETSYS".managepreparer_pkg_updateclientlocations($1, $2, $3::"CARNETSYS".addresstable[], $4, $5) + CALL "CARNETSYS".managepreparer_pkg_createclientlocation($1, $2, $3::"CARNETSYS".addresstable[], $4, $5) `; await client.query(callProcQuery, [ @@ -515,7 +515,7 @@ export class ManageClientsService { await client.query('BEGIN'); const callProcQuery = ` - CALL "CARNETSYS".managepreparer_pkg_getpreparerlocbyclientid($1, $2, $3) + CALL "CARNETSYS".managepreparer_pkg_GetPreparerByClientid($1, $2, $3) `; await client.query(callProcQuery, [body.P_SPID, body.P_CLIENTID, cursorName]); diff --git a/src/pg/user-maintenance/user-maintenance.controller.ts b/src/pg/user-maintenance/user-maintenance.controller.ts index 522f2e0..e66f167 100644 --- a/src/pg/user-maintenance/user-maintenance.controller.ts +++ b/src/pg/user-maintenance/user-maintenance.controller.ts @@ -41,8 +41,8 @@ export class UserMaintenanceController { @Post('CreateUSCIBLogins') @Roles('pua') - async CreateUSCIBLogins(@Body() body: CreateUSCIBLoginsDTO) { - return await this.userMaintenanceService.CreateUSCIBLogins(body); + async CreateUSCIBLogins(@Body() body: CreateUSCIBLoginsDTO, @Req() req: Request) { + return await this.userMaintenanceService.CreateUSCIBLogins(body, req); } // SP LOGINS @@ -56,7 +56,7 @@ export class UserMaintenanceController { @Post('CreateSPLogins') @Roles('psa') async CreateSPLogins(@Body() body: CreateSPLoginsDTO, @Req() req: Request) { - return await this.userMaintenanceService.CreateSPLogins(body,req); + return await this.userMaintenanceService.CreateSPLogins(body, req); } // CLIENT LOGINS diff --git a/src/pg/user-maintenance/user-maintenance.service.ts b/src/pg/user-maintenance/user-maintenance.service.ts index 800c7fc..b4226f3 100644 --- a/src/pg/user-maintenance/user-maintenance.service.ts +++ b/src/pg/user-maintenance/user-maintenance.service.ts @@ -162,7 +162,7 @@ export class UserMaintenanceService { } } - async CreateUSCIBLogins(body: CreateUSCIBLoginsDTO) { + async CreateUSCIBLogins(body: CreateUSCIBLoginsDTO, req: Request) { let client: PoolClient | null = null; @@ -194,6 +194,20 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); + let appDomain; + if (req.headers.origin) { + appDomain = extractSubdomain(req.headers.origin) + } + else { + appDomain = "" + } + + const mailRes = await this.authService.sendMail({ P_TO: body.P_USERID, P_MAIL_TYPE: MailTypeDTO.REGISTER_USCIB }, appDomain) + + if (mailRes.statusCode !== 200) { + throw new InternalServerException(); + } + return { statusCode: 201, message: ResponseStatus.created,