user confirm by mail
This commit is contained in:
parent
f2b7c63eee
commit
fef8bc92d4
@ -38,4 +38,23 @@ async def create_user(userSingle: users.UserCreate | None = None):
|
||||
current_user = users.User(username=userSingle.username, password=users_token.get_password_hash(userSingle.password), email=userSingle.email)
|
||||
user_repository.save(current_user)
|
||||
database.connect_redis.set(userSingle.username, key_hashed)
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "email has been sent"})
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "email has been sent"})
|
||||
|
||||
@router.get("/mail",tags=["mail"])
|
||||
async def confirm_user(key: str | None = None, username: str | None = None):
|
||||
if key is None or username is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Parameter key or/and username is empty"
|
||||
)
|
||||
user_repository = users.UserRepository(database=database.database)
|
||||
user = user_repository.find_one_by({"username": {'$eq': username}})
|
||||
key_hashed = database.connect_redis.get(username)
|
||||
if key_hashed != key:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Key is invalid"
|
||||
)
|
||||
user.confirmed = True
|
||||
user_repository.save(user)
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content={"message": "user account confirmed"})
|
Loading…
x
Reference in New Issue
Block a user