コード例 #1
0
 def authenticate_user(username: str, password: str, db: Session):
     user = DBUser.get_by_username(db, username)
     if not user:
         return False
     if not Auth.verify_password(password, user.password):
         return False
     return user
コード例 #2
0
async def register(request: Request, form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)):
    # 密码加密
    password = Auth.get_password_hash(form_data.password)

    db_user = DBUser.get_by_username(db, form_data.username)
    if db_user:
        return db_user

    db_user = DBUser(username=form_data.username, password=password)
    DBUser.add(db, db_user)

    request.session['test'] = "test"

    return db_user