コード例 #1
0
ファイル: test_models.py プロジェクト: 0xsKu/Flask-Foundation
    def test_user_password(self, testapp):
        """ Test password hashing and checking """

        admin = User('admin', 'supersafepassword')

        assert admin.username == 'admin'
        assert admin.check_password('supersafepassword')
コード例 #2
0
ファイル: test_models.py プロジェクト: tryer3000/flask-app
    def test_user_password(self, testapp):
        """ Test password hashing and checking """

        admin = User(username='******', password='******')

        assert admin.username == 'admin'
        assert admin.check_password('supersafepassword')
コード例 #3
0
ファイル: command.py プロジェクト: mozhemeng/flask-frame
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()
コード例 #4
0
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()
コード例 #5
0
    def test_user(self):
        admin = User('admin', 'supersafepassword')

        assert admin.username == 'admin'
        assert admin.check_password('supersafepassword')

        db.session.add(admin)
        db.session.commit()
コード例 #6
0
ファイル: test_login.py プロジェクト: tryer3000/flask-app
def user(testapp):
    with testapp.app_context():
        admin = User(username='******', password='******')
        db.session.add(admin)
        db.session.commit()
        db.session.refresh(admin)
        return admin
コード例 #7
0
ファイル: test_login.py プロジェクト: yasoob/Flask-Foundation
 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()
コード例 #8
0
    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
コード例 #9
0
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)
コード例 #10
0
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)
コード例 #11
0
ファイル: conftest.py プロジェクト: davidpmills/project-1
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