auth and mail template fixed

This commit is contained in:
Kallesh B S 2025-07-11 11:30:58 +05:30
parent cfb09b1f16
commit b553ff0623
4 changed files with 57 additions and 11 deletions

View File

@ -4,7 +4,7 @@
{{!-- <p style="font-size: 16px;">A Registration has been successfully initiated for the email: <strong>{{to}}</strong></p> --}}
<p>Please click below to complete your password reset:</p>
<a href={{url}} style="display: inline-block; margin-top: 20px; background-color: #007BFF; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; font-size: 16px;">
Register Now
Reset Now
</a>
<div style="margin-top: 40px;">
<p style="color: #888;">Powered by</p>

View File

@ -5,7 +5,6 @@ import { AuthLoginDTO, SendMailDTO } from './auth.dto';
import { Request, Response } from 'express';
import { LogoutInterceptor } from 'src/interceptors/logout.interceptor';
import { RegisterGuard } from 'src/guards/register.guard';
import { UserMaintenanceService } from 'src/oracle/user-maintenance/user-maintenance.service';
import { RolesGuard } from 'src/guards/roles.guard';
import { Roles } from 'src/decorators/roles.decorator';
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
@ -15,18 +14,17 @@ import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
export class AuthController {
constructor(
private readonly authService: AuthService,
private readonly userMaintenanceService: UserMaintenanceService
) { }
@Post('login')
@HttpCode(200)
async loginClient(@Body() body: AuthLoginDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) {
let k: any = await this.authService.loginUser(body.P_EMAILADDR, body.P_PASSWORD, req);
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, req);
if (k.access_token) {
res.cookie('access_token', k.access_token, {
httpOnly: true,
secure: true,
secure: true,
sameSite: 'none',
maxAge: 8 * 60 * 60 * 1000,
});

View File

@ -267,11 +267,23 @@ export class AuthService {
try {
const userSession = await this.getUserSession(username)
if (access_token && refresh_token && userSession.length > 0) {
const getSub: any = jwt.decode(refresh_token, { complete: true })
const user: any = await this.getUserDetailsById(getSub?.payload.sub)
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 }
}
const response = await axios.post(this.TOKEN_URL, params, {
@ -325,6 +337,42 @@ export class AuthService {
}
}
async getUserDetailsById(id: string) {
try {
const adminAccessToken = await this.getAdminAccessToken();
const userResponse = await axios.get(`${this.USERS_URL}/${id}`, {
headers: {
Authorization: `Bearer ${adminAccessToken}`
},
});
if (userResponse.status !== 200 || !Array.isArray(userResponse.data)) {
console.log("userResponse : ", userResponse);
console.log("userResponse status : ", userResponse.status);
throw new UnauthorizedException("Authentication failed");
}
console.log("user response : ", userResponse);
return userResponse.data;
} catch (error) {
console.log(error.message);
console.log("Error in getUserDetailsById ...........");
if (error instanceof UnauthorizedException) {
throw error;
}
else if (error instanceof BadRequestException) {
throw error;
}
throw new InternalServerErrorException();
}
}
async getUserDetailsByEmail(email: string): Promise<any> {
try {
const adminAccessToken = await this.getAdminAccessToken();
@ -472,10 +520,10 @@ export class AuthService {
}
const userPayload = {
username: body.P_EMAILADDR,
username: body.P_EMAILADDR.toLowerCase(),
// firstName:"A",
// lastName:"B",
email: body.P_EMAILADDR,
email: body.P_EMAILADDR.toLowerCase(),
emailVerified: true,
enabled: true,
attributes: {
@ -738,9 +786,9 @@ export class AuthService {
template: 'b',
context: {
to: body.P_TO,
url: `${source === 'ua' ? `https://policy.alphaomegainfosys.com/register/${token}`
: source === 'sa' ? `https://sp.alphaomegainfosys.com/register/${token}`
: source === 'ca' ? `https://client.alphaomegainfosys.com/register/${token}` : ''}`
url: `${source === 'ua' ? `https://policy.alphaomegainfosys.com/forgot-password/${token}`
: source === 'sa' ? `https://sp.alphaomegainfosys.com/forgot-password/${token}`
: source === 'ca' ? `https://client.alphaomegainfosys.com/forgot-password/${token}` : ''}`
}
}

View File

@ -33,7 +33,7 @@ export class AuthExceptionFilter implements ExceptionFilter {
// Send custom response
return response.status(status).json({
statusCode: status,
message: 'Authentication failed. Tokens cleared.',
message: 'Authentication failed',
});
}