From ed0d989915771fcdfbce9bba7296071afc6d481e Mon Sep 17 00:00:00 2001 From: Robin COuret Date: Fri, 6 Mar 2026 19:35:28 +0100 Subject: [PATCH] add register --- .../app/__pycache__/config.cpython-311.pyc | Bin 1507 -> 1559 bytes .../api/v1/__pycache__/auth.cpython-311.pyc | Bin 2875 -> 3085 bytes server/src/app/api/v1/auth.py | 8 ++- .../auth/__pycache__/security.cpython-311.pyc | Bin 2649 -> 3109 bytes server/src/app/auth/security.py | 13 +++- server/src/app/config.py | 1 + user-interface/src/router/index.ts | 12 +++- user-interface/src/services/apiAxios.ts | 6 +- .../src/views/{AuthView.vue => LoginView.vue} | 2 +- user-interface/src/views/RegisterView.vue | 63 ++++++++++++++++++ 10 files changed, 95 insertions(+), 10 deletions(-) rename user-interface/src/views/{AuthView.vue => LoginView.vue} (95%) create mode 100644 user-interface/src/views/RegisterView.vue diff --git a/server/src/app/__pycache__/config.cpython-311.pyc b/server/src/app/__pycache__/config.cpython-311.pyc index d2c593173d788d9019d2708598978a5e31110ee0..80056188224d3384bc5c244c3566eecde1b2fb86 100644 GIT binary patch delta 305 zcmaFNJ)MVlIWI340}vR9t}@jjluo*|Q0G3{a%1qupJ&SaL6 zkOs1fWPyaAra+Mxh$9XnBqq;gcGnPwNft?gSYWj>AQl^pU;#3U#U`_}ToCr+N30n%x;BB z#UBJu9_n}yPl8YnDLv>#@FMh}#|k;fLcxpR!9xo6;>kCyq2$oFJKya4-kUd%@9n4l z=XUg6Bw``3lGCU}=xWr)8>=~gqSjaF!^lIPQSGnA3vrAT#8l7pta-fNwWc7{fVFQ0 zo7ry?t6#4<@j2D&eyXkk-)KisAqinejNv>U5O?sTHYn4@3w!~m#1`JfM7&gnlA(Q% z@ygtCvBZ|^i(YZbXS`Ug)GEP;kIF8N9fg82_^e*XIT6vmjOT&&F@VdD z0rKHCI5Kbq;1@iP(2uV8mKx_HLe)1fKIB8h^TY!B{f70|fnrYHZ3#pp59d)+tRMS55JvQ0W zNVm0v0RBj5A!1s)1~LZ3Z+aRVB4wPTBT#25pBB@`rULDx%;Zfu>QLwPCAcqC@7Dc* z=OjhuSr8KN_Qxw*;U^@>8hdm9Yn-puy`?I<$S(mWe+d7*cxJvHnBGE%zT&La9FJoA X)zub)?ErQNQj$%aXek}^-hKZ7CAhEg delta 655 zcmZutJ!lj`6rS1L+ui#~jw59E_SQ4Ea>->4(L}HiG=1dVq)0QYv5|h|&k9VA9C+*jBE_2^h)6chk=b;goUl=a4bE2A zMZ!3XLydbF!D~pk575Z+S|rw3ys{Yy@wm(5Fwa#hJb)io6FfV(IirrVid4t4^Z?T) z7@-Cv43rv(Y$Vbg`uIGm6S#yx8cyZV@?p=Orv*5)uUIYAm%_6!ncs(>dH0T*yfk^Y zhwqfeW>+M9N=f=EOQepc;j~p=eqNDEkk$NSU+r|`UYjlO1=Q4(#4g+|ymoFJkpKLU cFAnAkw7Pxkh@d&4Upmoh1L_@Vr{t{CUmcQ`GXMYp diff --git a/server/src/app/api/v1/auth.py b/server/src/app/api/v1/auth.py index 4db286e..6565f9a 100644 --- a/server/src/app/api/v1/auth.py +++ b/server/src/app/api/v1/auth.py @@ -7,7 +7,7 @@ from src.app.models.user import User, UserCreate from src.app.data.user import create_user, get_user_by_username from src.app.auth.dependancies import get_current_user, authenticate_user -from src.app.auth.security import hash_password, create_access_token +from src.app.auth.security import hash_password, create_access_token, verify_beyond_user_limit from src.app.auth.schemas import Token router = APIRouter(prefix="/auth", tags=["auth"]) @@ -30,12 +30,16 @@ async def user(current_user: Annotated[str, Depends(get_current_user)]): @router.post("/register") async def create(user_data: UserCreate): + if(verify_beyond_user_limit()): + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="The user limit has been reached." + ) if get_user_by_username(user_data.username): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Username already registered" ) - hashed_password = hash_password(user_data.plain_password) user = User(username = user_data.username, hashed_password = hashed_password) created_user = create_user(user) diff --git a/server/src/app/auth/__pycache__/security.cpython-311.pyc b/server/src/app/auth/__pycache__/security.cpython-311.pyc index a2b187c6baff6d2985e706933b0315ac1a3fad5f..5d4a815e0be10d44b64333cfe00dcee34e16dde1 100644 GIT binary patch delta 1143 zcmZ`%&ube;6rR~#?XDzCvTXgbtt5unjW#7}(@=Z~y}2YLX(6_0nTxvCjBUj;T6K0+ z#~~meQgBNtv`YvH2?RoZ;bZ@R=90S!IXDXj(_3zV<`8=7o3T@BXos0^-}~m9w{PaX zSEYxw{Nr3MgJ4WgY;``hf63PdZ^65TD597nfeFUSHn<^7VhW2`+BbPh*u>Vh#U0@i zS2)BGX_D4lif2TYWVLPcA(10FktcakAO+1ie3%SFT$dNc2pQ2_nvaSS8I&+G5X(M- zG`3V`dXO^BunNt>8e-KYo91pH`tRckruf7Q)CO1vvoEki*I@#y=Wg;cEPc@%&T?h{Rg)!xaz9 z8aN>an3NU8=M>-S`C+&gNGd0OdujfR%dXloyTO`FYpWl%r4z5E2tE?ONS(r!U+pp6 zjK}S3xE|lMpItejWvgsG$@qLZkez5ngq|%mZ&TI|D3d0Lq^IDdf;@m{%8!+O8X$3c z{yGnQ8YgZ@>!GRX5OXefsu=yB9WQcirsf><=Gge#+eZ`enKC z!fkB3jh({iX0%r*ZT4jyPP;5boCTcw~ZM_GO-qe zfXk{PCjb(QcG{6_Dt|_Sy6{t^^Vd!FmwQ$e1KQ{8GkFg7RJ(NyKS@9E@+n-tKlKK|=YK)x^EXJ=6Q2M8 delta 746 zcmY*Wzi-n(81?yAY$r~d#vut|C~5?jxzLgdV25Oecye4e%C(_ny0?+X>u)2KPF@ARkOeR zCe>?=X^f;=Mkpc3^;FLcYA9}`W@b?TeZt4pqASedZMJkJczktgv-*iiJFKB}dulRY>VP$QcdE0N zDqW?%vk>CPB_4*430j&oB diff --git a/server/src/app/auth/security.py b/server/src/app/auth/security.py index 5cc3c27..a5cfa6b 100644 --- a/server/src/app/auth/security.py +++ b/server/src/app/auth/security.py @@ -1,5 +1,6 @@ from src.app.config import settings -from typing import Optional +from typing import Optional, Sequence +from src.app.models.user import User from datetime import timedelta, datetime, timezone from argon2 import PasswordHasher from argon2.exceptions import ( @@ -9,8 +10,7 @@ from argon2.exceptions import ( ) import jwt from jwt.exceptions import InvalidTokenError - - +from src.app.data.user import get_users password_hasher = PasswordHasher() @@ -37,4 +37,11 @@ def verify_token(token: str, token_type: str = "access") -> Optional[dict]: except InvalidTokenError: return None +def verify_beyond_user_limit() -> bool: + users: Sequence[User] = get_users() + if (len(users) > settings.USER_LIMIT): + return True + else: + return False + #def create_refresh_token(data: dict) -> str: \ No newline at end of file diff --git a/server/src/app/config.py b/server/src/app/config.py index 9595cb1..ebe0310 100644 --- a/server/src/app/config.py +++ b/server/src/app/config.py @@ -14,6 +14,7 @@ class Settings(BaseSettings): SECRET_KEY : str = Field('random_string', env='SECRET_KEY') ACCESS_TOKEN_EXPIRE_MINUTES: int = 240 ALGORITHM: str = "HS256" + USER_LIMIT: int = 10 class Config: env_file = ".env" diff --git a/user-interface/src/router/index.ts b/user-interface/src/router/index.ts index 0335622..852944f 100644 --- a/user-interface/src/router/index.ts +++ b/user-interface/src/router/index.ts @@ -1,7 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import { isAuthenticated } from '@/services/apiAxios' -const pagesWithoutGuard = ['login', 'app'] +const pagesWithoutGuard = ['login', 'app', 'register'] const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), @@ -22,14 +22,20 @@ const router = createRouter({ path: '/login', alias: '/login', name: 'login', - component: () => import('@/views/AuthView.vue'), + component: () => import('@/views/LoginView.vue'), + }, + { + path: '/register', + alias: '/register', + name: 'register', + component: () => import('@/views/RegisterView.vue'), } ], }) router.beforeEach(async (to, from) => { const isAuth = await isAuthenticated() - if (!isAuth && !pagesWithoutGuard.includes(to.name!.toString())) { + if (!isAuth && pagesWithoutGuard.includes(to.name!.toString())) { return { name: 'login' } } }) diff --git a/user-interface/src/services/apiAxios.ts b/user-interface/src/services/apiAxios.ts index f2eba36..828d996 100644 --- a/user-interface/src/services/apiAxios.ts +++ b/user-interface/src/services/apiAxios.ts @@ -14,7 +14,11 @@ api.interceptors.request.use((config) => { }) export const authAPI = { - register: (data: unknown) => api.post('/api/v1/auth/register', data), + register: (username: string, password: string) => + api.post( + '/api/v1/auth/register', + { "username":username, "plain_password":password } + ), login: (username: string, password: string) => api.post( '/api/v1/auth/login', diff --git a/user-interface/src/views/AuthView.vue b/user-interface/src/views/LoginView.vue similarity index 95% rename from user-interface/src/views/AuthView.vue rename to user-interface/src/views/LoginView.vue index 1dabd36..fa380e4 100644 --- a/user-interface/src/views/AuthView.vue +++ b/user-interface/src/views/LoginView.vue @@ -46,7 +46,7 @@ required > - Login + Login diff --git a/user-interface/src/views/RegisterView.vue b/user-interface/src/views/RegisterView.vue new file mode 100644 index 0000000..57c593f --- /dev/null +++ b/user-interface/src/views/RegisterView.vue @@ -0,0 +1,63 @@ + + + + + \ No newline at end of file