COrrection de nombreux bug, changement de font, réel username unique insensible à la casse...

This commit is contained in:
cherif
2023-01-17 00:30:39 +01:00
parent 8b365968ac
commit 796a8464b1
16 changed files with 95 additions and 83 deletions

View File

@@ -12,18 +12,9 @@ import { SessionSerializer } from './utils/serializer';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([User, Friendship]), UsersModule, 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 providers: [AuthenticationService, FortyTwoStrategy, UsersService, SessionSerializer, FriendshipService
// JwtStrategy ],
],
exports: [AuthenticationService], exports: [AuthenticationService],
controllers: [AuthenticationController], controllers: [AuthenticationController],
}) })

View File

@@ -15,7 +15,7 @@ export class User {
@Column({unique: true}) @Column({unique: true})
fortyTwoId: string; fortyTwoId: string;
@Column() @Column({unique: true})
username: string; username: string;
@Column() @Column()

View File

@@ -58,7 +58,7 @@ export class UsersController {
@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') 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) if (user.isEnabledTwoFactorAuth === false && user.isTwoFactorAuthenticated === true)
this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id); this.usersService.setIsTwoFactorAuthenticatedWhenLogout(user.id);
if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false) if (user.isEnabledTwoFactorAuth === true && user.isTwoFactorAuthenticated === false)

View File

@@ -55,12 +55,9 @@ export class UsersService {
} }
async isUsernameExists(usernameToSearch: string): Promise<boolean> { async isUsernameExists(usernameToSearch: string): Promise<boolean> {
// console.log('searching for username: ' + usernameToSearch) const user = await this.userRepository.createQueryBuilder('user')
.where('LOWER(user.username) = LOWER(:username)', {username : usernameToSearch})
const user = await this.userRepository.findOneBy({username : usernameToSearch}); .getOne()
// console.log({...user})
if (!user) if (!user)
return false; return false;
return true; return true;
@@ -101,10 +98,9 @@ export class UsersService {
return this.userRepository.save(user); return this.userRepository.save(user);
} }
async update(id: number, updateUserDto: UpdateUsersDto) { async update(id: number, updateUserDto: UpdateUsersDto, username : string) {
// console.log(`Update user ${id} with ${updateUserDto.isEnabledTwoFactorAuth}`); console.log("Maj user username : " + username + " updateuser dto " + updateUserDto.username )
// console.log({...updateUserDto}) if (await this.isUsernameExists(updateUserDto.username) === true && updateUserDto.username !== username) {
if (await this.isUsernameExists(updateUserDto.username) === true) {
// console.log('updating username ' + updateUserDto.username + ' but it already is in use') // 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);
} }

View File

@@ -16,11 +16,11 @@ body {
} }
@font-face { @font-face {
font-family: "Bit5x3"; font-family: "PressStart2P";
src: src:
url("./fonts/Bit5x3.woff2") format("woff2"), url("./fonts/PressStart2P.woff2") format("woff2"),
local("Bit5x3"), local("PressStart2P"),
url("./fonts/Bit5x3.woff") format("woff"); url("./fonts/PressStart2P.woff") format("woff");
font-weight: normal; font-weight: normal;
font-style: normal; font-style: normal;
font-display: swap; font-display: swap;
@@ -42,8 +42,8 @@ a:visited {
.background-pages { .background-pages {
background-color: #333; background-color: #333;
font-family: "Bit5x3"; font-family: "PressStart2P";
font-size: 2vw; font-size: 1vw;
color: white; color: white;
} }

View File

@@ -71,8 +71,8 @@
border-color: #071013; border-color: #071013;
border-width: 2px; border-width: 2px;
color: white; color: white;
font-family: "Bit5x3"; font-family: "PressStart2P";
font-size: x-large; font-size: 1vw;
padding: 10px; padding: 10px;
} }
@@ -81,8 +81,8 @@
border-color: #071013; border-color: #071013;
border-width: 2px; border-width: 2px;
color: white; color: white;
font-family: "Bit5x3"; font-family: "PressStart2P";
font-size: x-large; font-size: 1vw;
padding: 10px; padding: 10px;
} }

View File

@@ -88,7 +88,7 @@
.error { .error {
font-weight: bold; font-weight: bold;
font-size: 0.8em; font-size: 1vw;
color: red; color: red;
} }
</style> </style>

View File

@@ -393,7 +393,16 @@
</div> <!-- div "game_page" --> </div> <!-- div "game_page" -->
<style> <style>
@font-face {
font-family: "Bit5x3";
src:
url("/fonts/Bit5x3.woff2") format("woff2"),
local("Bit5x3"),
url("/fonts/Bit5x3.woff") format("woff");
font-weight: normal;
font-style: normal;
font-display: swap;
}
.dim_background { .dim_background {
background-color: #222; background-color: #222;
} }
@@ -423,15 +432,16 @@ canvas {
/* background-color: #ff0000; */ /* background-color: #ff0000; */
background-color: #333; background-color: #333;
max-width: 75vw; max-width: 75vw;
font-family: "Bit5x3";
/* max-height: 100vh; */ /* max-height: 100vh; */
width: 80%; width: 80%;
} }
.div_game { .div_game {
text-align: center; text-align: center;
font-family: "Bit5x3"; font-family: "PressStart2P";
color: rgb(245, 245, 245); color: rgb(245, 245, 245);
font-size: x-large; font-size: 1vw;
} }
.div_game fieldset { .div_game fieldset {
max-width: 50vw; max-width: 50vw;
@@ -442,10 +452,10 @@ canvas {
padding: 10px; padding: 10px;
} }
.pong_button { .pong_button {
font-family: "Bit5x3"; font-family: "PressStart2P";
color: rgb(245, 245, 245); color: rgb(245, 245, 245);
background-color: #333333; background-color: #333333;
font-size: x-large; font-size: 1vw;
padding: 10px; padding: 10px;
} }
.avatar { .avatar {

View File

@@ -179,6 +179,16 @@
<!-- --> <!-- -->
<style> <style>
@font-face {
font-family: "Bit5x3";
src:
url("/fonts/Bit5x3.woff2") format("woff2"),
local("Bit5x3"),
url("/fonts/Bit5x3.woff") format("woff");
font-weight: normal;
font-style: normal;
font-display: swap;
}
.dim_background { .dim_background {
background-color: #222; background-color: #222;
@@ -203,15 +213,16 @@ canvas {
/* background-color: #ff0000; */ /* background-color: #ff0000; */
background-color: #333333; background-color: #333333;
max-width: 75vw; max-width: 75vw;
font-family: "Bit5x3";
/* max-height: 100vh; */ /* max-height: 100vh; */
width: 80%; width: 80%;
} }
.div_game { .div_game {
text-align: center; text-align: center;
font-family: "Bit5x3"; font-family: "PressStart2P";
color: rgb(245, 245, 245); color: rgb(245, 245, 245);
font-size: x-large; font-size: 1vw;
} }
.div_game fieldset { .div_game fieldset {
max-width: 50vw; max-width: 50vw;
@@ -222,15 +233,15 @@ canvas {
padding: 10px; padding: 10px;
} }
.pong_button { .pong_button {
font-family: "Bit5x3"; font-family: "PressStart2P";
color: rgb(245, 245, 245); color: rgb(245, 245, 245);
background-color: #333333; background-color: #333333;
font-size: x-large; font-size: 1vw;
padding: 10px; padding: 10px;
} }
#match_list { #match_list {
font-family: 'Courier New', Courier, monospace; font-family: 'Courier New', Courier, monospace;
font-size: large; font-size: 1vw;
} }
.avatar { .avatar {
min-height: 100px; min-height: 100px;

View File

@@ -70,7 +70,7 @@
.stats-table { .stats-table {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
font-size: 0.9em; font-size: 1vw;
min-width: 400px; min-width: 400px;
} }

View File

@@ -6,6 +6,7 @@
import Button from '../../pieces/Button.svelte'; import Button from '../../pieces/Button.svelte';
import { fetchAvatar } from "../../pieces/utils"; import { fetchAvatar } from "../../pieces/utils";
import { error } from '../game/client/message';
let user; let user;
let avatar, newAvatar; let avatar, newAvatar;
@@ -34,40 +35,40 @@
}) })
const settingsHandler = async() => { const settingsHandler = async() => {
// I don't really care which i use at this point...
// if (set.username === nameTmp) {
if ((set.username.trim() === '') && set.tfa === user.isEnabledTwoFactorAuth) { if ((set.username.trim() === '') && set.tfa === user.isEnabledTwoFactorAuth) {
errors.username = 'Invalid new username'; set.username = user.username
return;
} }
else if ((set.username.trim() === '') && set.tfa !== user.isEnabledTwoFactorAuth) { errors.username = ''
set.username = user.username await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`, {
} method: 'PATCH',
else { headers: {
errors.username = ''; 'Content-Type': 'application/json'
},
body: JSON.stringify({
"username": set.username,
"isEnabledTwoFactorAuth": set.tfa
})
})
.then((response) => {
if (response.status === 200)
{
errors.username = ''
success.username = "Your changes have been saved"
}
else if (response.status === 201)
push("/2fa");
else if (response.status === 409)
{
success.username = ''
errors.username = `${set.username} is already in use, pick a different one.`;
}
else{
success.username = ''
errors.username = "Something went wrong";
}
} }
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`, { )
method: 'PATCH', .catch((err) => errors.username = err)
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"username": set.username,
"isEnabledTwoFactorAuth": set.tfa
})
})
.then((response) => {
if (response.status === 200)
success.username = "Your changes have been saved"
else if (response.status === 201)
push("/2fa");
else if (response.status === 409)
errors.username = `${set.username} is already in use, pick a different one.`;
else
errors.username = "Something went wrong";
}
)
.catch((err) => errors.username = err)
// .then((result) => console.log(result)) // .then((result) => console.log(result))
// .then(() => console.log('successful sub of new settings')) // .then(() => console.log('successful sub of new settings'))
@@ -198,13 +199,13 @@
.error{ .error{
font-size: 0.8em; font-size: 1vw;
font-weight: bold; font-weight: bold;
color: red; color: red;
} }
.success{ .success{
font-size: 0.8em; font-size: 1vw;
font-weight: bold; font-weight: bold;
color: green; color: green;
} }

View File

@@ -347,7 +347,7 @@
div.top-grid{ div.top-grid{
display: grid; display: grid;
grid-template-columns: repeat(12, 1fr); grid-template-columns: repeat(8, 1fr);
/* max-height: calc(100vh - 30vh); */ /* max-height: calc(100vh - 30vh); */
height: 85vh; height: 85vh;
/* margin: 0; */ /* margin: 0; */
@@ -357,12 +357,15 @@
grid-column: 1 / span 2; grid-column: 1 / span 2;
background: #FB8B24; background: #FB8B24;
padding: 1vw; padding: 1vw;
font-size: smaller;
max-width: 100%; max-width: 100%;
max-height: 100%; max-height: 100%;
box-sizing: border-box; box-sizing: border-box;
-moz-box-sizing: border-box; -moz-box-sizing: border-box;
-webkit-box-sizing: border-box; -webkit-box-sizing: border-box;
border-right: 4px solid #071013; border-right: 4px solid #071013;
border-bottom: 4px solid #071013;
overflow-wrap: break-word;
} }
div.sidebar-item{ div.sidebar-item{

View File

@@ -153,7 +153,7 @@
} }
.error{ .error{
font-size: 0.8em; font-size: 1vw;
font-weight: bold; font-weight: bold;
color: red; color: red;
} }

View File

@@ -43,9 +43,9 @@
background-color: #444; background-color: #444;
border-color: #071013; border-color: #071013;
color: white; color: white;
font-family: "Bit5x3"; font-family: "PressStart2P";
border-width: 2px; border-width: 2px;
font-size: 2vw; font-size: 1vw;
} }
@@ -53,9 +53,9 @@
background-color: #008c8c; background-color: #008c8c;
border-color: #071013; border-color: #071013;
color: white; color: white;
font-family: "Bit5x3"; font-family: "PressStart2P";
border-width: 2px; border-width: 2px;
font-size: 2vw; font-size: 1vw;
} }
.header { .header {