|
|
@@ -189,9 +189,9 @@ async def access_token(form_data: OAuth2PasswordRequestForm = Depends(), Authori
|
|
|
)
|
|
|
return {"access_token": access_token, "token_type": "bearer"}
|
|
|
|
|
|
-
|
|
|
-@app.post("/register")
|
|
|
-async def register(request: Request):
|
|
|
+#前後端分離完全實現後拔除
|
|
|
+@app.post("/register_old")
|
|
|
+async def register_old(request: Request):
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
user = models.User(**await request.form())
|
|
|
user_obj = first(db.query('SELECT * FROM users where username ="'+str(user.username)+'"'))
|
|
|
@@ -201,6 +201,19 @@ async def register(request: Request):
|
|
|
else:
|
|
|
return {'msg':user.username+'重複,請更改'}
|
|
|
|
|
|
+@app.post("/register")
|
|
|
+async def register(request: models.register_req):
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
|
|
|
+ user = models.User(**await request.form())
|
|
|
+ user_obj = first(db.query('SELECT * FROM users where username ="'+str(user.username)+'"'))
|
|
|
+ if user_obj == None:
|
|
|
+ if user_register(user):
|
|
|
+ return {'msg':'ok'}
|
|
|
+ else:
|
|
|
+ return {'msg': '內部錯誤'}
|
|
|
+ else:
|
|
|
+ return {'msg':user.username+':使用者名稱重複,請更改'}
|
|
|
+
|
|
|
|
|
|
@app.get('/logout')
|
|
|
def logout(request: Request, Authorize: AuthJWT = Depends()):
|
|
|
@@ -430,6 +443,7 @@ def user_register(user):
|
|
|
table = db['users']
|
|
|
user.password = get_password_hash(user.password)
|
|
|
table.insert(dict(user))
|
|
|
+ return True
|
|
|
|
|
|
def get_password_hash(password):
|
|
|
return pwd_context.hash(password)
|