コード例 #1
0
ファイル: views.py プロジェクト: codeforamerica/comport
def login():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            if form.user.is_admin():
                redirect_url = request.args.get("next") or url_for("admin.admin_dashboard")
                return redirect(redirect_url)
            else:
                if request.args.get("next"):
                    return redirect(request.args.get("next"))
                if form.user.first_department():
                    # direct the user to the first existing dataset page
                    redirect_path = form.user.first_department().get_first_dataset_path()
                    if redirect_path:
                        return redirect(url_for(redirect_path, short_name=form.user.first_department().short_name))
                    else:
                        flash("There are no datasets configured for this department.", 'alert alert-danger')
                        return redirect(url_for('public.home'))
                else:
                    flash("You are not registered in any department. Please contact support.", 'alert alert-danger')
                    return render_template("public/login.html", form=form, published=True)
        else:
            flash_errors(form)
    return render_template("public/login.html", form=form)
コード例 #2
0
ファイル: views.py プロジェクト: carolynjonesconway/comport
def login():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            if form.user.is_admin():
                redirect_url = request.args.get("next") or url_for(
                    "admin.admin_dashboard")
                return redirect(redirect_url)
            else:
                if request.args.get("next"):
                    return redirect(request.args.get("next"))
                if form.user.first_department():
                    return redirect(
                        url_for("department.department_dashboard",
                                department_id=form.user.first_department().id))
                else:
                    flash(
                        "You are not registered in any department. Please contact support.",
                        'alert alert-danger')
                    return render_template("public/login.html",
                                           form=form,
                                           published=True)
        else:
            flash_errors(form)
    return render_template("public/login.html", form=form, published=True)
コード例 #3
0
ファイル: views.py プロジェクト: BrandonBouier/comport
def login():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            if form.user.is_admin():
                redirect_url = request.args.get("next") or url_for("admin.admin_dashboard")
                return redirect(redirect_url)
            else:
                if request.args.get("next"):
                    return redirect(request.args.get("next"))
                if form.user.first_department():
                    # direct the user to the first existing dataset page
                    redirect_path = form.user.first_department().get_first_dataset_path()
                    if redirect_path:
                        return redirect(url_for(redirect_path, short_name=form.user.first_department().short_name))
                    else:
                        flash("There are no datasets configured for this department.", 'alert alert-danger')
                        return redirect(url_for('public.home'))
                else:
                    flash("You are not registered in any department. Please contact support.", 'alert alert-danger')
                    return render_template("public/login.html", form=form, published=True)
        else:
            flash_errors(form)
    return render_template("public/login.html", form=form)
コード例 #4
0
ファイル: test_user_forms.py プロジェクト: webmaven/comport
 def test_validate_inactive_user(self, user):
     user.active = False
     user.set_password('example')
     user.save()
     # Correct username and password, but user is not activated
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'User not activated' in form.username.errors
コード例 #5
0
 def test_validate_inactive_user(self, user):
     user.active = False
     user.set_password('example')
     user.save()
     # Correct username and password, but user is not activated
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'User not activated' in form.username.errors
コード例 #6
0
ファイル: views.py プロジェクト: webmaven/comport
def home():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == "POST":
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", "success")
            if form.user.is_admin():
                redirect_url = request.args.get("next") or url_for("admin.admin_dashboard")
                return redirect(redirect_url)
            else:

                redirect_url = request.args.get("next") or url_for(
                    "department.department_dashboard", department_id=form.user.department_id
                )
                return redirect(redirect_url)
        else:
            flash_errors(form)
    return render_template("public/home.html", form=form)
コード例 #7
0
def home():
    form = LoginForm(request.form)
    if current_user.is_admin():
        redirect_url = url_for("admin.admin_dashboard")
        return redirect(redirect_url)
    else:
        if current_user.first_department():
            return redirect(url_for("department.department_dashboard", department_id=current_user.first_department().id))
        else:
            flash("You are not registered in any department. Please contact support.", 'alert alert-danger')
            return render_template("public/login.html", form=form, published=True)
コード例 #8
0
ファイル: views.py プロジェクト: carolynjoneslee/comport
def login():
    form = LoginForm(request.form)
    # Handle logging in
    if request.method == 'POST':
        if form.validate_on_submit():
            login_user(form.user)
            flash("You are logged in.", 'success')
            if form.user.is_admin():
                redirect_url = request.args.get("next") or url_for("admin.admin_dashboard")
                return redirect(redirect_url)
            else:
                if request.args.get("next"):
                    return redirect(request.args.get("next"))
                if form.user.first_department():
                    return redirect(url_for("department.department_dashboard", department_id=form.user.first_department().id))
                else:
                    flash("You are not registered in any department. Please contact support.", 'alert alert-danger')
                    return render_template("public/login.html", form=form, published=True)
        else:
            flash_errors(form)
    return render_template("public/login.html", form=form, published=True)
コード例 #9
0
ファイル: views.py プロジェクト: carolynjonesconway/comport
def about():
    form = LoginForm(request.form)
    return render_template("public/about.html", form=form)
コード例 #10
0
ファイル: test_user_forms.py プロジェクト: webmaven/comport
 def test_validate_invalid_password(self, user):
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'Invalid password' in form.password.errors
コード例 #11
0
ファイル: test_user_forms.py プロジェクト: webmaven/comport
 def test_validate_unknown_username(self, db):
     form = LoginForm(username='******', password='******')
     assert form.validate() is False
     assert 'Unknown username' in form.username.errors
     assert form.user is None
コード例 #12
0
ファイル: test_user_forms.py プロジェクト: webmaven/comport
 def test_validate_success(self, user):
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is True
     assert form.user == user
コード例 #13
0
 def test_validate_invalid_password(self, user):
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is False
     assert 'Invalid password' in form.password.errors
コード例 #14
0
 def test_validate_unknown_username(self, db):
     form = LoginForm(username='******', password='******')
     assert form.validate() is False
     assert 'Unknown username' in form.username.errors
     assert form.user is None
コード例 #15
0
 def test_validate_success(self, user):
     user.set_password('example')
     user.save()
     form = LoginForm(username=user.username, password='******')
     assert form.validate() is True
     assert form.user == user