mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
added region to login
This commit is contained in:
@ -17,10 +17,21 @@ export class AuthService {
|
|||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async validateUser(email: string, pass: string): Promise<any> {
|
async validateUser(
|
||||||
|
email: string,
|
||||||
|
pass: string,
|
||||||
|
regionUuid?: string,
|
||||||
|
): Promise<any> {
|
||||||
const user = await this.userRepository.findOne({
|
const user = await this.userRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
email,
|
email,
|
||||||
|
region: regionUuid
|
||||||
|
? {
|
||||||
|
uuid: regionUuid,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
regionName: 'United Arab Emirates',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
relations: ['roles.roleType'],
|
relations: ['roles.roleType'],
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
|
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||||
import { IsPasswordStrong } from 'src/validators/password.validator';
|
import { IsPasswordStrong } from 'src/validators/password.validator';
|
||||||
|
|
||||||
export class UserSignUpDto {
|
export class UserSignUpDto {
|
||||||
@ -38,4 +38,8 @@ export class UserSignUpDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public lastName: string;
|
public lastName: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
public regionUuid: string;
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,9 @@ export class UserLoginDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
|
@ApiProperty()
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
regionUuid?: string;
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,17 @@ export class UserAuthService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const { regionUuid, ...rest } = userSignUpDto;
|
||||||
const user = await this.userRepository.save({
|
const user = await this.userRepository.save({
|
||||||
...userSignUpDto,
|
...rest,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
|
region: regionUuid
|
||||||
|
? {
|
||||||
|
uuid: regionUuid,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
regionName: 'United Arab Emirates',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
@ -80,7 +88,11 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async userLogin(data: UserLoginDto) {
|
async userLogin(data: UserLoginDto) {
|
||||||
const user = await this.authService.validateUser(data.email, data.password);
|
const user = await this.authService.validateUser(
|
||||||
|
data.email,
|
||||||
|
data.password,
|
||||||
|
data.regionUuid,
|
||||||
|
);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new UnauthorizedException('Invalid login credentials.');
|
throw new UnauthorizedException('Invalid login credentials.');
|
||||||
|
Reference in New Issue
Block a user