Merge branch luke into 'master'
This commit is contained in:
@@ -84,6 +84,7 @@ export class UsersController {
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@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);
|
||||
if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
|
||||
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
|
||||
@@ -103,6 +104,7 @@ export class UsersController {
|
||||
return this.usersService.remove(req.user.id);
|
||||
}
|
||||
|
||||
|
||||
// POST http://transcendance:8080/user/avatar
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@@ -118,15 +120,24 @@ export class UsersController {
|
||||
return res.status(HttpStatus.UNSUPPORTED_MEDIA_TYPE).json({message : "Unsupported media type. Please use a valid image file."});
|
||||
}
|
||||
|
||||
// GET http://transcendance:8080/user/avatar
|
||||
// don't pass your own username
|
||||
// GET http://transcendance:8080/user/avatar?username=username
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('avatar')
|
||||
getAvatar(@Req() request, @Res() response) {
|
||||
const promise = this.usersService.getAvatarUrl(request.user.id).then((url) =>
|
||||
async getAvatar(@Query('username') username: string, @Req() request, @Res() response) {
|
||||
let usernameToFind;
|
||||
if (username !== undefined) {
|
||||
usernameToFind = username;
|
||||
} else {
|
||||
usernameToFind = request.user.username;
|
||||
}
|
||||
const promise = this.usersService.getAvatarUrl(usernameToFind).then((url) =>
|
||||
{
|
||||
if (url)
|
||||
if (url) {
|
||||
console.log('what is the URL: ' + url)
|
||||
return of(response.sendFile(process.cwd() + '/uploads/avatars/' + url));
|
||||
}
|
||||
else
|
||||
throw new NotFoundException('Avatar not found');
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
@@ -68,13 +66,13 @@ export class UsersService {
|
||||
let partialUsers : Partial<User>[] = [];
|
||||
|
||||
for (const otherUser of otherUsers) {
|
||||
console.log('other user: ')
|
||||
console.log({...otherUser})
|
||||
let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
|
||||
console.log('user.services findIF Blocked... : ')
|
||||
console.log(tmp)
|
||||
if (tmp === false) {
|
||||
// if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) {
|
||||
// console.log('other user: ')
|
||||
// console.log({...otherUser})
|
||||
// let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
|
||||
// console.log('user.services findIF Blocked... : ')
|
||||
// console.log(tmp)
|
||||
// if (tmp === false) {
|
||||
if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) {
|
||||
partialUsers.push({username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats});
|
||||
}
|
||||
}
|
||||
@@ -83,31 +81,9 @@ export class UsersService {
|
||||
return partialUsers;
|
||||
}
|
||||
|
||||
// async findAbsolutelyAll() {
|
||||
// // const otherUsers = await this.userRepository.find({where: {id: Not(+currentUser.id)}, order: {username: "ASC"}, skip: offset, take: limit,});
|
||||
// const otherUsers = await this.userRepository.find({order: {username: "ASC"}});
|
||||
|
||||
// let partialUsers : Partial<User>[] = [];
|
||||
|
||||
// for (const otherUser of otherUsers) {
|
||||
// console.log('other user: ')
|
||||
// console.log({...otherUser})
|
||||
// let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
|
||||
// console.log('user.services findIF Blocked... : ')
|
||||
// console.log(tmp)
|
||||
// if (tmp === false) {
|
||||
// // if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === false) {
|
||||
// partialUsers.push({username: otherUser.username, image_url: otherUser.image_url, status: otherUser.status, stats: otherUser.stats});
|
||||
// }
|
||||
// }
|
||||
// console.log('user.services findAll, partialUsers:')
|
||||
// console.log({...partialUsers})
|
||||
// return partialUsers;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
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);
|
||||
@@ -119,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});
|
||||
@@ -158,13 +139,16 @@ export class UsersService {
|
||||
return this.userRepository.update(id, {image_url: avatar});
|
||||
}
|
||||
|
||||
async getAvatarUrl(id: number) {
|
||||
const user = await this.userRepository.findOneBy({id: id});
|
||||
// doing search with username not id because userService.findOne doesn't return an Id anymore, just username... fuck this architecture is big trash...
|
||||
// async getAvatarUrl(id: number) {
|
||||
async getAvatarUrl(username: string) {
|
||||
const user = await this.userRepository.findOneBy({username: username});
|
||||
if (!user)
|
||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
||||
// console.log('user.service getAvatarUrl of ' + user.username)
|
||||
if (!user.image_url)
|
||||
throw new HttpException(`The user has no avatar.`,HttpStatus.NOT_FOUND);
|
||||
console.log(user.image_url);
|
||||
// console.log('User.service Avatar URL ' + user.image_url);
|
||||
return user.image_url;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user