示例#1
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(_l('Congratulations! you can log with it now!'))
        return redirect(url_for('auth.login'))
    return render_template("auth/register.html", title='Sign up', form=form)
示例#2
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.dashboard'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(_('Congratulations, you are now a registered user!'), 'success')
        return redirect(url_for('auth.login'))

    return render_template('auth/register.html',
                           title='Registration',
                           form=form)
示例#3
0
 def test_password_hashing(self):
     user = User(username='******')
     user.set_password('cat')
     self.assertFalse(user.check_password('dog'))
     self.assertTrue(user.check_password('cat'))
示例#4
0
 def test_password_hashing(self):
     u = User(username='******')
     u.set_password('123456')
     self.assertFalse(u.check_password('dog'))
     self.assertTrue(u.check_password('123456'))