Merge branch 'master' into luke
This commit is contained in:
@@ -84,6 +84,7 @@ export class UsersController {
|
|||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Patch()
|
@Patch()
|
||||||
async update(@Req() req, @Body(new ValidationPipe()) usersUpdateDto: UpdateUsersDto, @Res() response : Response) {
|
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);
|
||||||
if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
|
if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
|
||||||
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
|
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
|
||||||
@@ -103,6 +104,7 @@ export class UsersController {
|
|||||||
return this.usersService.remove(req.user.id);
|
return this.usersService.remove(req.user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// POST http://transcendance:8080/user/avatar
|
// POST http://transcendance:8080/user/avatar
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@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."});
|
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(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get('avatar')
|
@Get('avatar')
|
||||||
getAvatar(@Req() request, @Res() response) {
|
async getAvatar(@Query('username') username: string, @Req() request, @Res() response) {
|
||||||
const promise = this.usersService.getAvatarUrl(request.user.id).then((url) =>
|
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));
|
return of(response.sendFile(process.cwd() + '/uploads/avatars/' + url));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw new NotFoundException('Avatar not found');
|
throw new NotFoundException('Avatar not found');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,12 +50,10 @@ export class UsersService {
|
|||||||
return partialUser;
|
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> {
|
async isUsernameExists(usernameToSearch: string): Promise<boolean> {
|
||||||
|
console.log('searching for username: ' + usernameToSearch)
|
||||||
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
const user = await this.userRepository.findOneBy({username : usernameToSearch});
|
||||||
|
console.log({...user})
|
||||||
if (!user)
|
if (!user)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
@@ -68,13 +66,13 @@ export class UsersService {
|
|||||||
let partialUsers : Partial<User>[] = [];
|
let partialUsers : Partial<User>[] = [];
|
||||||
|
|
||||||
for (const otherUser of otherUsers) {
|
for (const otherUser of otherUsers) {
|
||||||
console.log('other user: ')
|
// console.log('other user: ')
|
||||||
console.log({...otherUser})
|
// console.log({...otherUser})
|
||||||
let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
|
// let tmp = await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id);
|
||||||
console.log('user.services findIF Blocked... : ')
|
// console.log('user.services findIF Blocked... : ')
|
||||||
console.log(tmp)
|
// console.log(tmp)
|
||||||
if (tmp === false) {
|
// if (tmp === false) {
|
||||||
// if (await this.friendshipService.findIfUserIsBlockedOrHasBlocked(currentUser.id, otherUser.id) === 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});
|
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;
|
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) {
|
async create(createUserDto: CreateUsersDto) {
|
||||||
|
// console.log('\nuser.services create a new user, createUserDto: ')
|
||||||
|
// console.log({...createUserDto})
|
||||||
if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
|
if (await this.userRepository.findOneBy({fortyTwoId: createUserDto.fortyTwoId}))
|
||||||
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
|
throw new HttpException(`The user already exists.`,HttpStatus.CONFLICT);
|
||||||
const user = this.userRepository.create(createUserDto);
|
const user = this.userRepository.create(createUserDto);
|
||||||
@@ -119,6 +95,11 @@ export class UsersService {
|
|||||||
|
|
||||||
async update(id: number, updateUserDto: UpdateUsersDto) {
|
async update(id: number, updateUserDto: UpdateUsersDto) {
|
||||||
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`);
|
// 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(
|
const user = await this.userRepository.preload(
|
||||||
{id: id,
|
{id: id,
|
||||||
...updateUserDto});
|
...updateUserDto});
|
||||||
@@ -158,13 +139,16 @@ export class UsersService {
|
|||||||
return this.userRepository.update(id, {image_url: avatar});
|
return this.userRepository.update(id, {image_url: avatar});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAvatarUrl(id: number) {
|
// doing search with username not id because userService.findOne doesn't return an Id anymore, just username... fuck this architecture is big trash...
|
||||||
const user = await this.userRepository.findOneBy({id: id});
|
// async getAvatarUrl(id: number) {
|
||||||
|
async getAvatarUrl(username: string) {
|
||||||
|
const user = await this.userRepository.findOneBy({username: username});
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
throw new HttpException(`The user could not be found.`,HttpStatus.NOT_FOUND);
|
||||||
|
// console.log('user.service getAvatarUrl of ' + user.username)
|
||||||
if (!user.image_url)
|
if (!user.image_url)
|
||||||
throw new HttpException(`The user has no avatar.`,HttpStatus.NOT_FOUND);
|
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;
|
return user.image_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
console.error('conditionsFailed event', event.detail);
|
console.error('conditionsFailed event', event.detail);
|
||||||
// i mean i guess i can just leave this in there permanently?
|
// i mean i guess i can just leave this in there permanently?
|
||||||
|
|
||||||
replace('/unauthorized-access');
|
// replace('/unauthorized-access');
|
||||||
|
replace('/');
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -78,9 +78,11 @@
|
|||||||
if (response.status === 200)
|
if (response.status === 200)
|
||||||
success.username = "Your changes have been saved"
|
success.username = "Your changes have been saved"
|
||||||
else if (response.status === 201)
|
else if (response.status === 201)
|
||||||
push("/2fa")
|
push("/2fa");
|
||||||
|
else if (response.status === 409)
|
||||||
|
errors.username = `${set.username} is already in use, pick a different one.`;
|
||||||
else
|
else
|
||||||
errors.username = "Something went wrong"
|
errors.username = "Something went wrong";
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch((err) => errors.username = err)
|
.catch((err) => errors.username = err)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
|
|
||||||
{#if user !== undefined}
|
{#if user !== undefined}
|
||||||
<GenerateUserDisplay user={user} primary={true}/>
|
<GenerateUserDisplay user={user} primary={false}/>
|
||||||
<!-- <GenerateUserDisplay user={user} primary={true}/> -->
|
<!-- <GenerateUserDisplay user={user} primary={true}/> -->
|
||||||
{:else}
|
{:else}
|
||||||
<h2>Sorry</h2>
|
<h2>Sorry</h2>
|
||||||
|
|||||||
@@ -4,23 +4,40 @@
|
|||||||
|
|
||||||
|
|
||||||
export let user;
|
export let user;
|
||||||
export let primary;
|
export let primary; // kinda useless, not sure what i was going for... Might be userful after all
|
||||||
let rank = '';
|
let rank = '';
|
||||||
let avatar;
|
let avatar;
|
||||||
|
// avatar needs to be updated!!!
|
||||||
|
console.log('Generate User Display, BEFORE on mount ' + avatar)
|
||||||
|
// add errors
|
||||||
|
let errors = {avatar: ''};
|
||||||
|
|
||||||
onMount( async() => {
|
onMount( async() => {
|
||||||
// using this for now cuz for some reason there is yet to be a way to fet another person's avatar
|
// console.log('Generate User Display, on mount ' + user.username)
|
||||||
if (primary) {
|
if (primary) {
|
||||||
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar`, {method: "GET"})
|
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar`, {method: "GET"})
|
||||||
.then(response => {return response.blob()})
|
.then(response => {return response.blob()})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const url = URL.createObjectURL(data);
|
const url = URL.createObjectURL(data);
|
||||||
avatar = url;
|
avatar = url;
|
||||||
});
|
})
|
||||||
|
.catch(() => errors.avatar = 'Sorry your avatar could not be loaded' );
|
||||||
|
// console.log('avatar: ')
|
||||||
|
// console.log(avatar)
|
||||||
|
} else {
|
||||||
|
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar?username=${user.username}`, {method: "GET"})
|
||||||
|
.then(response => {return response.blob()})
|
||||||
|
.then(data => {
|
||||||
|
const url = URL.createObjectURL(data);
|
||||||
|
avatar = url;
|
||||||
|
})
|
||||||
|
.catch(() => errors.avatar = 'Sorry your avatar could not be loaded' );
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
/**** THIS IS BASICALLY ALL THE RANK LOGIC ERIC HAS MADE ****/
|
||||||
|
|
||||||
if (user.loseGame > user.winGame) {
|
if (user.loseGame > user.winGame) {
|
||||||
rank = 'Bitch Ass Loser!'
|
rank = 'Bitch Ass Loser!'
|
||||||
} else if (user.loseGame === user.winGame) {
|
} else if (user.loseGame === user.winGame) {
|
||||||
@@ -67,6 +84,7 @@
|
|||||||
<!-- <img class="icon" src="img/default_user_icon.png" alt="default user icon"> -->
|
<!-- <img class="icon" src="img/default_user_icon.png" alt="default user icon"> -->
|
||||||
<!-- <img class="icon" src="{user.image_url}" alt="default user icon"> -->
|
<!-- <img class="icon" src="{user.image_url}" alt="default user icon"> -->
|
||||||
<img class="avatar" src="{avatar}" alt="default user icon">
|
<img class="avatar" src="{avatar}" alt="default user icon">
|
||||||
|
<div class="error">{errors.avatar}</div>
|
||||||
<div class="username">{user.username}</div>
|
<div class="username">{user.username}</div>
|
||||||
<div class="rank">Rank:
|
<div class="rank">Rank:
|
||||||
<span class="glitter">
|
<span class="glitter">
|
||||||
@@ -150,6 +168,11 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error{
|
||||||
|
font-size: 0.8em;
|
||||||
|
font-weight: bold;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
/* Glittery Star Stuff */
|
/* Glittery Star Stuff */
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,57 @@ import GameSpectator from '../pages/game/GameSpectator.svelte';
|
|||||||
export const primaryRoutes = {
|
export const primaryRoutes = {
|
||||||
'/': SplashPage,
|
'/': SplashPage,
|
||||||
'/2fa': TwoFactorAuthentication,
|
'/2fa': TwoFactorAuthentication,
|
||||||
'/game': Game,
|
'/game': wrap({
|
||||||
'/spectator': GameSpectator,
|
component: Game,
|
||||||
'/ranking' : Ranking,
|
conditions: [
|
||||||
|
async(detail) => {
|
||||||
|
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||||
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
|
console.log('in /profile what is in user')
|
||||||
|
console.log(user)
|
||||||
|
|
||||||
|
if (user && user.username)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
'/spectator': wrap({
|
||||||
|
component: GameSpectator,
|
||||||
|
conditions: [
|
||||||
|
async(detail) => {
|
||||||
|
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||||
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
|
console.log('in /profile what is in user')
|
||||||
|
console.log(user)
|
||||||
|
|
||||||
|
if (user && user.username)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
'/ranking': wrap({
|
||||||
|
component: Ranking,
|
||||||
|
conditions: [
|
||||||
|
async(detail) => {
|
||||||
|
const user = await fetch('http://' + process.env.WEBSITE_HOST + ":" + process.env.WEBSITE_PORT + '/api/v2/user')
|
||||||
|
.then((resp) => resp.json())
|
||||||
|
|
||||||
|
console.log('in /profile what is in user')
|
||||||
|
console.log(user)
|
||||||
|
|
||||||
|
if (user && user.username)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}),
|
||||||
'/profile': wrap({
|
'/profile': wrap({
|
||||||
component: ProfilePage,
|
component: ProfilePage,
|
||||||
conditions: [
|
conditions: [
|
||||||
@@ -50,7 +98,6 @@ export const primaryRoutes = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}),
|
}),
|
||||||
|
|
||||||
'/unauthorized-access': UnauthorizedAccessPage,
|
'/unauthorized-access': UnauthorizedAccessPage,
|
||||||
'*': NotFound
|
'*': NotFound
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user