コード例 #1
0
    def test_get_by_id(self):
        """Get user by ID."""
        user = User("foo", "*****@*****.**")
        user.save()

        retrieved = User.get_by_id(user.id)
        assert retrieved == user
コード例 #2
0
 def test_check_password(self):
     """Check password."""
     user = User.create(username="******",
                        email="*****@*****.**",
                        password="******")
     assert user.check_password("foobarbaz123") is True
     assert user.check_password("barfoobaz") is False
コード例 #3
0
ファイル: views.py プロジェクト: BlockScope/FAI-Airscore
def setup_admin():
    """Register 1st admin."""
    if current_app.config['admin_exists']:
        return render_template('404.html')
    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            active=True,
            access='admin',
        )
        flash("Thank you for registering. You can now log in.", "success")
        current_app.config['admin_exists'] = True
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/setup_admin.html", form=form)
コード例 #4
0
ファイル: views.py プロジェクト: BlockScope/FAI-Airscore
def register():
    """Register new scorekeeper."""
    # if we accept self registration then they become scorekeepers automatically
    if Defines.ADMIN_SELF_REG:
        access = 'scorekeeper'
    # otherwise they become pending admin approval
    else:
        access = 'pending'

    form = RegisterForm(request.form)
    if form.validate_on_submit():
        User.create(
            username=form.username.data,
            email=form.email.data,
            password=form.password.data,
            active=True,
            access=access,
        )
        flash("Thank you for registering. You can now log in.", "success")
        return redirect(url_for("public.home"))
    else:
        flash_errors(form)
    return render_template("public/register.html", form=form)
コード例 #5
0
ファイル: views.py プロジェクト: BlockScope/FAI-Airscore
def reset_password(token):
    form = LoginForm(request.form)
    if current_user.is_authenticated:
        return redirect(url_for('public.home'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    reset_form = ResetPasswordForm()
    if reset_form.validate_on_submit():
        user.set_password(reset_form.password.data)
        user.update()
        flash('Your password has been reset.')
        return redirect(url_for('public.home'))
    return render_template('public/reset_password.html', reset_form=reset_form, form=form)
コード例 #6
0
def create_app(config_object="airscore.settings"):
    """Create application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/.

    :param config_object: The configuration object to use.
    """
    app = Flask(__name__.split(".")[0])  # , debug=True)
    app.config.from_object(config_object)
    app.config.update(SESSION_COOKIE_SAMESITE='Lax')
    # app.config["REDIS_URL"] = app.config["REDIS_URL"]
    app.redis = Redis(host=app.config["REDIS_CONTAINER"], port=6379)
    app.task_queue = rq.Queue(app.config["RQ_QUEUE"], connection=app.redis)
    register_extensions(app)
    register_blueprints(app)
    register_errorhandlers(app)
    register_shellcontext(app)
    register_commands(app)
    configure_logger(app)
    with app.app_context():
        app.config['admin_exists'] = User.admin_exists()
    return app
コード例 #7
0
ファイル: views.py プロジェクト: BlockScope/FAI-Airscore
def load_user(user_id):
    """Load user by ID."""
    return User.get_by_id(int(user_id))
コード例 #8
0
 def test_password_is_nullable(self):
     """Test null password."""
     user = User(username="******", email="*****@*****.**")
     user.save()
     assert user.password is None
コード例 #9
0
 def test_created_at_defaults_to_datetime(self):
     """Test creation date."""
     user = User(username="******", email="*****@*****.**")
     user.save()
     assert bool(user.created_at)
     assert isinstance(user.created_at, dt.datetime)