Exemplo n.º 1
0
def login():

    if request.method == 'GET':
        user_dict = request.authorization
    elif request.method == 'POST':
        user_dict = request.get_json()

    if user_dict is None or user_dict is '':
        return util.make_auth_challenge(msg='No credentials provided')

    try:
        username = user_dict['username']
    except:
        return util.make_json_error(msg='Missing username', status_code=401)
    try:
        password = user_dict['password']
    except:
        return util.make_json_error(msg='Missing password', status_code=401)

    if not User.authenticate(username, password):
        return util.make_json_error(msg='Wrong username and/or password',
                                    status_code=401)

    try:
        user = User.get_by_name(user_dict['username'])
        login_user(user)
        return util.make_json_success(msg='Success')
    except UserNotFoundError as e:
        return util.make_json_error(msg='User not found', status_code=401)
Exemplo n.º 2
0
def login():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    email = request.json.get('email', None)
    password = request.json.get('password', None)

    if not email or not password:
        return {"errors": ["Missing required parameters"]}, 400

    authenticated, user = User.authenticate(email, password)
    print(authenticated)
    print(user)
    if authenticated:
        login_user(user)
        return {"current_user_id": current_user.id, 'current_user_first_name': current_user.first_name}

    return {"errors": ["Invalid email or password"]}, 401
Exemplo n.º 3
0
def load_user_request(id):
    user_dict = request.authorization

    if user_dict is None or user_dict is '':
        return None

    try:
        username = user_dict['username']
    except:
        return None
    try:
        password = user_dict['password']
    except:
        return None

    if not User.authenticate(username, password):
        return None

    try:
        user = User.get_by_name(user_dict['username'])
        login_user(user)
        return user
    except UserNotFoundError as e:
        return None