So i added a check to make it so you can't change your username to someone else's, also turns out Cherif already has a check so that if you change your username to someone else's 42 username who isn't a user yet and then they try to become a user, their username will have a random string attached to the end so it is also unique, then fixed a few minor things, and made it so all UnauthorizedPages take you back to / as in the SplashPage rather than a special page from which you navigate to /, that said, i think feedback for the user is kinda nice, will decide with team eventually
This commit is contained in:
@@ -120,7 +120,7 @@ export class UsersController {
|
||||
return res.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).json({message : "Unsupported media type. Please use a valid image file."});
|
||||
}
|
||||
|
||||
|
||||
// don't pass your own username
|
||||
// GET http://transcendance:8080/user/avatar?username=username
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
|
||||
@@ -50,12 +50,10 @@ export class UsersService {
|
||||
return partialUser;
|
||||
}
|
||||
|
||||
|
||||
/***** THIS IS THE THING I REALLY NEED TO FIX!!!!!!! *****/
|
||||
|
||||
// Ok this gets called in the Authenitcation Service, but like i was still able to make a username === someone else's
|
||||
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||
console.log('searching for username: ' + usernameToSearch)
|
||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||
console.log({...user})
|
||||
if (!user)
|
||||
return false;
|
||||
return true;
|
||||
@@ -84,6 +82,8 @@ export class UsersService {
|
||||
}
|
||||
|
||||
async create(createUserDto: CreateUsersDto) {
|
||||
// console.log('\nuser.services create a new user, createUserDto: ')
|
||||
// console.log({...createUserDto})
|
||||
if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
|
||||
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
|
||||
const user = this.userRepository.create(createUserDto);
|
||||
@@ -95,6 +95,11 @@ export class UsersService {
|
||||
|
||||
async update(id: number, updateUserDto: UpdateUsersDto) {
|
||||
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
||||
// console.log({...updateUserDto})
|
||||
if (await this.isUsernameExists(updateUserDto.username) === true) {
|
||||
console.log('updating username ' + updateUserDto.username + ' but it already is in use')
|
||||
throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT);
|
||||
}
|
||||
const user = await this.userRepository.preload(
|
||||
{id: id,
|
||||
...updateUserDto});
|
||||
|
||||
Reference in New Issue
Block a user