cleaned up everything, basically all comments and console.logs are gone

This commit is contained in:
Me
2023-01-17 21:29:41 +01:00
parent 11f54bde83
commit 3b72079663
16 changed files with 10 additions and 194 deletions

View File

@@ -8,17 +8,13 @@ import { FriendshipService } from './friendship.service';
export class FriendshipController { export class FriendshipController {
constructor(private readonly friendshipService: FriendshipService) { } constructor(private readonly friendshipService: FriendshipService) { }
// new and improved finder of people
// GET http://transcendance:8080/api/v2/network/myfriends // GET http://transcendance:8080/api/v2/network/myfriends
@Get('myfriends') @Get('myfriends')
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
findOne(@Query('username') otherUsername: string, @Req() req) { findOne(@Query('username') otherUsername: string, @Req() req) {
// console.log('GET myfriends')
const user = req.user; const user = req.user;
if (otherUsername !== undefined) { if (otherUsername !== undefined) {
// console.log('my friend: ' + otherUsername)
return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username); return this.friendshipService.findOneRelationshipByUsername(otherUsername, user.username);
} }
return this.friendshipService.findAllFriendships(user.id); return this.friendshipService.findAllFriendships(user.id);
@@ -30,10 +26,8 @@ export class FriendshipController {
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) { create(@Body() createFriendshipDto: CreateFriendshipDto, @Req() req) {
// console.log('friendship.service create')
const user = req.user; const user = req.user;
if (user.username !== createFriendshipDto.receiverUsername) { if (user.username !== createFriendshipDto.receiverUsername) {
// console.log('friendship.service create have a receiver name')
return this.friendshipService.create(createFriendshipDto, user); return this.friendshipService.create(createFriendshipDto, user);
} }
return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST); return new HttpException('You can\'t request a frienship to yourself', HttpStatus.BAD_REQUEST);
@@ -72,7 +66,6 @@ export class FriendshipController {
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
remove(@Param('relationshipId') relationshipId: number, @Req() req) { remove(@Param('relationshipId') relationshipId: number, @Req() req) {
const user : User = req.user; const user : User = req.user;
// console.log('deleting a friendship')
return this.friendshipService.removeFriendship(relationshipId, user); return this.friendshipService.removeFriendship(relationshipId, user);
} }
@@ -99,8 +92,6 @@ export class FriendshipController {
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
findBlocked(@Query('relationshipId') relationshipId: number, @Req() req) { findBlocked(@Query('relationshipId') relationshipId: number, @Req() req) {
// console.log('friendship.controller fetching blocked users')
// console.log(relationshipId)
const user = req.user; const user = req.user;
if (Number.isNaN(relationshipId)) if (Number.isNaN(relationshipId))
return this.friendshipService.findAllBlockedFriends(user.id); return this.friendshipService.findAllBlockedFriends(user.id);

View File

@@ -16,7 +16,6 @@ export class FriendshipService {
private readonly userRepository: Repository<User>, private readonly userRepository: Repository<User>,
) { } ) { }
//kinda useless but someone else might use it
async findOneRelationshipById(friendId : number, userId : number) { async findOneRelationshipById(friendId : number, userId : number) {
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
@@ -39,12 +38,8 @@ export class FriendshipService {
) )
}), }),
) )
// .andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
.getOne() .getOne()
// console.log('END Find one friend by ID: ')
// console.log({...friendship})
if (!friendship) { if (!friendship) {
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND); throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
} }
@@ -52,7 +47,6 @@ export class FriendshipService {
} }
async findOneRelationshipByUsername(friendUsername : string, username : string) { async findOneRelationshipByUsername(friendUsername : string, username : string) {
// This seems to work, finding friendships by username but checking the actual users not the friendship
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
@@ -76,9 +70,6 @@ export class FriendshipService {
) )
.getOne() .getOne()
// console.log('END Find one friend by username: ')
// console.log({...friendship})
if (!friendship) { if (!friendship) {
throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND); throw new HttpException(`There is no such friendship`, HttpStatus.NOT_FOUND);
} }
@@ -100,8 +91,6 @@ export class FriendshipService {
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
} }
// console.log('friendship.service my friends:')
// console.log({...sendFrienships})
return sendFrienships; return sendFrienships;
} }
@@ -142,16 +131,6 @@ export class FriendshipService {
.where('sender.id = :requestee', { requestee: userId }) .where('sender.id = :requestee', { requestee: userId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.BLOCKED })
.getMany(); .getMany();
// let partialFriendship : Partial<Friendship>[] = [];
// for (const friendship of friendships) {
// partialFriendship.push({id: friendship.id, date: friendship.date, senderUsername: friendship.senderUsername, receiverUsername: friendship.receiverUsername, status: friendship.status});
// }
// console.log('friendship.service findAllBlockedFriends, friendships:')
// console.log({...friendships})
// console.log('friendship.service findAllBlockedFriends, partial friendship:')
// return partialFriendship;
let sendFrienships: SendableFriendship[] = [] let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
@@ -167,10 +146,6 @@ export class FriendshipService {
.where('sender.id = :requestee', { requestee: userId }) .where('sender.id = :requestee', { requestee: userId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
.getMany(); .getMany();
// console.log('friendships services pendant friendships:')
// console.log({...friendships})
let sendFrienships: SendableFriendship[] = [] let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
@@ -186,10 +161,6 @@ export class FriendshipService {
.where('receiver.id = :addressee', { addressee: userId }) .where('receiver.id = :addressee', { addressee: userId })
.andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED }) .andWhere('friendship.status = :status', { status: FriendshipStatus.REQUESTED })
.getMany(); .getMany();
// console.log('friendship service received requests')
// console.log({...friendships})
let sendFrienships: SendableFriendship[] = [] let sendFrienships: SendableFriendship[] = []
for (const friendship of friendships) { for (const friendship of friendships) {
sendFrienships.push(new SendableFriendship(friendship)); sendFrienships.push(new SendableFriendship(friendship));
@@ -198,16 +169,12 @@ export class FriendshipService {
} }
async create(createFriendshipDto: CreateFriendshipDto, creator : User) { async create(createFriendshipDto: CreateFriendshipDto, creator : User) {
// console.log("DTO : \n")
// console.log({...createFriendshipDto})
const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername}); const receiver = await this.userRepository.findOneBy({username: createFriendshipDto.receiverUsername});
if (!receiver) if (!receiver)
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND); throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED) if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND); throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
@@ -218,21 +185,13 @@ export class FriendshipService {
.andWhere('receiver.id = :receiverId2', {receiverId2: creator.id}) .andWhere('receiver.id = :receiverId2', {receiverId2: creator.id})
.getOne(); .getOne();
// console.log('friendship.service create, friendship: \n\n\n')
// console.log({...friendship})
if (friendship) { if (friendship) {
// console.log('there is already a friend request')
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED) if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK); throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED) { else if (friendship.status && friendship.status === FriendshipStatus.REQUESTED) {
if (friendship && friendship.sender && friendship.sender.id === creator.id) { if (friendship && friendship.sender && friendship.sender.id === creator.id) {
throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`, HttpStatus.OK); throw new HttpException(`The friendship request has already been sent the ${friendship.date}.`, HttpStatus.OK);
} else { } else {
// console.log('the friend request is being updated to Accepted')
friendship.status = FriendshipStatus.ACCEPTED; friendship.status = FriendshipStatus.ACCEPTED;
const saveAFriendship = await this.friendshipRepository.save(friendship); const saveAFriendship = await this.friendshipRepository.save(friendship);
return new SendableFriendship(saveAFriendship); return new SendableFriendship(saveAFriendship);
@@ -242,7 +201,6 @@ export class FriendshipService {
else if (friendship.status && friendship.status === FriendshipStatus.DECLINED) else if (friendship.status && friendship.status === FriendshipStatus.DECLINED)
throw new HttpException(`The request has been declined.`, HttpStatus.OK); throw new HttpException(`The request has been declined.`, HttpStatus.OK);
} }
// console.log('friendship.service create, we are still saving a new friendship')
const newFriendship = new Friendship(); const newFriendship = new Friendship();
newFriendship.sender = creator; newFriendship.sender = creator;
@@ -259,10 +217,6 @@ export class FriendshipService {
.leftJoinAndSelect('friendship.receiver', 'receiver') .leftJoinAndSelect('friendship.receiver', 'receiver')
.where('friendship.id = :friendshipId', { friendshipId: relationshipId }) .where('friendship.id = :friendshipId', { friendshipId: relationshipId })
.getOne(); .getOne();
// console.log('.service accept friendship')
// console.log({...relation})
if (!relation) if (!relation)
throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND); throw new HttpException(`The requested relationship not found.`, HttpStatus.NOT_FOUND);
if (relation.sender.id === user.id) { if (relation.sender.id === user.id) {
@@ -304,8 +258,6 @@ export class FriendshipService {
// in the case where you RECEIVED the friendship but now want to block that person // in the case where you RECEIVED the friendship but now want to block that person
if (relation.receiver && relation.receiver.id === user.id) { if (relation.receiver && relation.receiver.id === user.id) {
// console.log('friendship.service blockFriendship trying to delete and recreate a friendship with block')
// console.log({...relation})
const newFriendshipDto = {"receiverUsername": relation.sender.username, "status": FriendshipStatus.BLOCKED}; const newFriendshipDto = {"receiverUsername": relation.sender.username, "status": FriendshipStatus.BLOCKED};
await this.removeFriendship(relationshipId, user); await this.removeFriendship(relationshipId, user);
return await this.create(newFriendshipDto, user); return await this.create(newFriendshipDto, user);
@@ -328,17 +280,10 @@ export class FriendshipService {
if (friendship.sender.id !== user.id && friendship.receiver.id !== user.id) { if (friendship.sender.id !== user.id && friendship.receiver.id !== user.id) {
throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN); throw new HttpException(`You can't do that.`, HttpStatus.FORBIDDEN);
} }
// console.log('.service deleted a friendship')
return this.friendshipRepository.remove(friendship); return this.friendshipRepository.remove(friendship);
} }
async findIfUserIsBlockedOrHasBlocked(userConnectedId: number, userToFindId: number) { async findIfUserIsBlockedOrHasBlocked(userConnectedId: number, userToFindId: number) {
// console.log("finding if user is blocked")
// console.log('user connected: ' + userConnectedId)
// console.log('user to find: ' + userToFindId)
const friendship = await this.friendshipRepository const friendship = await this.friendshipRepository
.createQueryBuilder('friendship') .createQueryBuilder('friendship')
.leftJoinAndSelect('friendship.sender', 'sender') .leftJoinAndSelect('friendship.sender', 'sender')
@@ -362,17 +307,11 @@ export class FriendshipService {
.andWhere('friendship.status = :status', {status : FriendshipStatus.BLOCKED}) .andWhere('friendship.status = :status', {status : FriendshipStatus.BLOCKED})
.getOne() .getOne()
// console.log('printing friendship queried')
// console.log({...friendship})
if (friendship) { if (friendship) {
console.log('we are blocked in friendship.service') console.log('we are blocked in friendship.service')
return true; return true;
} }
// console.log('we are not blocked in friendship service')
return false; return false;
} }
} }

View File

@@ -1,11 +1,6 @@
import { Friendship, FriendshipStatus } from "./entities/friendship.entity"; import { Friendship, FriendshipStatus } from "./entities/friendship.entity";
// Ok i don't really know what i'm doing but i want a thing that is typeset that i can use to send info back to the Front when they create a friendship or ask for a friendship
// Ok it doesn't seem like i really need an interface, that just enfoces the types
// export interface SendableFriendship {
export class SendableFriendship { export class SendableFriendship {
id: number; id: number;
date: Date; date: Date;
@@ -13,7 +8,6 @@ export class SendableFriendship {
receiverUsername: string; receiverUsername: string;
status: FriendshipStatus; status: FriendshipStatus;
// if my constructor is here won't it get sent all over the place too?
constructor(friendship: Friendship) { constructor(friendship: Friendship) {
this.id = friendship.id; this.id = friendship.id;
this.date = friendship.date this.date = friendship.date

View File

@@ -8,7 +8,6 @@ export class SendableUser {
status: string; status: string;
stats: UserStats; stats: UserStats;
// if my constructor is here won't it get sent all over the place too?
constructor(user: User) { constructor(user: User) {
this.username = user.username; this.username = user.username;
this.image_url = user.image_url; this.image_url = user.image_url;

View File

@@ -4,11 +4,9 @@ import { User } from './entities/user.entity';
import { Repository, Not } from 'typeorm'; import { Repository, Not } from 'typeorm';
import { CreateUsersDto } from './dto/create-users.dto'; import { CreateUsersDto } from './dto/create-users.dto';
import { UpdateUsersDto } from './dto/update-users.dto'; import { UpdateUsersDto } from './dto/update-users.dto';
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
import { UserStats } from './entities/userStat.entities'; import { UserStats } from './entities/userStat.entities';
import { FriendshipService } from 'src/friendship/friendship.service'; import { FriendshipService } from 'src/friendship/friendship.service';
// On va devoir sûrement trouver un moyen plus simple pour passer l'id, sûrement via des pipes
// ou des interceptors, mais pour l'instant on va faire comme ça.
@Injectable() @Injectable()
export class UsersService { export class UsersService {
@@ -22,16 +20,12 @@ export class UsersService {
const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id}); const user = await this.userRepository.findOneBy({fortyTwoId: fortytwo_id});
if (!user) if (!user)
{ {
// console.log(`The requested user not found.`);
return null; return null;
} }
// console.log(`The requested user found.`);
return user; return user;
} }
async findOne(username: string) { async findOne(username: string) {
// console.log(`FIND ONE USER SERVICE Find user ${username}`);
const user = await this.userRepository.createQueryBuilder('user') const user = await this.userRepository.createQueryBuilder('user')
.leftJoinAndSelect('user.stats', 'stats') .leftJoinAndSelect('user.stats', 'stats')
.where('user.username = :username', { username: username }) .where('user.username = :username', { username: username })
@@ -39,8 +33,6 @@ export class UsersService {
if (!user) if (!user)
throw new NotFoundException(`The requested user not found.`); throw new NotFoundException(`The requested user not found.`);
// console.log(`FIND ONE USER SERVICE The requested user found. ` + user.username + " " + user.stats.id + user.stats.winGame + user.stats.loseGame + user.stats.drawGame + user.stats.totalGame);
const partialUser : Partial<User> = { const partialUser : Partial<User> = {
username: user.username, username: user.username,
image_url: user.image_url, image_url: user.image_url,
@@ -48,9 +40,6 @@ export class UsersService {
status: user.status, status: user.status,
stats: user.stats, stats: user.stats,
}; };
// console.log(`Returned Partial User.` + partialUser.username + user.username);
return partialUser; return partialUser;
} }
@@ -69,26 +58,14 @@ 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({...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) { 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});
} }
} }
// console.log('user.services findAll, partialUsers:')
// console.log({...partialUsers})
return 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);
@@ -101,7 +78,6 @@ export class UsersService {
async update(id: number, updateUserDto: UpdateUsersDto, username : string) { async update(id: number, updateUserDto: UpdateUsersDto, username : string) {
console.log("Maj user username : " + username + " updateuser dto " + updateUserDto.username ) console.log("Maj user username : " + username + " updateuser dto " + updateUserDto.username )
if (await this.isUsernameExists(updateUserDto.username) === true && updateUserDto.username !== 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); throw new HttpException(`The username is already in use.`,HttpStatus.CONFLICT);
} }
const user = await this.userRepository.preload( const user = await this.userRepository.preload(
@@ -143,15 +119,12 @@ export class UsersService {
return this.userRepository.update(id, {image_url: avatar}); return this.userRepository.update(id, {image_url: avatar});
} }
// 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(username: string) { async getAvatarUrl(username: string) {
const user = await this.userRepository.findOneBy({username: username}); 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.service Avatar URL ' + user.image_url);
return user.image_url; return user.image_url;
} }

View File

@@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import { push } from "svelte-spa-router"; import { push } from "svelte-spa-router";
let qrCodeImg; let qrCodeImg;
@@ -57,21 +56,18 @@
</script> </script>
<!-- ask Hugo but for Reactive page might want to put main in a div or something? -->
<main> <main>
<h1>2FA Sign In</h1> <h1>2FA Sign In</h1>
<p>use google authenticator</p> <p>use google authenticator</p>
{#await fetchQrCodeImg} {#await fetchQrCodeImg}
<p>Please Wait...</p> <p>Please Wait...</p>
{:then data} {:then data}
<!-- What the hell is data? ask Cherif -->
<img src={qrCodeImg} alt="A QRCodeImg you must scan with google authenticator" id="qrcodeImg" /> <img src={qrCodeImg} alt="A QRCodeImg you must scan with google authenticator" id="qrcodeImg" />
<form on:submit|preventDefault={submitCode}> <form on:submit|preventDefault={submitCode}>
<input id="code" bind:value={qrCode} type="text" placeholder="Input Code"/> <input id="code" bind:value={qrCode} type="text" placeholder="Input Code"/>
<button type="submit">Send</button> <button type="submit">Send</button>
</form> </form>
{#if wrongCode} {#if wrongCode}
<!-- shoudl i do this in the Net Ninja way? like it's "" until an error happens? -->
<div class="error"> <div class="error">
{wrongCode} {wrongCode}
</div> </div>
@@ -83,18 +79,13 @@
<style> <style>
main { main {
/* display: flex; */
/* align-items: center; */
text-align: center; text-align: center;
padding-top: 40px; padding-top: 40px;
padding-bottom: 40px; padding-bottom: 40px;
/* max-width: 500px; */
} }
form { form {
/* max-width: 330px; */
padding-top: 15px; padding-top: 15px;
} }
form input { form input {

View File

@@ -18,15 +18,12 @@
</script> </script>
<div class="background-pages"> <div class="background-pages">
{#if oneUser} {#if oneUser}
<GenerateUserDisplay user={oneUser}/> <GenerateUserDisplay user={oneUser}/>
{:else} {:else}
<h2>Sorry</h2> <h2>Sorry</h2>
<div>Failed to load user {params.username}</div> <div>Failed to load user {params.username}</div>
{/if} {/if}
<!-- This is where i might toss in an Invite to Game button ? -->
</div> </div>
<style> <style>

View File

@@ -11,9 +11,8 @@
let avatar, newAvatar; let avatar, newAvatar;
let uploadAvatarSuccess = false; let uploadAvatarSuccess = false;
// tbh i might not need this...
let set = { username: '', tfa: false }; let set = { username: '', tfa: false };
let nameTmp; // annoying... let nameTmp;
const errors = { username: '', checkbox: '', avatar: ''}; const errors = { username: '', checkbox: '', avatar: ''};
let success = {username: '', avatar: '' }; let success = {username: '', avatar: '' };
@@ -24,7 +23,6 @@
if (!user) { if (!user) {
console.log('User did not load, something more official should prolly happen') console.log('User did not load, something more official should prolly happen')
} }
// i don't unerstand why this is necessary but it really doesn't like it otherwise
nameTmp = user.username; nameTmp = user.username;
set.tfa = user.isEnabledTwoFactorAuth; set.tfa = user.isEnabledTwoFactorAuth;
@@ -82,8 +80,6 @@
const data = new FormData(); const data = new FormData();
data.append("file", newAvatar[0]); data.append("file", newAvatar[0]);
// tmp
console.log(data);
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar`, await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user/avatar`,
{ {
@@ -136,8 +132,6 @@
<form on:submit|preventDefault={settingsHandler}> <form on:submit|preventDefault={settingsHandler}>
<div class="form-field"> <div class="form-field">
<div class="label">New Username</div> <div class="label">New Username</div>
<!-- it really hates {user.username} and ${user.username} -->
<!-- <input type="text" placeholder="current username: ${user.username}" bind:value={set.username}> -->
<input type="text" placeholder="{nameTmp}" bind:value={set.username}> <input type="text" placeholder="{nameTmp}" bind:value={set.username}>
<div class="success">{success.username}</div> <div class="success">{success.username}</div>
<div class="error">{errors.username}</div> <div class="error">{errors.username}</div>
@@ -152,18 +146,15 @@
</Card> </Card>
<Card> <Card>
<!-- ok so it can't actually show us the file we upload until we've uploaded it... -->
{#if avatar} {#if avatar}
<img class="avatar" src={avatar} alt="your avatar"/> <img class="avatar" src={avatar} alt="your avatar"/>
{/if} {/if}
<form on:submit|preventDefault={uploadAvatar}> <form on:submit|preventDefault={uploadAvatar}>
<!-- not convinced this has any utility. -->
<!-- <input type="text" bind:value={postVar} placeholder={"choose your file"}/> -->
<div class="form-field"> <div class="form-field">
<div class="label">Pick a new Avatar</div> <div class="label">Pick a new Avatar</div>
<input type="file" bind:files={newAvatar}/> <input type="file" bind:files={newAvatar}/>
<div class="error">{errors.avatar}</div> <div class="error">{errors.avatar}</div>
<div class="success">{success.avatar}</div> <div class="success">{success.avatar}</div>
</div> </div>
<Button type={!newAvatar ? "primary" : "secondary"}>Upload Avatar</Button> <Button type={!newAvatar ? "primary" : "secondary"}>Upload Avatar</Button>
</form> </form>
@@ -174,38 +165,23 @@
</main> </main>
<style> <style>
main { main {
text-align: center; text-align: center;
/* display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 20px; */
} }
div.cards{ div.cards{
display: grid; display: grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
grid-gap: 20px; grid-gap: 20px;
/* text-align: center; */
margin-bottom: 10px; margin-bottom: 10px;
} }
img { img {
/* we want the image to display as the same size no matter the resolution */
/* max-width: fit-content; */
/* max-width: 100px; */
width: 60px; width: 60px;
/* ok this works but i'm guessing i'll need to add some @media ... */
/* padding: 10px; */
/* this doesn't work either when nothing loads and it's just the words... don't love that */
} }
form { form {
/* max-width: 500px; */
text-align: center; text-align: center;
} }
@@ -223,7 +199,6 @@
color: #333; color: #333;
} }
.error{ .error{
font-size: 1vw; font-size: 1vw;
font-weight: bold; font-weight: bold;

View File

@@ -496,18 +496,12 @@
.box { .box {
--width: 70vw; --width: 70vw;
--height: 60vh; --height: 60vh;
/* --height: auto; */
position: absolute; position: absolute;
width: var(--width); width: var(--width);
/* width: auto; */
/* height: var(--height); */ /* height: var(--height); */
height: auto; height: auto;
left: calc(50% - var(--width) / 2); left: calc(50% - var(--width) / 2);
/* left: 0px; */
top: calc(50% - var(--height) / 2); top: calc(50% - var(--height) / 2);
/* top: 0px; */
/* top: calc(50% - ); */
/* display: flex; */
align-items: center; align-items: center;
padding: 8px; padding: 8px;
border: 2px solid white; border: 2px solid white;

View File

@@ -7,8 +7,6 @@
background: white; background: white;
padding: 20px; padding: 20px;
border-radius: 6px; border-radius: 6px;
/* this softens the corners */
box-shadow: 0px 2px 4px rgba(0,0,0,0.1); box-shadow: 0px 2px 4px rgba(0,0,0,0.1);
} }
</style> </style>

View File

@@ -3,7 +3,6 @@
export let user; export let user;
let rank = ''; let rank = '';
let avatar;
if (user.stats.loseGame > user.stats.winGame) { if (user.stats.loseGame > user.stats.winGame) {
rank = "Come on, you can do better" rank = "Come on, you can do better"
@@ -47,13 +46,11 @@
<div class="outer"> <div class="outer">
{#if user} {#if user}
<main> <main>
<!-- <img class="avatar" src="{avatar}" alt="user avatar"> -->
{#await fetchAvatar(user.username) then avatar} {#await fetchAvatar(user.username) then avatar}
<img class="avatar" src="{avatar}" alt="user avatar"> <img class="avatar" src="{avatar}" alt="user avatar">
{:catch error} {:catch error}
<p class="errorA">Avatar was unable to load</p> <p class="errorA">Avatar was unable to load</p>
{/await} {/await}
<!-- <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">
@@ -102,11 +99,8 @@
text-align: center; text-align: center;
} }
/* Normal CSS stuff */
.avatar{ .avatar{
max-width: 150px; max-width: 150px;
/* width: 1em; */
/* padding: 5px; */
} }
/* The variable rich section */ /* The variable rich section */
@@ -114,10 +108,8 @@
max-width: 600px; max-width: 600px;
margin: 40px auto; margin: 40px auto;
text-align: center; text-align: center;
/* i think i want to use a grid? */
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
/* not sure about this, maybe top should be larger? */
grid-template-rows: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
} }
@@ -139,12 +131,6 @@
font-weight: bold; font-weight: bold;
} }
.error{
font-size: 1vw;
font-weight: bold;
color: red;
}
.errorA{ .errorA{
font-size: 0.5em; font-size: 0.5em;
font-weight: bold; font-weight: bold;
@@ -173,8 +159,6 @@
} }
/* Glittery Star Stuff */ /* Glittery Star Stuff */

View File

@@ -2,11 +2,6 @@
import { push } from "svelte-spa-router"; import { push } from "svelte-spa-router";
import { location } from 'svelte-spa-router'; import { location } from 'svelte-spa-router';
// no need, it's just for links
import active from 'svelte-spa-router/active'
// or i could leave them all and not display if they're active?
$: current = $location; $: current = $location;
let handleClickLogout = async () => let handleClickLogout = async () =>

View File

@@ -24,7 +24,6 @@
.tab.big{ .tab.big{
margin-bottom: 50px; margin-bottom: 50px;
/* guessing at size */
} }
.tab.medium{ .tab.medium{
margin-bottom: 40px; margin-bottom: 40px;
@@ -32,7 +31,6 @@
} }
.tab.small{ .tab.small{
margin-bottom: 10px; margin-bottom: 10px;
/* need it small */
} }
ul{ ul{
display: flex; display: flex;
@@ -41,15 +39,12 @@
list-style-type: none; list-style-type: none;
} }
li{ li{
/* margin: 0 16px; */
/* font-size: 18px; */
color: #555; color: #555;
cursor: pointer; cursor: pointer;
} }
li.big{ li.big{
margin: 0 20px; margin: 0 20px;
font-size: 22px; font-size: 22px;
/* guessing at size */
} }
li.medium{ li.medium{
margin: 0 16px; margin: 0 16px;
@@ -59,7 +54,6 @@
li.small{ li.small{
margin: 8px; margin: 8px;
font-size: 10px; font-size: 10px;
/* need it small */
} }
.active{ .active{
@@ -79,7 +73,6 @@
li.default{ li.default{
margin: 0 16px; margin: 0 16px;
font-size: 18px; font-size: 18px;
/* the OG size */
} }
@media screen and (max-width: 700px) { @media screen and (max-width: 700px) {
@@ -93,5 +86,4 @@
} }
} }
</style> </style>

View File

@@ -6,7 +6,6 @@ export async function fetchAvatar(username?: string)
url += `?username=${username}`; url += `?username=${username}`;
} }
// throw new Error("HTTP ")
return fetch(url) return fetch(url)
.then((response) => { .then((response) => {
if (!response.ok) { if (!response.ok) {

View File

@@ -12,11 +12,9 @@ import { fetchUser } from "../pieces/utils";
async function checkLogin(detail) { async function checkLogin(detail) {
const user = await fetchUser(); const user = await fetchUser();
if (!user || !user.username) { if (!user || !user.username) {
// console.log('failed to be logged in')
return false; return false;
} }
else { else {
// console.log('successfully logged in')
return true; return true;
} }
} }

View File

@@ -5,8 +5,6 @@ import ProfileSettings from '../pages/profile/ProfileSettings.svelte';
import ProfileUsers from '../pages/profile/ProfileUsers.svelte'; import ProfileUsers from '../pages/profile/ProfileUsers.svelte';
import ProfileDisplayOneUser from "../pages/profile/ProfileDisplayOneUser.svelte"; import ProfileDisplayOneUser from "../pages/profile/ProfileDisplayOneUser.svelte";
import DisplayAUser from '../pieces/DisplayAUser.svelte';
// establishing the prefix here very clearly so we can have a coherent repeatable structure // establishing the prefix here very clearly so we can have a coherent repeatable structure
export const prefix = '/profile'; export const prefix = '/profile';
@@ -15,6 +13,5 @@ export const profileRoutes = {
'/settings': ProfileSettings, '/settings': ProfileSettings,
'/users': ProfileUsers, '/users': ProfileUsers,
'/users/:username': ProfileDisplayOneUser, '/users/:username': ProfileDisplayOneUser,
// '/users/:username': DisplayAUser,
'*': NotFound '*': NotFound
}; };