Ejemplo n.º 1
0
def signup():
    error = None
    req = request.json
    request_email = req['email'].lower()
    password = req['password']
    entry = user.findSingleUser({'email': request_email})

    if entry is not None:
        error = 'Email is already in use'
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    try:
        invite_code = req['invite']
        if not invite.is_valid(invite_code):
            raise Exception("Invalid invite code")
        new_user = user.create_user(req)
        if (new_user is None):
            raise Exception()

        database_wrapper.save_entity(new_user)
        invite.consume(invite_code, new_user['_id'])

        # We need to log in the just-registered user.
        status = Auth.login(new_user, password)
        return jsonify(user.get_basic_info_from_users([new_user])[0])
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
def signup():
    error = None
    req = request.json
    request_email = req['email'].lower()
    password = req['password']
    entry = user.findSingleUser({'email': request_email})

    if entry is not None:
        error = 'Email is already in use'
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    try:
        invite_code = req['invite']
        if not invite.is_valid(invite_code):
            raise Exception("Invalid invite code")
        new_user = user.create_user(req)
        if (new_user is None):
            raise Exception()

        database_wrapper.save_entity(new_user)
        invite.consume(invite_code, new_user['_id'])

        # We need to log in the just-registered user.
        status = Auth.login(new_user, password)
        return jsonify(user.get_basic_info_from_users([new_user])[0])
    except Exception as e:
        return jsonify(error=str(e)), HTTP_400_BAD_REQUEST
Ejemplo n.º 3
0
def login():
    req = request.json
    try:
        email = req['email'].lower()
        password_hash = req['password']
    except:
        return '', HTTP_400_BAD_REQUEST

    user_object = user.findSingleUser({'email': email})
    error = Auth.login(user_object, password_hash)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(user_object)
def login():
    req = request.json
    try:
        email = req['email'].lower()
        password_hash = req['password']
    except:
        return '', HTTP_400_BAD_REQUEST

    user_object = user.findSingleUser({'email': email})
    error = Auth.login(user_object, password_hash)
    if error:
        return jsonify(LoggedIn=False, error=error), HTTP_400_BAD_REQUEST
    return user.get_basic_info_with_security(user_object)