def test_user_password(self, testapp): """ Test password hashing and checking """ admin = User('admin', 'supersafepassword') assert admin.username == 'admin' assert admin.check_password('supersafepassword')
def test_user_password(self, testapp): """ Test password hashing and checking """ admin = User(username='******', password='******') assert admin.username == 'admin' assert admin.check_password('supersafepassword')
def init(): print("start to deploy now") from appname.models import User, Permission print("insert permission") Permission.insert_permissions() print("insert admin user") User.insert_admin()
def create_admin(email, password): admin = User() admin.email = email admin.password = encrypt_password(password) admin.active = True admin.confirmed_at = datetime.now(tzlocal()) db.session.add(admin) db.session.commit()
def test_user(self): admin = User('admin', 'supersafepassword') assert admin.username == 'admin' assert admin.check_password('supersafepassword') db.session.add(admin) db.session.commit()
def user(testapp): with testapp.app_context(): admin = User(username='******', password='******') db.session.add(admin) db.session.commit() db.session.refresh(admin) return admin
def setup(self): app = create_app('appname.settings.DevConfig', env='dev') self.app = app.test_client() db.app = app db.create_all() admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit()
def test_user_save(self): """ Test Saving the user model """ admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit() user = User.query.filter_by(username="******").first() assert user is not None
def login(): form = LoginForm() if form.validate_on_submit(): user = User.authenticate(username=form.username.data, password=form.password.data) if user and login_user(user): flash("Logged in successfully.", "success") return redirect(request.args.get("next") or url_for(".home")) else: flash("Login failed.", "danger") return render_template("login.html", form=form)
def change_password(): form = ChangePasswordForm() if request.method == "GET": return render_template("change_password.html", form=form) # Re-validate old password if form.validate_on_submit() and User.authenticate( current_user.username, form.current_password.data): current_user.update_password(form.password.data) current_user.save() flash("Password change successfully.", "success") return redirect(url_for(".home")) else: flash("Password change failed.", "danger") return render_template("change_password.html", form=form)
def testapp(request): app = create_app('appname.settings.TestConfig', env='dev') client = app.test_client() db.app = app db.create_all() if getattr(request.module, "create_user", True): admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit() def teardown(): db.session.remove() db.drop_all() request.addfinalizer(teardown) return client