소스 검색

fix register

ming 3 년 전
부모
커밋
e2b4284c49
2개의 변경된 파일11개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 0
      api/main.py
  2. 10 9
      api/util/user.py

+ 1 - 0
api/main.py

@@ -192,6 +192,7 @@ async def access_token(form_data: OAuth2PasswordRequestForm = Depends(), Authori
 
 @app.post("/register")
 async def register(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)+'"'))
     if user_obj != None:

+ 10 - 9
api/util/user.py

@@ -1,6 +1,5 @@
 class user_util():
-
-    def get_user_id(token):
+    def get_user_id(self, token):
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         credentials_exception = HTTPException(
             status_code=status.HTTP_401_UNAUTHORIZED,
@@ -21,14 +20,14 @@ class user_util():
         user_id = first(db.query('SELECT * FROM users where username="' + user.username+'"'))['id']
         return user_id
 
-    def check_user_exists(username):
+    def check_user_exists(self, username):
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         if int(next(iter(db.query('SELECT COUNT(*) FROM AI_anchor.users WHERE username = "'+username+'"')))['COUNT(*)']) > 0:
             return True
         else:
             return False
 
-    def get_user(username: str):
+    def get_user(self, username: str):
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         if not check_user_exists(username):  # if user don't exist
             return False
@@ -37,17 +36,17 @@ class user_util():
         user = models.User(**user_dict)
         return user
         
-    def user_register(user):
+    def user_register(self, user):
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         table = db['users']
         user.password = get_password_hash(user.password)
         table.insert(dict(user))
 
-    def get_password_hash(password):
+    def get_password_hash(self, password):
         return pwd_context.hash(password)
-    def verify_password(plain_password, hashed_password):
+    def verify_password(self, plain_password, hashed_password):
         return pwd_context.verify(plain_password, hashed_password)
-    def authenticate_user(username: str, password: str):
+    def authenticate_user(self, username: str, password: str):
         db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/AI_anchor?charset=utf8mb4')
         if not check_user_exists(username):  # if user don't exist
             return False
@@ -55,4 +54,6 @@ class user_util():
         user = models.User(**user_dict)
         if not verify_password(password, user.password):
             return False
-        return user
+        return user
+
+    def