Browse Source

one picture avatar upload

master
nicolas-arnaud 2 years ago
parent
commit
d441108c11
  1. 1
      back/volume/src/pong/game/Game.ts
  2. 4
      back/volume/src/users/users.controller.ts
  3. 36
      front/volume/src/components/Profile.svelte

1
back/volume/src/pong/game/Game.ts

@ -147,6 +147,7 @@ export class Game {
stop (): void { stop (): void {
if (this.timer !== null) { if (this.timer !== null) {
this.gameStoppedCallback(this.players[0].name) this.gameStoppedCallback(this.players[0].name)
clearInterval(this.timer) clearInterval(this.timer)
this.timer = null this.timer = null
this.players = [] this.players = []

4
back/volume/src/users/users.controller.ts

@ -10,7 +10,8 @@ import {
UseInterceptors, UseInterceptors,
Res, Res,
StreamableFile, StreamableFile,
BadRequestException BadRequestException,
Redirect
} from '@nestjs/common' } from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express' import { FileInterceptor } from '@nestjs/platform-express'
@ -57,6 +58,7 @@ export class UsersController {
@Post('avatar') @Post('avatar')
@UseGuards(AuthenticatedGuard) @UseGuards(AuthenticatedGuard)
@Redirect('http://localhost')
@UseInterceptors( @UseInterceptors(
FileInterceptor('avatar', { FileInterceptor('avatar', {
storage: diskStorage({ storage: diskStorage({

36
front/volume/src/components/Profile.svelte

@ -26,20 +26,32 @@
event.preventDefault(); event.preventDefault();
alert("Trying to " + (is2faEnabled ? "disable" : "enable") + " 2FA"); alert("Trying to " + (is2faEnabled ? "disable" : "enable") + " 2FA");
} }
function submitAvatar() {
let form: HTMLFormElement = <HTMLFormElement>(
document.getElementById("upload_avatar")
);
form.submit();
}
</script> </script>
<div class="overlay"> <div class="overlay">
<div class="profile" on:click|stopPropagation on:keydown|stopPropagation> <div class="profile" on:click|stopPropagation on:keydown|stopPropagation>
<div class="profile-header"> <div class="profile-header">
<img class="profile-img" src={API_URL + "/avatar"} alt="avatar" />
<h3>{realname}</h3> <h3>{realname}</h3>
<form
action={API_URL + "/avatar"} <form action={API_URL + "/avatar"} method="post"
method="post" enctype="multipart/form-data" id= "upload_avatar">
enctype="multipart/form-data" <div class=input-avatar>
> <label for="avatar-input">
<input type="file" id="avatar-input" name="avatar" /> <img src={API_URL + "/avatar"} alt="avatar" class="profile-img" />
<input type="submit" /> </label>
<input
type="file"
id="avatar-input"
name="avatar"
on:change={submitAvatar}
/>
</div>
</form> </form>
</div> </div>
<div class="profile-body"> <div class="profile-body">
@ -97,12 +109,16 @@
} }
.profile-img { .profile-img {
width: 50px; width: 80px;
height: 50px; height: 80px;
margin-right: 1rem; margin-right: 1rem;
} }
.two-factor-auth { .two-factor-auth {
margin-top: 1rem; margin-top: 1rem;
} }
.input-avatar > input {
display: none;
}
</style> </style>

Loading…
Cancel
Save