def post(self): data = UserLogin.parser.parse_args() email = data['email'] password = data['password'] user_object = UserModel(email, password) user = user_object.check_if_user_exists_by_email(email) if user == 0: return send_error('user does not exist', status.HTTP_400_BAD_REQUEST) else: user = user_object.verify_user(email, password) if user == 0: return send_error('either email/password is not correct', status.HTTP_401_UNAUTHORIZED) else: access_token = create_access_token(identity=user['user_id'], fresh=True) refresh_token = create_refresh_token(identity=user['user_id']) return send_success( 'success', { 'access_token': access_token, 'refresh_token': refresh_token, 'user': user }, status.HTTP_200_OK)
def post(self): data = UserRegister.parser.parse_args() email = data['email'] password = data['password'] user_object = UserModel(email, password) # check if user already exixsts new_user = user_object.check_if_user_exists_by_email(email) if new_user == 0: new_user = user_object.add_user(email, password) return send_success('user created', new_user, status.HTTP_201_CREATED) else: return send_error('user already exists', status.HTTP_409_CONFLICT)