Exemple #1
0
def signup():
    form = signupForm()
    if form.validate_on_submit():
        print('received')
        u = User(email=form.email.data,
                 password=User.encryptpassword(form.password.data))
        u.ct = datetime.utcnow()
        u.save()
        if login_user(u):
            track_activity(u, request.remote_addr)
            return redirect(url_for('user.welcome'))
    return render_template('signup.html', form=form)
Exemple #2
0
def set_new_pwd():
    form = set_newpwdForm(reset_token=request.args.get('reset_token'))
    if form.validate_on_submit():
        print('reset_token', request.form.get('reset_token'))
        token = request.form.get('reset_token')
        u = deserializer(token)
        if u:
            u.password = u.encryptpassword(form.new_pwd.data)
            u.save()
            login_user(u)
            track_activity(u, request.remote_addr)
            print('password has been reset')
            return redirect(url_for('user.settings'))
        else:
            return 'the token is expired or tamperd with'

    return render_template('set_new_pwd.html', form=form)
Exemple #3
0
def login():
    form = LoginForm(next=request.args.get('next'))
    if form.validate_on_submit():
        next = request.form.get('next')
        identity = form.identity.data
        password = form.password.data
        u = User.find_by_identity(identity)
        if u and u.passwordmatch:
            login_user(u, remember=False)
            track_activity(u, request.remote_addr)
            if next:
                return redirect(urljoin(request.host_url, next))
            else:
                return redirect(url_for('user.settings'))
        else:
            return '密码不正确'

    return render_template('login.html', form=form)