COrrection de nombreux bug, changement de font, réel username unique insensible à la casse...

This commit is contained in:
cherif
2023-01-17 00:30:39 +01:00
parent 8b365968ac
commit 796a8464b1
16 changed files with 95 additions and 83 deletions

View File

@@ -12,18 +12,9 @@ import { SessionSerializer } from './utils/serializer';
@Module({
imports: [TypeOrmModule.forFeature([User, Friendship]), UsersModule,
// JwtModule.registerAsync({
// useFactory: async (configService: ConfigService) => {
// return {
// signOptions: { expiresIn: '1h' },
// secret: process.env.JWT_SECRET,
// };
// }
// })
],
providers: [AuthenticationService, FortyTwoStrategy, UsersService, SessionSerializer, FriendshipService
// JwtStrategy
],
],
exports: [AuthenticationService],
controllers: [AuthenticationController],
})

View File

@@ -15,7 +15,7 @@ export class User {
@Column({unique: true})
fortyTwoId: string;
@Column()
@Column({unique: true})
username: string;
@Column()

View File

@@ -58,7 +58,7 @@ export class UsersController {
@Patch()
async update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto, @Res() response : Response) {
console.log('user.controller updating user info')
const user = await this.usersService.update(req.user.id, usersUpdateDto);
const user = await this.usersService.update(req.user.id, usersUpdateDto, req.user.username);
if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false)

View File

@@ -55,12 +55,9 @@ export class UsersService {
}
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
// console.log('searching for username: ' + usernameToSearch)
const user = await this.userRepository.findOneBy({username : usernameToSearch});
// console.log({...user})
const user = await this.userRepository.createQueryBuilder('user')
.where('LOWER(user.username) = LOWER(:username)', {username : usernameToSearch})
.getOne()
if (!user)
return false;
return true;
@@ -101,10 +98,9 @@ export class UsersService {
return this.userRepository.save(user);
}
async update(id: number, updateUserDto: UpdateUsersDto) {
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
// console.log({...updateUserDto})
if (await this.isUsernameExists(updateUserDto.username) === true) {
async update(id: number, updateUserDto: UpdateUsersDto, username : string) {
console.log("Maj user username : " + username + " updateuser dto " + updateUserDto.username )
if (await this.isUsernameExists(updateUserDto.username) === true && updateUserDto.username !== username) {
// console.log('updating username ' + updateUserDto.username + ' but it already is in use')
throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT);
}