def post(self): data = Register.parser.parse_args() if User.find_by_username(data.username): return ResponseHandler.error('user exists', 400) user = User(**data) user.save() if user.id: return ResponseHandler.success('User Added', 200, data=user.json()) return ResponseHandler.error('user not added', 400)
def post(cls): data = cls.parser.parse_args() # no duplicate users with user names if User.find_by_username(data["username"]): return { "message": "A user with that username already exists..." }, 400 connection = sqlite3.connect(db_name) cursor = connection.cursor() insert_query = "INSERT INTO Users VALUES (NULL, ?, ?)" cursor.execute(insert_query, (data["username"], data["password"])) connection.commit() connection.close() return { "message": "User Created Succesfully" }, 201 # create response Code
def authenticate(username, password): user = User.find_by_username(username) if user and check_password_hash(user.password, password): return Auth.authenticatebyUser(user) return {'message': 'invalid credentials '}, 401