Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin'
Browse files Browse the repository at this point in the history
  • Loading branch information
a-boring-man committed Apr 19, 2023
2 parents 10f3cb9 + b46df1c commit ef27bb7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 40 deletions.
22 changes: 0 additions & 22 deletions back/nest_project/src/app.controller.spec.ts

This file was deleted.

2 changes: 0 additions & 2 deletions back/nest_project/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from './user/user.entity';
// import { SocketModule } from './socket/socket.module';
// import { AuthModule } from './auth/auth.module';
import { AuthModule } from './auth/auth.module';
import { GameUpdateCenterModule } from './game_update_center/game_update_center.module';
import { ChatModule } from './chat/chat.module';
Expand Down
7 changes: 3 additions & 4 deletions back/nest_project/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ export class UserController {
return this.userService.delete(data.id);
}
/**
* Get avatar
* Get avatar in chat
* @param data
* @returns
*/
@UseGuards(JwtAuthGuard)
@Get('getAvatar/:user')
async findAvatar(@Param('user') data: idDto): Promise<string> {
return await this.userService.getAvatar(data.id);
async findAvatar(@Param('user') id: string ): Promise<string> {
return await this.userService.getAvatar(id);
}

//update avatar picture
// @UseGuards(JwtAuthGuard)
// @Post('user/uploadAvatar')
Expand Down
8 changes: 4 additions & 4 deletions back/nest_project/src/user/user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsNotEmpty, IsString, IsEmail, IsUUID, MinLength, MaxLength, IsBoolean, IsNumber } from "class-validator";
import { Optional } from "@nestjs/common";
import { Match } from "src/match/Match";
import { IsNotEmpty, IsString, IsEmail, IsUUID, MinLength, IsBoolean, IsNumber } from "class-validator";
import { ChannelDto } from "src/chat/channel/channel.dto";
import { MessageChannelEntity } from "src/chat/messageChannel/messageChannel.entity";
import { MessagePrivateEntity } from "src/chat/messagePrivate/messagePrivate.entity";
Expand All @@ -13,7 +13,7 @@ export class UserDto {
@IsString() readonly id42: string;
@IsNotEmpty() @IsString() readonly login: string;
@IsNotEmpty() @IsEmail() readonly email: string;
@IsNotEmpty() @IsString() @MinLength(8) password: string; //@IsOptionnal
@IsNotEmpty() @IsString() @MinLength(8) password: string;
readonly channelsAsNormal: ChannelDto[];
readonly channelsAsOp: ChannelDto[];
readonly channelsAsGod: ChannelDto[];
Expand All @@ -37,12 +37,12 @@ export class UserDto {
export class SignUpDto {
@IsNotEmpty() @IsString() readonly login: string;
@IsNotEmpty() @IsEmail() readonly email: string;
@IsNotEmpty() @IsString() @MinLength(8) password: string;
@IsNotEmpty() @IsString() @MinLength(6) @MaxLength(10) password: string;
}

export class LoginDto {
@IsNotEmpty() @IsString() readonly login: string;
@IsNotEmpty() @IsString() @MinLength(8) password: string;
@IsNotEmpty() @IsString() @MinLength(6) @MaxLength(10) password: string;
}

export class SignUp42Dto {
Expand Down
18 changes: 10 additions & 8 deletions front/react_project/src/components/SignupPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "../styles/LoginPage.scss"
import React, { useContext, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import ReactDOMServer from 'react-dom/server';
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
Expand All @@ -11,14 +11,14 @@ import { generateRandomAvatarOptions } from "../assets/avatarGenerator";

const userSchema = yup.object().shape({
login: yup.string().required("Login is required") .min(3, "Login must be at least 3 characters"),
email: yup.string().required("Email is required"),
password: yup.string().required("Password is required") .min(8, "Password must be at least 8 characters"),
email: yup.string().required("Email is required").email("Invalid email format").matches(/(.fr|.com)$/, "Invalid email format"),
password: yup.string().required("Password is required") .min(6, "Password must be at least 6 characters") .max(10, "Password is 10 characters maximum"),
})


const SignupPage: React.FC = () => {
let navigate = useNavigate();
const [errorLogin, setError] = useState<boolean>(false);

const { register, handleSubmit, formState: { errors }} = useForm<SignUpForm>({
resolver: yupResolver(userSchema)
});
Expand All @@ -27,13 +27,15 @@ const SignupPage: React.FC = () => {
const avatar = generateRandomAvatarOptions();
const svgString = ReactDOMServer.renderToString(avatar);

setError(false);
data.avatarSvg = 'data:image/svg+xml,' + encodeURIComponent(svgString);
await accountService.isUniqueLogin(data.login)
.then(loginUnique => {
if(loginUnique.data == true) {
accountService.signUp(data)
.then(Response => {
accountService.saveToken(Response.data.access_token);
.then(res => {
console.log(res.data);
accountService.saveToken(res.data.access_token);
navigate("/");
})
.catch(error => {console.log(error);})
Expand Down Expand Up @@ -69,8 +71,8 @@ const SignupPage: React.FC = () => {
placeholder="Password"
/>
{errors.password && <p className='logError'>{errors.password.message}</p>}
<button className="form_element" type="submit">SIGN UP</button>
{errorLogin ? <p className="error">This login already exist, choose another one</p> : null}
<button className="form_element" type="submit">SIGN UP</button>
{errorLogin ? <p className="error">This login already exist</p> : null}
</form>
<NavLink to="/login">Already registered ? Log In</NavLink>
</div>
Expand Down

0 comments on commit ef27bb7

Please sign in to comment.