def post_login(): if current_user.is_authenticated: response = jsonify(errors={"detail": "You are already login as {}.".format(current_user.username)}) response.status_code = 400 return response data = json.loads(request.data)["data"] emailOrUsername = data["username"] if "@" in emailOrUsername: user = Users.query.filter(Users.email_insensitive == emailOrUsername).first() else: user = Users.query.filter(Users.username_insensitive == emailOrUsername).first() if not user or not user.check_password(data["password"]): response = jsonify(errors={"detail": "Invalid username or password."}) response.status_code = 400 return response else: login_user(user, remember=True) response = jsonify(data=read_user_serializer.dump(user).data) response.status_code = 200 return response
def get_user_by_id(id): users = Users.query.get(id) data, errors = read_user_serializer.dump(users) data['relationships'] = users.get_relationships() return jsonify(data=data)
def get_users(): users = Users.query.all() data, errors = read_user_serializer.dump(users, many=True) return jsonify(data=data)