def login(request): if request.method == "POST": form = forms.Login(request.POST) if form.is_valid(): email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') user = authenticate(username=email, password=password) if user is not None: login_auth(request, user) return redirect(request.GET.get('next', reverse('index'))) else: messages.error(request, "Bad email or password.") else: form = forms.Login() return render(request, "login.html", {'form': form})
def root(n=None): """ the index and login view """ b = None form = forms.Login(session.get('lang')) if n is not None and n == 'a': n = True elif n is not None and n == 'b': b = True elif n is None: n = False else: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) if data.User.query.first() is None: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) # Check if default password and account dpass = False if data.User.query.filter_by(id=1).first().verify_password('admin'): dpass = True if form.validate_on_submit(): if current_user.is_authenticated: flash('Error: wrong entry, something went wrong', 'danger') return redirect(url_for('core.root')) user = data.User.query.filter_by(name=form.name.data).first() if user is not None: if user.verify_password(form.password.data): if form.rm.data: login_user(user, remember=True) else: login_user(user) flash("Notice: logged-in and all good", 'info') if b: s = str(session.get('next_url', '/')) session['next_url'] = None return redirect(s) else: if is_operator(): return redirect( url_for( 'manage_app.offices', o_id=data.Operators.query.filter_by(id=current_user.id).first().office_id )) else: return redirect(url_for('manage_app.manage')) flash( "Error: wrong user name or password", 'danger') return redirect(url_for("core.root", n='a')) flash( "Error: wrong user name or password", 'danger') return redirect(url_for("core.root", n='a')) return render_template("index.html", operators=data.Operators.query, page_title="Free Queue Manager", form=form, n=n, dpass=dpass)
def login(): login_form = forms.Login() if login_form.validate_on_submit(): username = login_form.username.data password = login_form.password.data return render_template("login.j2", title="Login", form=login_form, subject_name=app.config['SUBJECT_NAME'])
def root(n=None): b = None form = forms.Login(session.get('lang')) if n is not None and n == 'a': n = True elif n is not None and n == 'b': b = True elif n is None: n = False else: flash(get_lang(4), "danger") return redirect(url_for('core.root')) if data.User.query.first() is None: flash(get_lang(4), "danger") return redirect(url_for('core.root')) # Check if default password and account dpass = False if data.User.query.filter_by(id=1).first().verify_password('admin'): dpass = True if form.validate_on_submit(): if current_user.is_authenticated: flash(get_lang(4), "danger") return redirect(url_for('core.root')) user = data.User.query.filter_by(name=form.name.data).first() if user is not None: if user.verify_password(form.password.data): if form.rm.data: login_user(user, remember=True) else: login_user(user) flash(get_lang(16), "info") if b: s = str(session.get('next_url', '/')) session['next_url'] = None return redirect(s) else: if current_user.role_id == 3: return redirect( url_for('manage_app.offices', o_id=data.Operators.query.filter_by( id=current_user.id).first().office_id)) else: return redirect(url_for('manage_app.manage')) flash(get_lang(17), "danger") return redirect(url_for("core.root", n='a')) flash(get_lang(17), "danger") return redirect(url_for("core.root", n='a')) return render_template("index.html", operators=data.Operators.query, ptitle="Free Queue Manager", form=form, n=n, dpass=dpass)
def login(request): if request.method == "POST": form = forms.Login(request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user is not None: login_auth(request, user) return redirect(request.POST.get('next', reverse('home'))) else: messages.error(request, "Bad username or password.") else: form = forms.Login() if request.GET.get('modal') == '1': base = 'modalForm.html' else: base = 'form.html' return render(request, "login.html", {'form': form, 'base': base})
def root(n=None): ''' welcome view and login. ''' form = forms.Login(session.get('lang')) has_default_password = data.User.has_default_password() wrong_credentials = n == 'a' should_redirect = n == 'b' def logged_in_all_good(): destination = url_for('manage_app.manage') if is_operator(): destination = url_for('manage_app.offices', o_id=data.Operators.get( current_user.id).office_id) elif should_redirect: destination = f'{session.get("next_url", "/")}' session['next_url'] = None flash('Notice: logged-in and all good', 'info') return redirect(destination) if form.validate_on_submit(): if current_user.is_authenticated: return logged_in_all_good() user = data.User.query.filter_by(name=form.name.data).first() if not user or not user.verify_password(form.password.data): flash('Error: wrong user name or password', 'danger') return redirect(url_for('core.root', n='a')) login_user(user, remember=bool(form.rm.data)) return logged_in_all_good() return render_template('index.html', operators=data.Operators.query, page_title='Free Queue Manager', form=form, n=wrong_credentials, dpass=has_default_password)
def login(): if current_user.is_authenticated: return redirect(url_for("dashboard.index")) form = forms.Login() if form.validate_on_submit(): username = form.username.data password = form.password.data error = None user = models.User.query.filter_by(username=username).first() if user is None or not user.check_password(password): error = "Invalid username or password." if error is None: login_user(user) return redirect(url_for("dashboard.index")) flash(error, "danger") return render_template("auth/login.html", form=form)