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)
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)
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
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)
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)
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)
def about(): form = LoginForm(request.form) return render_template("public/about.html", form=form)
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
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
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