auth and mail template fixed
This commit is contained in:
parent
cfb09b1f16
commit
b553ff0623
@ -4,7 +4,7 @@
|
|||||||
{{!-- <p style="font-size: 16px;">A Registration has been successfully initiated for the email: <strong>{{to}}</strong></p> --}}
|
{{!-- <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>
|
<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;">
|
<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>
|
</a>
|
||||||
<div style="margin-top: 40px;">
|
<div style="margin-top: 40px;">
|
||||||
<p style="color: #888;">Powered by</p>
|
<p style="color: #888;">Powered by</p>
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { AuthLoginDTO, SendMailDTO } from './auth.dto';
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { LogoutInterceptor } from 'src/interceptors/logout.interceptor';
|
import { LogoutInterceptor } from 'src/interceptors/logout.interceptor';
|
||||||
import { RegisterGuard } from 'src/guards/register.guard';
|
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 { RolesGuard } from 'src/guards/roles.guard';
|
||||||
import { Roles } from 'src/decorators/roles.decorator';
|
import { Roles } from 'src/decorators/roles.decorator';
|
||||||
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
|
||||||
@ -15,18 +14,17 @@ import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
|
|||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly authService: AuthService,
|
private readonly authService: AuthService,
|
||||||
private readonly userMaintenanceService: UserMaintenanceService
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
@Post('login')
|
@Post('login')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
async loginClient(@Body() body: AuthLoginDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) {
|
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) {
|
if (k.access_token) {
|
||||||
res.cookie('access_token', k.access_token, {
|
res.cookie('access_token', k.access_token, {
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: 'none',
|
sameSite: 'none',
|
||||||
maxAge: 8 * 60 * 60 * 1000,
|
maxAge: 8 * 60 * 60 * 1000,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -267,11 +267,23 @@ export class AuthService {
|
|||||||
try {
|
try {
|
||||||
const userSession = await this.getUserSession(username)
|
const userSession = await this.getUserSession(username)
|
||||||
|
|
||||||
|
|
||||||
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 user: any = await this.getUserDetailsById(getSub?.payload.sub)
|
||||||
|
|
||||||
|
if (user.email !== username) {
|
||||||
|
throw new UnauthorizedException("Authentication failed")
|
||||||
|
}
|
||||||
|
|
||||||
let tokens = await this.getTokenFromRefreshToken(req);
|
let tokens = await this.getTokenFromRefreshToken(req);
|
||||||
const decoded = jwt.decode(access_token, { complete: true });
|
const decoded = jwt.decode(access_token, { complete: true });
|
||||||
const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined;
|
const email: any = (decoded && typeof decoded === 'object') ? (decoded as any).payload?.email : undefined;
|
||||||
return { ...tokens, email }
|
return { ...tokens, email }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await axios.post(this.TOKEN_URL, params, {
|
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> {
|
async getUserDetailsByEmail(email: string): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const adminAccessToken = await this.getAdminAccessToken();
|
const adminAccessToken = await this.getAdminAccessToken();
|
||||||
@ -472,10 +520,10 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const userPayload = {
|
const userPayload = {
|
||||||
username: body.P_EMAILADDR,
|
username: body.P_EMAILADDR.toLowerCase(),
|
||||||
// firstName:"A",
|
// firstName:"A",
|
||||||
// lastName:"B",
|
// lastName:"B",
|
||||||
email: body.P_EMAILADDR,
|
email: body.P_EMAILADDR.toLowerCase(),
|
||||||
emailVerified: true,
|
emailVerified: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
attributes: {
|
attributes: {
|
||||||
@ -738,9 +786,9 @@ export class AuthService {
|
|||||||
template: 'b',
|
template: 'b',
|
||||||
context: {
|
context: {
|
||||||
to: body.P_TO,
|
to: body.P_TO,
|
||||||
url: `${source === 'ua' ? `https://policy.alphaomegainfosys.com/register/${token}`
|
url: `${source === 'ua' ? `https://policy.alphaomegainfosys.com/forgot-password/${token}`
|
||||||
: source === 'sa' ? `https://sp.alphaomegainfosys.com/register/${token}`
|
: source === 'sa' ? `https://sp.alphaomegainfosys.com/forgot-password/${token}`
|
||||||
: source === 'ca' ? `https://client.alphaomegainfosys.com/register/${token}` : ''}`
|
: source === 'ca' ? `https://client.alphaomegainfosys.com/forgot-password/${token}` : ''}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ export class AuthExceptionFilter implements ExceptionFilter {
|
|||||||
// Send custom response
|
// Send custom response
|
||||||
return response.status(status).json({
|
return response.status(status).json({
|
||||||
statusCode: status,
|
statusCode: status,
|
||||||
message: 'Authentication failed. Tokens cleared.',
|
message: 'Authentication failed',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user