Merge branch 'master' into hugo
This commit is contained in:
@@ -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],
|
||||
})
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
import { IsBoolean, Matches, IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
import { isSet } from 'util/types';
|
||||
|
||||
export class CreateUsersDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^[a-zA-Z0-9'-_]+$/)
|
||||
readonly username: string;
|
||||
readonly fortyTwoId: string;
|
||||
@IsEmail()
|
||||
|
||||
@@ -15,7 +15,7 @@ export class User {
|
||||
@Column({unique: true})
|
||||
fortyTwoId: string;
|
||||
|
||||
@Column()
|
||||
@Column({unique: true})
|
||||
username: string;
|
||||
|
||||
@Column()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user