def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('home')) else: flash('Login Unsuccessful. Please check Email and password', 'danger') return render_template('login.html', title='Login', form=form)
def get(self, request, *args, **kwargs): form = LoginForm() grp = Group.objects.get(name='Generate Report') context = super(AdminView, self).get_context_data(**kwargs) context['form'] = form if grp not in request.user.groups.all(): context['login'] = False else: context['login'] = True return self.render_to_response(context)
def common_login(request): if request.user.is_authenticated: return redirect_user_to_index(request.user) context = get_error_context(request) context['form'] = LoginForm() return render(request, 'attendance/login.html', context)