def register(): form = RegistrationForm() if form.validate_on_submit(): email = form.email.data username = form.username.data user = User(email=email, username=username) user.password = form.password.data company = Company() company.name = form.company.data db.session.add(user) db.session.add(company) company.set_company_owner(user) company.add_user(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm Your Account', 'auth/email/confirm', user=user, token=token) flash('A confirmation email has been sent to you by email.') return redirect(url_for('auth.login')) return render_template('auth/register.html', form=form)
def test_valid_confirmation_token(clean_db): u = User() u.password = '******' db.session.add(u) db.session.commit() token = u.generate_confirmation_token() assert u.confirm(token)