Browse Source

* Fix 2fa

master
vvandenb 2 years ago
parent
commit
9363512fd9
  1. 2
      Makefile
  2. 1
      back/volume/src/auth/auth.controller.ts
  3. 1
      back/volume/src/auth/auth.service.ts
  4. 158
      front/volume/src/App.svelte
  5. 19
      front/volume/src/Auth.ts
  6. 2
      list

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

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

@ -66,7 +66,6 @@ export class AuthController {
@Get('/verify')
@UseGuards(AuthenticatedGuard)
@Redirect(`http://${frontHost}:${frontPort}`)
async VerifyEmail (@Profile42() profile: Profile): Promise<void> {
const ftId: number = profile.id
const user = await this.usersService.findUser(ftId)

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

@ -25,7 +25,6 @@ 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)
try {
await this.mailerService.sendMail({

158
front/volume/src/App.svelte

@ -167,90 +167,92 @@
>
</div>
{:else if $store.twoFA === true && $store.isVerified === false}
<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>
<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}
{clickHistory}
{clickFriends}
{clickChannels}
{clickLeaderboard}
{failedGameLogIn}
{gamePlaying}
/>
{#if !failedGameLogIn && !gamePlaying}
<Navbar
{clickProfile}
{clickHistory}
{clickFriends}
{clickChannels}
{clickLeaderboard}
{failedGameLogIn}
{gamePlaying}
/>
{#if appState.includes(`${APPSTATE.CHANNELS}#`)}
{#key appState}
{#if appState.includes(`${APPSTATE.CHANNELS}#`)}
{#key appState}
<div
on:click={() => setAppState(APPSTATE.CHANNELS)}
on:keydown={() => setAppState(APPSTATE.CHANNELS)}
>
<Chat
{appState}
{setAppState}
bind:channel={selectedChannel}
on:view-profile={openIdProfile}
on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame}
on:send-message={openDirectChat}
on:return-home={resetAppState}
/>
</div>
{/key}
{/if}
{#if appState.includes(APPSTATE.CHANNELS)}
<div
class="{appState !== APPSTATE.CHANNELS ? 'hidden' : ''}"
on:click={resetAppState}
on:keydown={resetAppState}
>
<Channels onSelectChannel={handleSelectChannel} />
</div>
{/if}
{#if appState === APPSTATE.LEADERBOARD}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Leaderboard />
</div>
{/if}
{#if appState === APPSTATE.FRIENDS}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Friends />
</div>
{/if}
{#if appState === APPSTATE.HISTORY}
<div on:click={resetAppState} on:keydown={resetAppState}>
<MatchHistory />
</div>
{/if}
{#if appState === APPSTATE.HISTORY_ID}
<div
on:click={() => setAppState(APPSTATE.PROFILE)}
on:keydown={() => setAppState(APPSTATE.PROFILE)}
>
<MatchHistory username={profileUsername} />
</div>
{/if}
{#if appState === APPSTATE.PROFILE}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Profile {resetGameConnection} {gamePlaying} bind:username={profileUsername} on:view-history={() => setAppState(APPSTATE.HISTORY_ID)} />
</div>
{/if}
{#if appState === APPSTATE.PROFILE_ID}
<div
on:click={() => setAppState(APPSTATE.CHANNELS)}
on:keydown={() => setAppState(APPSTATE.CHANNELS)}
on:click={() =>
setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)}
on:keydown={() =>
setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)}
>
<Chat
{appState}
{setAppState}
bind:channel={selectedChannel}
on:view-profile={openIdProfile}
on:add-friend={addFriend}
on:invite-to-game={pong.inviteToGame}
on:send-message={openDirectChat}
on:return-home={resetAppState}
<Profile
{gamePlaying}
bind:username={profileUsername}
on:view-history={() => setAppState(APPSTATE.HISTORY_ID)}
/>
</div>
{/key}
{/if}
{#if appState.includes(APPSTATE.CHANNELS)}
<div
class="{appState !== APPSTATE.CHANNELS ? 'hidden' : ''}"
on:click={resetAppState}
on:keydown={resetAppState}
>
<Channels onSelectChannel={handleSelectChannel} />
</div>
{/if}
{#if appState === APPSTATE.LEADERBOARD}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Leaderboard />
</div>
{/if}
{#if appState === APPSTATE.FRIENDS}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Friends />
</div>
{/if}
{#if appState === APPSTATE.HISTORY}
<div on:click={resetAppState} on:keydown={resetAppState}>
<MatchHistory />
</div>
{/if}
{#if appState === APPSTATE.HISTORY_ID}
<div
on:click={() => setAppState(APPSTATE.PROFILE)}
on:keydown={() => setAppState(APPSTATE.PROFILE)}
>
<MatchHistory username={profileUsername} />
</div>
{/if}
{#if appState === APPSTATE.PROFILE}
<div on:click={resetAppState} on:keydown={resetAppState}>
<Profile {resetGameConnection} {gamePlaying} bind:username={profileUsername} on:view-history={() => setAppState(APPSTATE.HISTORY_ID)} />
</div>
{/if}
{#if appState === APPSTATE.PROFILE_ID}
<div
on:click={() =>
setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)}
on:keydown={() =>
setAppState(APPSTATE.CHANNELS + "#" + selectedChannel.name)}
>
<Profile
{gamePlaying}
bind:username={profileUsername}
on:view-history={() => setAppState(APPSTATE.HISTORY_ID)}
/>
</div>
{/if}
{/if}
<Pong bind:gamePlaying={gamePlaying} bind:this={pong} bind:failedGameLogIn={failedGameLogIn} {appState} {setAppState} bind:resetGameConnection={resetGameConnection} />
{/if}

19
front/volume/src/Auth.ts

@ -31,13 +31,11 @@ export function login() {
}
export async function verify() {
if (get(store).twoFa === true) return;
if (get(store).isVerified === true) return;
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') {
if (email !== undefined && email !== '' && email !== 'ok') {
const response = await fetch(API_URL + "/log/email", {
method: "POST",
mode: "cors",
@ -47,22 +45,17 @@ 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(API_URL)
}
const response = await fetch(API_URL + "/log/verify", {
method: "GET",
mode: "cors",
credentials: "include",
});
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);
await show_popup("We have sent you an email to verify your account. Check your mailbox!.", false);
} else {
console.log("there")
await show_popup("Email doensn't seem valid", false);}
await show_popup("Email doensn't seem valid", false);
}
}
export function logout() {

2
list

@ -1,2 +0,0 @@
- manage users on deleting channel
- delete
Loading…
Cancel
Save