def setUpClass(cls): from tutorial.models.meta import Base from tutorial.models import ( User, Page, get_tm_session, ) from tutorial import main settings = { 'sqlalchemy.url': 'sqlite://', 'auth.secret': 'seekrit', } app = main({}, **settings) cls.testapp = webtest.TestApp(app) session_factory = app.registry['dbsession_factory'] cls.engine = session_factory.kw['bind'] Base.metadata.create_all(bind=cls.engine) with transaction.manager: dbsession = get_tm_session(session_factory, transaction.manager) editor = User(name='editor', role='editor') editor.set_password('editor') basic = User(name='basic', role='basic') basic.set_password('basic') page1 = Page(name='FrontPage', data='This is the front page') page1.creator = editor page2 = Page(name='BackPage', data='This is the back page') page2.creator = basic dbsession.add_all([basic, editor, page1, page2])
def setUpClass(cls): from tutorial.models.meta import Base from tutorial.models import ( User, Page, get_tm_session, ) from tutorial import main settings = { 'sqlalchemy.url': 'sqlite://', 'auth.secret': 'seekrit', } app = main({}, **settings) cls.testapp = TestApp(app) session_factory = app.registry['dbsession_factory'] cls.engine = session_factory.kw['bind'] Base.metadata.create_all(bind=cls.engine) with transaction.manager: dbsession = get_tm_session(session_factory, transaction.manager) editor = User(name='editor', role='editor') editor.set_password('editor') basic = User(name='basic', role='basic') basic.set_password('basic') page1 = Page(name='FrontPage', data='This is the front page') page1.creator = editor page2 = Page(name='BackPage', data='This is the back page') page2.creator = basic dbsession.add_all([basic, editor, page1, page2])
def register(): if current_user.is_authenticated: return redirect(url_for('main.index')) 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!')) return redirect(url_for('auth.login')) return render_template('auth/register.html', title=_('Register'), form=form)
def register(): isActive = 0 if current_user.is_authenticated: isActive = 1 success = 0 form = forms.SignUp() if request.method == 'POST': form = forms.SignUp(request.form) user = User(username=request.form['username'], email=request.form['email']) user.set_password(request.form['password']) db.session.add(user) db.session.commit() success = 1 title = "Registration" description = "This is the registration page" return render_template("register.html", title=title, description=description, form=form, success=success, isActive=isActive)
def makeUser(self, name, role, password='******'): from tutorial.models import User user = User(name=name, role=role) user.set_password(password) return user
def test_password_hashing(self): u = User(username='******') u.set_password('cat') self.assertFalse(u.check_password('dog')) self.assertTrue(u.check_password('cat'))