Pheuw1 2 years ago
parent
commit
88f3596bbe
  1. 2
      Makefile
  2. 15
      back/volume/src/auth/auth.controller.ts
  3. 2
      back/volume/src/auth/mails/confirm.hbs
  4. 7
      back/volume/src/chat/dto/updateUser.dto.ts
  5. 0
      front/volume/.gitattributes
  6. 5
      front/volume/src/App.svelte
  7. 38
      front/volume/src/Auth.ts
  8. 4
      front/volume/src/components/Alert/content.ts
  9. 3
      front/volume/src/components/Chat.svelte

2
Makefile

@ -4,7 +4,7 @@ USER = gavaniwast
all: clean dev
dev:
NODE_ENV="development" docker-compose up --build
NODE_ENV="development" docker compose up --build
check:
NODE_ENV="check" docker-compose run back --build

15
back/volume/src/auth/auth.controller.ts

@ -17,6 +17,8 @@ import { Profile42 } from './42.decorator'
import { AuthService } from './auth.service'
import { UsersService } from 'src/users/users.service'
import { EmailDto } from 'src/chat/dto/updateUser.dto'
import User from 'src/users/entity/user.entity'
const frontHost =
process.env.HOST !== undefined && process.env.HOST !== ''
@ -34,6 +36,19 @@ export class AuthController {
private readonly usersService: UsersService
) {}
@Post('/email')
@UseGuards(AuthenticatedGuard)
async setEmail (
@Profile42() profile: Profile,
@Body() body: EmailDto
): Promise<void> {
console.log('in')
const email = body.email
const user = (await this.usersService.findUser(+profile.id)) as User
user.email = email
await this.usersService.save(user)
}
@Get('in')
@UseGuards(FtOauthGuard)
ftAuth (): void {}

2
back/volume/src/auth/mails/confirm.hbs

@ -8,7 +8,7 @@
<body>
<h2>Hello {{username}}! </h2>
<p> Once you clicked on the next verify button, you will have access to the app</p>
<form action="http://c2r7p5:3001/log/verify" method="post">
<form action="http://localhost:3001/log/verify" method="post">
<button type="submit" name="code" value={{code}}>Verify</button>
</form>
</body>

7
back/volume/src/chat/dto/updateUser.dto.ts

@ -1,4 +1,4 @@
import { IsNumber, IsString } from 'class-validator'
import { IsEmail, IsNumber, IsString } from 'class-validator'
export class IdDto {
@IsNumber()
@ -13,3 +13,8 @@ export class PasswordDto {
export class MuteDto {
data: number[]
}
export class EmailDto {
@IsEmail()
email: string
}

0
.gitattributes → front/volume/.gitattributes

5
front/volume/src/App.svelte

@ -167,7 +167,10 @@
>
</div>
{:else if $store.twoFA === true && $store.isVerified === false}
<h1><button type="button" on:click={verify}>verify</button></h1>
<div class="login-div">
<button class="login-button" type="button" style="width:100%;height:100%;font-size:xx-large;" on:click={verify}>Verify</button
>
</div>
{:else}
<Navbar
{clickProfile}

38
front/volume/src/Auth.ts

@ -1,6 +1,6 @@
import { writable } from "svelte/store";
import { show_popup } from "./components/Alert/content";
import { content, show_popup } from "./components/Alert/content";
import {get} from 'svelte/store'
let _user = localStorage.getItem("user");
export const store = writable(_user ? JSON.parse(_user) : null);
store.subscribe((value) => {
@ -30,15 +30,37 @@ export function login() {
window.location.replace(API_URL + "/log/in");
}
export function verify() {
fetch(API_URL + "/log/verify", {
method: "get",
export async function verify() {
let email : string;
await show_popup("Enter your preferred email adress:\n(defaults to 42 email)")
email = get(content);
if (email == '')
return ;
if (email != 'ok') {
const response = await fetch(API_URL + "/log/email", {
method: "POST",
mode: "cors",
headers: {"Content-Type": "application/json",},
credentials: "include",
body: JSON.stringify({email: email})
})
if (response.ok) {await show_popup("Email set",false)}
else {await show_popup("Couldn't set Email",false); return }
console.log(response.ok)
}
console.log(API_URL)
const response = await fetch(API_URL + "/log/verify", {
method: "GET",
mode: "cors",
credentials: "include",
});
show_popup(
"We have sent you an email to verify your account. Check the mailbox which is linked to your 42's profile."
, false);
console.log(response.ok)
if (response.ok) {
console.log("here")
await show_popup("We have sent you an email to verify your account. Check your mailbox!.", false);
} else { await show_popup("Email doensn't seem valid", false);}
}
export function logout() {

4
front/volume/src/components/Alert/content.ts

@ -18,11 +18,9 @@ export async function waitForCondition() {
const unsub = popup.subscribe((value) => {val = value})
async function checkFlag() {
if (val == null) {
console.log("finished",val)
unsub()
return new Promise(resolve => setTimeout(resolve, 100));
await new Promise(resolve => setTimeout(resolve, 100));
} else {
console.log("waiting")
await new Promise(resolve => setTimeout(resolve, 1000));
return await checkFlag();
}

3
front/volume/src/components/Chat.svelte

@ -217,7 +217,7 @@
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ data: [target.ftId, duration] }),
body: JSON.stringify({ data: target.ftId, duration }),
});
if (response.ok) {
await show_popup(`User banned for: ${duration} seconds`, false);
@ -226,6 +226,7 @@
const error = await response.json();
await show_popup(error.message, false);
}
socket.emit("kickUser", channel.id, $store.ftId, target.ftId);
}
};

Loading…
Cancel
Save