Ejemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(ProjectSearchResultsView,
                        self).get_context_data(**kwargs)
        project_list = super(ProjectSearchResultsView, self).get_queryset()
        search_words = self.request.GET.get('q')
        result_project = self.find_projects(search_words, project_list)

        if len(result_project) == 0:
            context['object_list'] = result_project
            context['is_paginated'] = False
            context['display_login_form'] = True
            context['form'] = LoginForm()
            context['search_words'] = search_words
            return context

        #use the title of the project like url parameter for the detail page.
        for project in result_project:
            project.url_detail = project.title.replace(" ", "_")
            project.partial_username = project.user.username.split("@")[0]

        paginator = Paginator(result_project, self.paginate_by)
        page = self.request.GET.get('page')
        try:
            project_page = paginator.page(page)
        except PageNotAnInteger:
            project_page = paginator.page(1)
        except EmptyPage:
            project_page = paginator.page(paginator.num_pages)

        context['object_list'] = result_project
        context['display_login_form'] = True
        context['form'] = LoginForm()
        context['search_words'] = search_words
        return context
Ejemplo n.º 2
0
def login(request):
    if request.method == 'POST':
        form = LoginForm(data=request.POST)
        if form.is_valid():
            auth.login(request, form.get_user())
            return HttpResponseRedirect(reverse('main:index'))
    else:
        form = LoginForm

    context = {
        'page_title': 'Авторизация',
        'form': form,

    }
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 3
0
def login(request):
    # form = AuthenticationForm()
    form = LoginForm()

    context = {
        'page_title': 'авторизация',
        'form': form,
    }
    return render(request, 'authapp/login.html', context)
Ejemplo n.º 4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))

    loginForm = LoginForm()

    if loginForm.validate_on_submit():
        user = User.query.filter_by(username=loginForm.username.data).first()
        if user is None or not user.check_password(loginForm.password.data):
            flash('Invalid username or password')
            return redirect(url_for('login'))
        login_user(user, remember=loginForm.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)

    return render_template('login.html', title='Sign In', form=loginForm)
Ejemplo n.º 5
0
def login_view(request):
    mensaje = ""
    if request.user.is_authenticated() :
        return  HttpResponseRedirect('/')
    else:
        if request.POST :
            form = LoginForm(request.POST)
            if form.is_valid():
			    usuario = form.cleaned_data['usuario']
			    password = form.cleaned_data['password']
			    usuariov = authenticate(username=usuario, password=password)
			    if usuariov is not None and usuariov.is_active:
			        login(request, usuariov)
			        return HttpResponseRedirect('/')
			    else:
			        mensaje ="Usuario y/o Contrasena incorrecta"
        form = LoginForm()
        ctx = {'form':form, 'mensaje':mensaje}
        return render_to_response('authapp/login.html', ctx, RequestContext(request))
Ejemplo n.º 6
0
def login(request):
    title = 'Все товары | Войдите'
    next_page = request.GET.get('next', None)

    if request.user and request.user.is_active:
        return HttpResponseRedirect(reverse('index'))

    login_form = LoginForm(data=request.POST or None)
    if login_form.is_valid():
        user = auth.authenticate(username=request.POST.get('username', None),
                                 password=request.POST.get('password', None))
        if user and user.is_active:
            auth.login(request, user)
        if request.POST.get('next_page', None) is not None:
            return HttpResponseRedirect(request.POST.get('next_page'))
        return HttpResponseRedirect(reverse('index'))

    return render(request, 'authapp/login.html', {
        'title': title,
        'login_form': login_form,
        'next_page': next_page
    })