Skip to content

Commit

Permalink
Feat/registrationscreen (#3)
Browse files Browse the repository at this point in the history
* done with loginscreen

* .

* rename files

* done with loginscreen

* rename files

* user resource legenerálása

* Registration form on the way

* user a jo helyre

* prisma file irkalasa

* HomePage, routing, RegistrationPage update

* schema migartion and crud

* Cors in backend

* createUserDTO

* fetch path update

* CORS update, GreetingsPage, Navbar, fetch path update

* db schema changes

* HomePage, AfteLogin page update

* sto-s

* javitas

* ureate uset dto update

* update-user-dto update

* merge-hez

* sign in, sign up methods

* Navbar, AfterLogin, Reporting periods, Home page

* hibajavitas

* compare problem fixing

* CurrentJobs, Login update

* user controllerben login fv

* ugyeskedes

* everything works

---------

Co-authored-by: Mikola Bálint István <[email protected]>
Co-authored-by: Trisztán Piller <[email protected]>
  • Loading branch information
3 people authored Sep 9, 2024
1 parent 31c9a83 commit 666842b
Show file tree
Hide file tree
Showing 44 changed files with 12,691 additions and 840 deletions.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@nestjs/schematics": "^10.1.1",
"@swc/cli": "^0.3.12",
"@swc/core": "^1.5.0",
"@types/bcrypt": "^5.0.2",
"@types/express": "^4.17.21",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.1",
Expand Down
18 changes: 18 additions & 0 deletions apps/backend/prisma/migrations/20240706165250_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Warnings:
- The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
- The `id` column on the `User` table would be dropped and recreated. This will lead to data loss if there is data in the column.
- A unique constraint covering the columns `[password]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `password` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" DROP CONSTRAINT "User_pkey",
ADD COLUMN "password" TEXT NOT NULL,
DROP COLUMN "id",
ADD COLUMN "id" SERIAL NOT NULL,
ADD CONSTRAINT "User_pkey" PRIMARY KEY ("id");

-- CreateIndex
CREATE UNIQUE INDEX "User_password_key" ON "User"("password");
16 changes: 16 additions & 0 deletions apps/backend/prisma/migrations/20240714182617_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:
- A unique constraint covering the columns `[confirmPassword]` on the table `User` will be added. If there are existing duplicate values, this will fail.
- Added the required column `confirmPassword` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `firstname` to the `User` table without a default value. This is not possible if the table is not empty.
- Added the required column `lastname` to the `User` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "User" ADD COLUMN "confirmPassword" TEXT NOT NULL,
ADD COLUMN "firstname" TEXT NOT NULL,
ADD COLUMN "lastname" TEXT NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "User_confirmPassword_key" ON "User"("confirmPassword");
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- You are about to drop the column `confirmPassword` on the `User` table. All the data in the column will be lost.
*/
-- DropIndex
DROP INDEX "User_confirmPassword_key";

-- DropIndex
DROP INDEX "User_password_key";

-- AlterTable
ALTER TABLE "User" DROP COLUMN "confirmPassword";
8 changes: 5 additions & 3 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ datasource db {
}

model User {
id String @id @default(cuid())
// authSchId String @unique
email String @unique
id Int @id @default(autoincrement())
lastname String
firstname String
password String
email String @unique
}
3 changes: 2 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { PrismaModule } from 'nestjs-prisma';

import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';

@Module({
imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true })],
imports: [ConfigModule.forRoot(), PrismaModule.forRoot({ isGlobal: true }), UserModule],
controllers: [AppController],
providers: [AppService],
})
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

app.enableCors({
origin: ['http://localhost:3000', 'https://sprint.kir-dev.hu'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization'],
});

await app.listen(3001);
}
bootstrap();
1 change: 1 addition & 0 deletions apps/backend/src/sprint/dto/create-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateSprintDto {}
4 changes: 4 additions & 0 deletions apps/backend/src/sprint/dto/update-sprint.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';

Check failure on line 1 in apps/backend/src/sprint/dto/update-sprint.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
import { CreateSprintDto } from './create-sprint.dto';

export class UpdateSprintDto extends PartialType(CreateSprintDto) {}
1 change: 1 addition & 0 deletions apps/backend/src/sprint/entities/sprint.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Sprint {}
34 changes: 34 additions & 0 deletions apps/backend/src/sprint/sprint.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';

Check failure on line 1 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
import { SprintService } from './sprint.service';
import { CreateSprintDto } from './dto/create-sprint.dto';
import { UpdateSprintDto } from './dto/update-sprint.dto';

@Controller('sprint')
export class SprintController {
constructor(private readonly sprintService: SprintService) {}

@Post()
create(@Body() createSprintDto: CreateSprintDto) {
return this.sprintService.create(createSprintDto);
}

@Get()
findAll() {
return this.sprintService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.sprintService.findOne(+id);

Check failure on line 22 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateSprintDto: UpdateSprintDto) {
return this.sprintService.update(+id, updateSprintDto);

Check failure on line 27 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.sprintService.remove(+id);

Check failure on line 32 in apps/backend/src/sprint/sprint.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

use `Number(id)` instead
}
}
9 changes: 9 additions & 0 deletions apps/backend/src/sprint/sprint.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';

Check failure on line 1 in apps/backend/src/sprint/sprint.module.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Run autofix to sort these imports!
import { SprintService } from './sprint.service';
import { SprintController } from './sprint.controller';

@Module({
controllers: [SprintController],
providers: [SprintService],
})
export class SprintModule {}
27 changes: 27 additions & 0 deletions apps/backend/src/sprint/sprint.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';

import { CreateSprintDto } from './dto/create-sprint.dto';
import { UpdateSprintDto } from './dto/update-sprint.dto';

@Injectable()
export class SprintService {
create(createSprintDto: CreateSprintDto) {

Check failure on line 8 in apps/backend/src/sprint/sprint.service.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

'createSprintDto' is defined but never used
return 'This action adds a new sprint';
}

findAll() {
return `This action returns all sprint`;
}

findOne(id: number) {
return `This action returns a #${id} sprint`;
}

update(id: number, updateSprintDto: UpdateSprintDto) {

Check failure on line 20 in apps/backend/src/sprint/sprint.service.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

'updateSprintDto' is defined but never used
return `This action updates a #${id} sprint`;
}

remove(id: number) {
return `This action removes a #${id} sprint`;
}
}
45 changes: 45 additions & 0 deletions apps/backend/src/user/auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import * as bcrypt from 'bcrypt';
import { CreateUserDto } from 'src/user/dto/create-user.dto';
import { UserService } from 'src/user/user.service';

@Injectable()
export class AuthService {
saltOrRounds: number = 10;

constructor(private usersService: UserService) {}

async signIn(email, pass) {
const user = await this.usersService.findOneByEMail(email);

if (!user) {
throw new UnauthorizedException();
}

const isMatch = await bcrypt.compare(pass, user?.password);

if (!isMatch) {
throw new UnauthorizedException();
}

return user;
}

async signUp(payload: CreateUserDto) {
const hashPass = await bcrypt.hash(payload.password, this.saltOrRounds);

const user = {
surName: payload.surName,
foreName: payload.foreName,
password: hashPass,
email: payload.email,
};

await this.usersService.create({
email: user.email,
password: user.password,
firstname: user.foreName,
lastname: user.surName,
});
}
}
7 changes: 7 additions & 0 deletions apps/backend/src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class CreateUserDto {
surName: string;
foreName: string;
password: string;
email: string;
//TODO: user adatelemei
}
5 changes: 5 additions & 0 deletions apps/backend/src/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PartialType } from '@nestjs/mapped-types';

import { CreateUserDto } from './create-user.dto';

export class UpdateUserDto extends PartialType(CreateUserDto) {}
1 change: 1 addition & 0 deletions apps/backend/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class User {}
21 changes: 21 additions & 0 deletions apps/backend/src/user/user.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';

import { UserController } from './user.controller';
import { UserService } from './user.service';

describe('UserController', () => {
let controller: UserController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UserController],
providers: [UserService],
}).compile();

controller = module.get<UserController>(UserController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
49 changes: 49 additions & 0 deletions apps/backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { User } from '@prisma/client';
import { AuthService } from 'src/user/auth.service';

import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { UserService } from './user.service';

@Controller('user')
export class UserController {
constructor(
private readonly userService: UserService,
private readonly authService: AuthService
) {}

@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.authService.signUp(createUserDto);
}

@Post('login')
async logIn(@Body() loginDto: { email: string; password: string }): Promise<User & { isRegistered: boolean }> {
const user = await this.authService.signIn(loginDto.email, loginDto.password);
return {
...user,
isRegistered: user ? true : false,

Check failure on line 26 in apps/backend/src/user/user.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint Check

Unnecessary use of boolean literals in conditional expression
};
}

@Get()
findAll() {
return this.userService.findAll();
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.userService.findOne(Number(id));
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
return this.userService.update(Number(id), updateUserDto);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.userService.remove(Number(id));
}
}
11 changes: 11 additions & 0 deletions apps/backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';

import { AuthService } from './auth.service';
import { UserController } from './user.controller';
import { UserService } from './user.service';

@Module({
controllers: [UserController],
providers: [UserService, AuthService],
})
export class UserModule {}
19 changes: 19 additions & 0 deletions apps/backend/src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing';

import { UserService } from './user.service';

describe('UserService', () => {
let service: UserService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UserService],
}).compile();

service = module.get<UserService>(UserService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
33 changes: 33 additions & 0 deletions apps/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from '@nestjs/common';
import { Prisma, User } from '@prisma/client';
import { PrismaService } from 'nestjs-prisma';

@Injectable()
export class UserService {
constructor(private readonly prisma: PrismaService) {}

async create(data: Prisma.UserCreateInput): Promise<User> {
//Itt kell megoldani a jelszó hashelését (asszem)
return await this.prisma.user.create({ data });
}

async findAll(): Promise<User[]> {
return await this.prisma.user.findMany();
}

findOne(id: number): Promise<User> {
return this.prisma.user.findUnique({ where: { id } });
}

findOneByEMail(email: string) {
return this.prisma.user.findUnique({ where: { email } });
}

async update(id: number, data: Prisma.UserUpdateInput) {
return await this.prisma.user.update({ where: { id }, data });
}

async remove(id: number) {
return await this.prisma.user.delete({ where: { id } });
}
}
1 change: 1 addition & 0 deletions apps/frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ module.exports = {
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-console': 'off',
},
};
Loading

0 comments on commit 666842b

Please sign in to comment.