Commit adb1f3cd by Karsa Zoltán István

bugfixes

parent 9a6f23b7
from typing import Union
from pydantic import BaseModel, Field, EmailStr
from pydantic import BaseModel, EmailStr
class User(BaseModel):
username: str
......@@ -14,13 +14,13 @@ class Token(BaseModel):
token: str
class UserLoginSchema(BaseModel):
username: EmailStr = Field(...)
password: str = Field(...)
username: str
password: str
class Config:
schema_extra = {
"example": {
"email": "abdulazeez@x.com",
"username": "user",
"password": "weakpassword"
}
}
\ No newline at end of file
......@@ -8,8 +8,7 @@ from sredis.sredis import *
from sredis.models import *
import logging
from core.models import User, DataCenter, Token
from uuid import uuid4
from core.auth import signJWT, hash_pass
from core.auth import signJWT
from core.bearer import get_current_user
logging.config.fileConfig('logging.conf', disable_existing_loggers=False)
......@@ -26,12 +25,7 @@ add_datacenter("https://kappa3.fured.cloud.bme.hu")
@app.post("/user/signup", tags=["user"])
async def create_user(user: User = Body(...)):
user = PUser(
username=user.username,
email=user.email,
password=hash_pass(user.password)
)
user.save()
create_puser(user)
return signJWT(user.username)
@app.post("/user/login", tags=["user"])
......
import datetime
from typing import Optional
from redis_om import HashModel
from redis_om import HashModel, Field
from pydantic import EmailStr
class PUser(HashModel):
username: str
username: str = Field(index=True)
email: EmailStr
password: str
import redis
from core.auth import hash_pass
from core.models import UserLoginSchema
from .models import PUser
from passlib.hash import pbkdf2_sha256
from core.models import User
from core.auth import hash_pass
from fastapi import HTTPException
from redis_om import Migrator
r = redis.Redis(host='localhost', port=6379, db=0, decode_responses=True)
r.set("datacenters_cnt", 1)
......@@ -33,7 +36,18 @@ def get_datacenter_token(username: str, datacenter: str):
return str(r.hget(f"tokens:{username}", datacenter))
def check_user(data: UserLoginSchema):
user = PUser.find((PUser.username == data.username)).all()
user = PUser.find(PUser.username == data.username).all()
if pbkdf2_sha256.verify(data.password, user[0].password):
return user[0]
return False
\ No newline at end of file
return False
def create_puser(user: User):
s = PUser.find(PUser.username == 'karsa').all()
if s:
raise HTTPException(status_code=403, detail="User already exists")
user = PUser(
username=user.username,
email=user.email,
password=hash_pass(user.password)
)
user.save()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment