Beispiel #1
0
 def post(self):
     requested_data = request.get_json()
     user = UserModel.get_user_by_username(requested_data["username"])
     if user:
         if compare_digest(requested_data["password"], user.password):
             return {"msg": "Login successful"}, 200
         else:
             return {"msg": "Bad username or password"}, 400
     return {"msg": "Invalid username or password"}, 400
Beispiel #2
0
 def post(self):
     try:
         requested_data = request.get_json()
         if UserModel.get_user_by_username(requested_data["username"]):
             return {"msg": "Username already exists"}, 400
         if UserModel.get_user_by_email(requested_data["email"]):
             return {"msg": "Email already exists"}, 400
         user_schema = UserSchema()
         result: dict = user_schema.load(requested_data)
         UserModel.register_user(**result)
         return {"msg": "Registration successful"}, 201
     except ValidationError as err:
         return jsonify(err.messages, 400)