Created signup form
This commit is contained in:
parent
6f245534f0
commit
41b1e8837b
@ -43,6 +43,7 @@ export interface CreateFolderResponse extends BaseResponse {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export type SignupResponse = DeleteResponse;
|
||||
export type UploadFileResponse = DeleteResponse;
|
||||
export interface DeleteResponse extends BaseResponse {
|
||||
statusCode: 200;
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
GetRootResponse,
|
||||
LoginResponse,
|
||||
RefreshResponse,
|
||||
SignupResponse,
|
||||
UploadFileResponse
|
||||
} from '../../dto';
|
||||
import jwtDecode, { JwtPayload } from 'jwt-decode';
|
||||
@ -94,7 +95,7 @@ export const auth_login = (
|
||||
export const auth_signup = (
|
||||
username: string,
|
||||
password: string
|
||||
): Promise<LoginResponse | ErrorResponse> =>
|
||||
): Promise<SignupResponse | ErrorResponse> =>
|
||||
post<AuthSignUpRequest>('/api/auth/signup', {
|
||||
username: username,
|
||||
password: password
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
||||
import LoginView from '@/views/LoginView.vue';
|
||||
import SignupView from '@/views/SignupView.vue';
|
||||
import HomeView from '@/views/HomeView.vue';
|
||||
import AboutView from '@/views/AboutView.vue';
|
||||
import FSView from '@/views/FSView.vue';
|
||||
@ -19,6 +20,11 @@ const routes: Array<RouteRecordRaw> = [
|
||||
name: 'login',
|
||||
component: LoginView
|
||||
},
|
||||
{
|
||||
path: '/signup',
|
||||
name: 'signup',
|
||||
component: SignupView
|
||||
},
|
||||
{
|
||||
path: '/fs/:node_id',
|
||||
name: 'fs',
|
||||
|
@ -13,7 +13,7 @@ const jwt = inject<TokenInjectType>('jwt') as TokenInjectType;
|
||||
|
||||
async function login() {
|
||||
if (username.value === '' || password.value === '') {
|
||||
error.value = 'Username and/or Password missing';
|
||||
error.value = 'Email and/or Password missing';
|
||||
return;
|
||||
}
|
||||
const res = await auth_login(username.value, password.value);
|
||||
@ -38,6 +38,7 @@ async function login() {
|
||||
<input type="email" placeholder="Email" v-model="username" />
|
||||
<input type="password" placeholder="Password" v-model="password" />
|
||||
<button @click="login()">Login</button>
|
||||
<router-link to="signup">Signup instead?</router-link>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
35
frontend/src/views/SignupView.vue
Normal file
35
frontend/src/views/SignupView.vue
Normal file
@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { auth_signup, isErrorResponse } from '@/api';
|
||||
|
||||
let username = ref('');
|
||||
let password = ref('');
|
||||
let password2 = ref('');
|
||||
const error = ref('');
|
||||
|
||||
async function signup() {
|
||||
if (username.value === '' || password.value === '') {
|
||||
error.value = 'Email and/or Password missing';
|
||||
return;
|
||||
}
|
||||
if (password.value !== password2.value) {
|
||||
error.value = "Passwords don't match";
|
||||
return;
|
||||
}
|
||||
const res = await auth_signup(username.value, password.value);
|
||||
error.value = isErrorResponse(res)
|
||||
? 'Signup failed: ' + res.message
|
||||
: 'Signup successful, please wait till an admin unlocks your account.';
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="error !== ''" v-text="error"></div>
|
||||
<input type="email" placeholder="Email" v-model="username" />
|
||||
<input type="password" placeholder="Password" v-model="password" />
|
||||
<input type="password" placeholder="Repeat password" v-model="password2" />
|
||||
<button @click="signup()">Signup</button>
|
||||
<router-link to="login">Login instead?</router-link>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
@ -11,10 +11,10 @@ import { AuthService } from '../services/auth';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { Public } from '../authguards';
|
||||
import {
|
||||
BaseResponse,
|
||||
ErrorResponse,
|
||||
LoginResponse,
|
||||
RefreshResponse
|
||||
RefreshResponse,
|
||||
SignupResponse
|
||||
} from 'dto';
|
||||
|
||||
@Controller('api/auth')
|
||||
@ -37,7 +37,7 @@ export default class AuthController {
|
||||
async signup(
|
||||
@Body('username') username,
|
||||
@Body('password') password
|
||||
): Promise<BaseResponse | ErrorResponse> {
|
||||
): Promise<SignupResponse | ErrorResponse> {
|
||||
if ((await this.authService.findUser(username)) != null)
|
||||
throw new BadRequestException('Username already taken');
|
||||
await this.authService.signup(username, password);
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
UnauthorizedException
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { JWTToken, User, UserRole } from '../entities';
|
||||
import { Repository, LessThanOrEqual } from 'typeorm';
|
||||
@ -81,6 +85,8 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async signup(username: string, password: string) {
|
||||
if (await this.findUser(username))
|
||||
throw new BadRequestException('User already exists');
|
||||
const user = new User();
|
||||
user.name = username;
|
||||
user.password = await argon2.hash(password);
|
||||
|
Loading…
Reference in New Issue
Block a user