Example #1
0
def signup():
    ''' signup user. '''
    email = g.formdata.get('email')
    name = g.formdata.get('name')
    password = g.formdata.get('password')

    # validate input
    if not email or not name or not password:
        raise FriendlyException.fec(error_code.ENP_REQUIRED)

    # generate a verify code.
    verify_code = ''.join(random.sample(string.letters, 6))
    user = User(email=email, name=name, password=password,
                verify_code=verify_code)
    try:
        user.save()
    except NotUniqueError:
        raise FriendlyException.fec(error_code.EMAIL_DUPLICATE, email)
    # should we send a email here?
    return user
Example #2
0
def signup():
    ''' signup user. '''
    email = g.formdata.get('email')
    name = g.formdata.get('name')
    password = g.formdata.get('password')

    # validate input
    if not email or not name or not password:
        raise FriendlyException.fec(error_code.ENP_REQUIRED)

    # generate a verify code.
    verify_code = ''.join(random.sample(string.letters, 6))
    user = User(email=email,
                name=name,
                password=password,
                verify_code=verify_code)
    try:
        user.save()
    except NotUniqueError:
        raise FriendlyException.fec(error_code.EMAIL_DUPLICATE, email)
    # should we send a email here?
    return user
Example #3
0
def do_login():

    next_url = g.formdata.get('next')
    email = g.formdata.get('email')
    password = g.formdata.get('password')
    remember = (g.formdata.get('remember', 'no') == 'yes')

    print '=============' + request.values.get('next')

    user = User.objects(email=email, password=password).first()
    if user is not None:
        if login_user(SessionUserMixin(user), remember=remember):
            user.last_login_on = datetime.datetime.now()
            user.save()
            return redirect(next_url or url_for('index'))

    raise FriendlyException.fec(error_code.LOGIN_FAILED)
Example #4
0
def do_login():
    
    next_url = g.formdata.get('next')
    email = g.formdata.get('email')
    password = g.formdata.get('password')
    remember = (g.formdata.get('remember', 'no') == 'yes')
    
    
    
    print '=============' + request.values.get('next')
    
    user = User.objects(email=email, password=password).first()
    if user is not None:
        if login_user(SessionUserMixin(user), remember=remember):
            user.last_login_on = datetime.datetime.now()
            user.save()
            return redirect(next_url or url_for('index'))

    raise FriendlyException.fec(error_code.LOGIN_FAILED)
Example #5
0
def load_user(user_id):
    return SessionUserMixin(User.objects(id=user_id).first())
Example #6
0
def load_user(user_id):
    return SessionUserMixin(User.objects(id=user_id).first())