def delete(self, username): user = UserModel.find_by_username(username) if user: user.delete_from_db() return {'message': "User deleted."} return {'message': 'User not found.'}, 404
def patch(self, username): data = ChangeLocation.parser.parse_args() user = UserModel.find_by_username(username) if user: user.location = data['location'] user.save_to_db() return {"message": "User successfully updated"}, 201
def patch(self, username): data = ChangePassword.parser.parse_args() user = UserModel.find_by_username(username) if user: user.password = data['password'] user.save_to_db() return {"message": "User successfully updated."}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']): return {"message": "A user with that username already exists"}, 400 user = UserModel(data['username'], sha256_crypt.hash(data['password']), data['email'], data['age'], data['location'], data['option_1'], data['option_2'], data['option_3'], data['option_4'], data['family'], data['gender']) user.save_to_db() return {"message": "User created successfully."}, 201
def patch(self, username): data = GetUser.parser.parse_args() user = UserModel.find_by_username(username) if user: user.family = data['family'] user.option_1 = data['option_1'] user.option_2 = data['option_2'] user.option_3 = data['option_3'] user.option_4 = data['option_4'] user.save_to_db() return {"message": "User successfully updated."}, 201
def post(self): data = self.parser.parse_args() user = UserModel.find_by_username(data['username']) orig = data['password'] if user and sha256_crypt.verify(orig, user.password): access_token = create_access_token(identity=user.id, fresh=True) refresh_token = create_refresh_token(user.id) return { 'message': 'User logged in', 'access_token': access_token, 'refresh_token': refresh_token }, 200 return {'message': 'Invalid credentials'}, 401
def get(self, username): user = UserModel.find_by_username(username) if user: return user.json() return {'message': 'User not found'}, 404