Exemplo n.º 1
0
def login():

    result = None
    email = request.form["email"]
    password = request.form["password"]
    json_response = {}

    if email and password:
        email = email.lower()
        user_mapper = UserDAO()
        user = user_mapper.validate(email, password)

        if user:
            #login user
            is_success = login_user(user)
            if is_success:
                json_response['error'] = False
                json_response['data'] = "User logged in"
            else:
                json_response['error'] = True
                json_response['data'] = "Check user/password"

        else:
            json_response['error'] = True
            json_response['data'] = "Check user/password"

    else:
        json_response['error'] = True
        json_response['data'] = "email/password not supplied"

    return jsonify(json_response)
Exemplo n.º 2
0
def test_create_user():
    user_mapper = UserDAO()
    user = User("*****@*****.**", "test123", "tester")

    result = user_mapper.add(user)

    print result
Exemplo n.º 3
0
def signup():

    email = request.form["email"]
    uname = request.form["name"]
    password = request.form["password"]
    repeat = request.form["repeat"]

    result = None
    json_response = {}

    try:
        if email and uname and password and repeat:

            email = email.lower()
            uname = uname.strip()

            user = User()
            user.name = uname
            user.email = email
            user.password = password

            user_mapper = UserDAO()
            user_id = user_mapper.add(user)
            print user_id, "new user"

        else:
            json_respons['error'] = True
            json_response['data'] = "params error"

    except Exception as e:
        print "error while signing up user"
        print e
        
        # 500 internal server error
        raise ExceptionResponse()

    if user_id:
        json_response['error'] = False
        json_response['data'] = "Success!"
    else:
        json_response['error'] = True
        json_response['data'] = "Error signing up user"

    return jsonify(json_response)
Exemplo n.º 4
0
def load_user(id):
    user = UserDAO()
    return user.get(id)