Pheuw1 2 years ago
parent
commit
88f3596bbe
  1. 2
      Makefile
  2. 17
      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. 7
      front/volume/src/App.svelte
  7. 38
      front/volume/src/Auth.ts
  8. 4
      front/volume/src/components/Alert/content.ts
  9. 5
      front/volume/src/components/Chat.svelte

2
Makefile

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

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

@ -17,6 +17,8 @@ import { Profile42 } from './42.decorator'
import { AuthService } from './auth.service' import { AuthService } from './auth.service'
import { UsersService } from 'src/users/users.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 = const frontHost =
process.env.HOST !== undefined && process.env.HOST !== '' process.env.HOST !== undefined && process.env.HOST !== ''
@ -28,12 +30,25 @@ const frontPort =
: '80' : '80'
@Controller('log') @Controller('log')
export class AuthController { export class AuthController {
constructor ( constructor (
private readonly authService: AuthService, private readonly authService: AuthService,
private readonly usersService: UsersService 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') @Get('in')
@UseGuards(FtOauthGuard) @UseGuards(FtOauthGuard)
ftAuth (): void {} ftAuth (): void {}

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

@ -8,7 +8,7 @@
<body> <body>
<h2>Hello {{username}}! </h2> <h2>Hello {{username}}! </h2>
<p> Once you clicked on the next verify button, you will have access to the app</p> <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> <button type="submit" name="code" value={{code}}>Verify</button>
</form> </form>
</body> </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 { export class IdDto {
@IsNumber() @IsNumber()
@ -13,3 +13,8 @@ export class PasswordDto {
export class MuteDto { export class MuteDto {
data: number[] data: number[]
} }
export class EmailDto {
@IsEmail()
email: string
}

0
.gitattributes → front/volume/.gitattributes

7
front/volume/src/App.svelte

@ -167,9 +167,12 @@
> >
</div> </div>
{:else if $store.twoFA === true && $store.isVerified === false} {: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} {:else}
<Navbar <Navbar
{clickProfile} {clickProfile}
{clickHistory} {clickHistory}
{clickFriends} {clickFriends}

38
front/volume/src/Auth.ts

@ -1,6 +1,6 @@
import { writable } from "svelte/store"; 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"); let _user = localStorage.getItem("user");
export const store = writable(_user ? JSON.parse(_user) : null); export const store = writable(_user ? JSON.parse(_user) : null);
store.subscribe((value) => { store.subscribe((value) => {
@ -30,15 +30,37 @@ export function login() {
window.location.replace(API_URL + "/log/in"); window.location.replace(API_URL + "/log/in");
} }
export function verify() { export async function verify() {
fetch(API_URL + "/log/verify", { let email : string;
method: "get", 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", mode: "cors",
credentials: "include", credentials: "include",
}); });
show_popup( console.log(response.ok)
"We have sent you an email to verify your account. Check the mailbox which is linked to your 42's profile." if (response.ok) {
, false); 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() { 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}) const unsub = popup.subscribe((value) => {val = value})
async function checkFlag() { async function checkFlag() {
if (val == null) { if (val == null) {
console.log("finished",val)
unsub() unsub()
return new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
} else { } else {
console.log("waiting")
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));
return await checkFlag(); return await checkFlag();
} }

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

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

Loading…
Cancel
Save