Esempio n. 1
0
def register_user():
    i = ctx.request.input(name='', email='', password='')
    name = i.name.strip()
    email = i.email.strip().lower()
    password = hashlib.md5(i.password).hexdigest()
    if not name:
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    # if not password or not _RE_PASSWORD.match(password):
    #     raise APIValueError('password')
    user = LocalAuth.find_first('where user_email=?', email)
    if user:
        raise APIError('register:failed', 'email', 'Email already in user.')
    user = Users(user_name=name)
    user.insert()
    # print user.user_id
    localauth = LocalAuth(user_id=user.user_id, user_email=email, user_password=password)
    localauth.insert()
    # make session cookie
    cookie = make_signed_cookie(user.user_id, localauth.user_password, None)
    ctx.response.set_cookie(__COOKIE_NAME, cookie)
    return user