Browse Source

see you tomorrow

master
Pheuw1 2 years ago
parent
commit
2a6d3b1412
  1. 2
      back/volume/package-lock.json
  2. 2
      back/volume/package.json
  3. 8
      back/volume/src/auth/auth.controller.ts
  4. 26
      back/volume/src/auth/auth.service.ts
  5. 8
      back/volume/src/chat/chat.controller.ts
  6. 4
      back/volume/src/chat/chat.gateway.ts
  7. 10
      back/volume/src/main.ts
  8. 8
      front/volume/src/Auth.ts
  9. 2
      front/volume/src/components/Alert/Alert.svelte
  10. 5
      front/volume/src/components/Alert/content.ts
  11. 11
      front/volume/src/components/Chat.svelte

2
back/volume/package-lock.json

@ -44,7 +44,7 @@
"passport-42": "^1.2.6",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"rxjs": "^7.8.0",
"socket.io": "^4.6.1",
"source-map-support": "^0.5.21",
"typeorm": "^0.3.12"

2
back/volume/package.json

@ -56,7 +56,7 @@
"passport-42": "^1.2.6",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"rxjs": "^7.8.0",
"socket.io": "^4.6.1",
"source-map-support": "^0.5.21",
"typeorm": "^0.3.12"

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

@ -18,7 +18,7 @@ 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'
import type User from 'src/users/entity/user.entity'
const frontHost =
process.env.HOST !== undefined && process.env.HOST !== ''
@ -30,7 +30,7 @@ const frontPort =
: '80'
@Controller('log')
export class AuthController {
export class AuthController {
constructor (
private readonly authService: AuthService,
private readonly usersService: UsersService
@ -42,10 +42,10 @@ export class AuthController {
@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
const user = (await this.usersService.getFullUser(+profile.id))
user.email = email
console.log(`email sent to ${user.email}`)
await this.usersService.save(user)
}

26
back/volume/src/auth/auth.service.ts

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'
import { BadRequestException, Injectable } from '@nestjs/common'
import { type User } from 'src/users/entity/user.entity'
import { UsersService } from 'src/users/users.service'
import { MailerService } from '@nestjs-modules/mailer'
@ -25,16 +25,22 @@ export class AuthService {
async sendConfirmationEmail (user: User): Promise<void> {
user.authToken = Math.floor(10000 + Math.random() * 90000).toString()
console.log(`email sent to ${user.email}`)
await this.usersService.save(user)
await this.mailerService.sendMail({
to: user.email,
subject: 'Welcome to ft_transcendence! Confirm Email',
template: 'confirm',
context: {
username: user.username,
code: user.authToken
}
})
try {
await this.mailerService.sendMail({
to: user.email,
subject: 'Welcome to ft_transcendence! Confirm Email',
template: 'confirm',
context: {
username: user.username,
code: user.authToken
}
})
} catch {
throw new BadRequestException("Email doesnt't seem to be valid")
}
console.log(`email sent to ${user.email}`)
}
async verifyAccount (code: string): Promise<boolean> {

8
back/volume/src/chat/chat.controller.ts

@ -21,6 +21,7 @@ import type User from 'src/users/entity/user.entity'
import type Channel from './entity/channel.entity'
import { Profile42 } from 'src/auth/42.decorator'
import { Profile } from 'passport-42'
import { IsNumberString, IsPositive } from 'class-validator'
@Controller('channels')
@UseGuards(AuthenticatedGuard)
@ -140,7 +141,9 @@ export class ChatController {
): Promise<void> {
const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(target.data[0])
console.log(target)
if (isNaN(+target.data[1])) {
throw new BadRequestException(`Invalid duration ${target.data[1]}`)
}
if (user == null) {
throw new NotFoundException(`User #${target.data[0]} not found`)
}
@ -167,6 +170,9 @@ export class ChatController {
): Promise<void> {
const channel = await this.channelService.getFullChannel(id)
const user: User | null = await this.usersService.findUser(mute.data[0])
if (isNaN(+mute.data[1])) {
throw new BadRequestException(`Invalid duration ${mute.data[1]}`)
}
if (user == null) {
throw new NotFoundException(`User #${mute.data[0]} not found`)
}

4
back/volume/src/chat/chat.gateway.ts

@ -138,8 +138,8 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
const user = (await this.userService.findUser(kick.to)) as User
const connect = (await this.connectedUserRepository.findOneBy({
user: user.ftId
})) as ConnectedUser
if (connect) {
}))
if (connect !== null) {
console.log(`kicking ${user.username} from ${channel.name} with socket ${connect.socket}`)
this.server.to(connect.socket).emit('kicked')
}

10
back/volume/src/main.ts

@ -1,4 +1,4 @@
import { InternalServerErrorException, Logger } from '@nestjs/common'
import { InternalServerErrorException, Logger, ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import * as session from 'express-session'
@ -15,13 +15,17 @@ async function bootstrap (): Promise<void> {
? +process.env.BACK_PORT
: 3001
const cors = {
origin: new RegExp(`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`),
origin: new RegExp(
`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`
),
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS',
preflightContinue: false,
optionsSuccessStatus: 204,
credentials: true,
allowedHeaders: ['Accept', 'Content-Type', 'Authorization']
allowedHeaders:
['Accept', 'Content-Type', 'Authorization']
}
app.useGlobalPipes(new ValidationPipe())
app.use(
session({
resave: false,

8
front/volume/src/Auth.ts

@ -31,6 +31,7 @@ export function login() {
}
export async function verify() {
if (get(store).twoFa === true) return;
let email : string;
await show_popup("Enter your preferred email adress:\n(defaults to 42 email)")
email = get(content);
@ -46,7 +47,6 @@ export async function verify() {
})
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", {
@ -56,9 +56,11 @@ export async function verify() {
});
console.log(response.ok)
if (response.ok) {
console.log("here")
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);}
} else {
console.log("there")
await show_popup("Email doensn't seem valid", false);}
}

2
front/volume/src/components/Alert/Alert.svelte

@ -5,7 +5,7 @@
export let onOkay = () => {};
import { content, popup } from "./content";
let value;
let value = '';
let onChange = () => {
$content = "";
};

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

@ -10,8 +10,7 @@ export async function show_popup(message, form = true) {
message,
form
}))
await waitForCondition()
await waitForCondition()
await waitForCondition()
}
export async function waitForCondition() {
@ -25,5 +24,5 @@ export async function waitForCondition() {
return await checkFlag();
}
}
return checkFlag()
return await checkFlag()
}

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

@ -210,6 +210,8 @@
"Enter a time for which the user will be banned from this channel"
);
const duration = $content;
if (duration == "")
return;
response = await fetch(API_URL + "/channels/" + channel.id + "/ban", {
credentials: "include",
method: "POST",
@ -217,16 +219,15 @@
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);
socket.emit("kickUser", channel.id, $store.ftId, target.ftId);
} else {
const error = await response.json();
await show_popup(error.message, false);
}
socket.emit("kickUser", channel.id, $store.ftId, target.ftId);
const error = await response.json();
await show_popup(error.message, false)
}
}
};

Loading…
Cancel
Save