当前位置: 首页>>代码示例>>Python>>正文


Python utils.handle_login函数代码示例

本文整理汇总了Python中users.utils.handle_login函数的典型用法代码示例。如果您正苦于以下问题:Python handle_login函数的具体用法?Python handle_login怎么用?Python handle_login使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了handle_login函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: login

def login(request, template):
    """Try to log the user in."""
    if request.method == 'GET' and not request.MOBILE:
        url = reverse('users.auth') + '?' + request.GET.urlencode()
        return HttpResponsePermanentRedirect(url)

    next_url = get_next_url(request) or reverse('home')
    form = handle_login(request)

    if request.user.is_authenticated():
        # Add a parameter so we know the user just logged in.
        # fpa =  "first page authed" or something.
        next_url = urlparams(next_url, fpa=1)
        res = HttpResponseRedirect(next_url)
        max_age = (None if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE
                        else settings.SESSION_COOKIE_AGE)
        res.set_cookie(settings.SESSION_EXISTS_COOKIE,
                       '1',
                       secure=False,
                       max_age=max_age)
        return res

    if request.MOBILE:
        return jingo.render(request, template, {
            'form': form,
        })

    return user_auth(request, login_form=form)
开发者ID:lonnen,项目名称:kitsune,代码行数:28,代码来源:views.py

示例2: login

def login(request, mobile=False):
    """Try to log the user in."""
    form = handle_login(request)
    
    next = clean_next_url(request)
    
    if mobile:
        next_url = next or reverse('mobile.home')
        
        if request.user.is_authenticated():
            profile = request.user.profile
            if not profile.login_mobile:
                profile.login_mobile = True
                profile.save()
                profile.trigger_multisparker_badge()
            return HttpResponseRedirect(next_url)

        return jingo.render(request, 'users/mobile/login.html',
                            {'form': form, 'next_url': next_url})
    else: # ajax login
        if request.method == 'POST' and request.is_ajax():
            if not form.is_valid():
                return {'status': 'error',
                        'errors': dict(form.errors.iteritems())}
            else:
                profile = request.user.profile
                if not profile.login_desktop:
                    profile.login_desktop = True
                    profile.save()
                    profile.trigger_multisparker_badge()
                
                return {'status': 'success',
                        'next': next or reverse('desktop.home')}

        return HttpResponseBadRequest()
开发者ID:mozilla,项目名称:spark,代码行数:35,代码来源:views.py

示例3: browserid_signin_html

def browserid_signin_html(request):
    next_url = _clean_next_url(request) or reverse('home')
    browserid_locales = constance.config.BROWSERID_LOCALES
    if request.locale.lower() not in browserid_locales.lower():
        raise Http404
    form = handle_login(request)
    return jingo.render(request, 'users/browserid_signin.html',
                        {'form': form, 'next_url': next_url})
开发者ID:kaiquewdev,项目名称:kuma,代码行数:8,代码来源:views.py

示例4: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request) or reverse('home')
    form = handle_login(request)

    if request.user.is_authenticated():
        return HttpResponseRedirect(next_url)

    return jingo.render(request, 'users/login.html',
                        {'form': form, 'next_url': next_url})
开发者ID:MechanisM,项目名称:kitsune,代码行数:10,代码来源:views.py

示例5: login

def login(request):
    """Try to log the user in."""
    next_url = get_next_url(request) or reverse('home')
    form = handle_login(request)

    if request.user.is_authenticated():
        res = HttpResponseRedirect(next_url)
        res.set_cookie(settings.SESSION_EXISTS_COOKIE, '1', secure=False)
        return res

    return jingo.render(request, 'users/login.html',
                        {'form': form, 'next_url': next_url})
开发者ID:lmorchard,项目名称:kitsune,代码行数:12,代码来源:views.py

示例6: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request) or reverse('home')
    form = handle_login(request)

    if request.user.is_authenticated():
        return _redirect_with_mindtouch_login(next_url,
            form.cleaned_data.get('username'),
            form.cleaned_data.get('password'))

    response = jingo.render(request, 'users/login.html',
                            {'form': form, 'next_url': next_url})
    response['x-frame-options'] = 'SAMEORIGIN'
    return response
开发者ID:pmclanahan,项目名称:kuma,代码行数:14,代码来源:views.py

示例7: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request)
    if request.method == 'GET' and request.user.is_authenticated():
        if next_url:
            return HttpResponseRedirect(next_url)
    else:
        next_url = _clean_next_url(request) or reverse('home')
    form = handle_login(request)

    if form.is_valid() and request.user.is_authenticated():
        next_url = next_url or reverse('home')
        return HttpResponseRedirect(next_url)

    return render(request, 'users/login.html',
                            {'form': form, 'next_url': next_url})
开发者ID:AprilMorone,项目名称:kuma,代码行数:16,代码来源:views.py

示例8: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request)
    if request.method == "GET" and request.user.is_authenticated():
        if next_url:
            return HttpResponseRedirect(next_url)
    else:
        next_url = _clean_next_url(request) or reverse("home")
    form = handle_login(request)

    if form.is_valid() and request.user.is_authenticated():
        next_url = next_url or reverse("home")
        return _redirect_with_mindtouch_login(
            next_url, form.cleaned_data.get("username"), form.cleaned_data.get("password")
        )

    return render(request, "users/login.html", {"form": form, "next_url": next_url})
开发者ID:hardfire,项目名称:kuma,代码行数:17,代码来源:views.py

示例9: login

def login(request):
    """Try to log the user in."""
    next_url = _clean_next_url(request)
    if request.method == 'GET' and request.user.is_authenticated():
        if next_url:
            return HttpResponseRedirect(next_url)
    else:
        next_url = _clean_next_url(request) or reverse('home')
    form = handle_login(request)

    if form.is_valid() and request.user.is_authenticated():
        next_url = next_url or reverse('home')
        return _redirect_with_mindtouch_login(next_url,
            form.cleaned_data.get('username'),
            form.cleaned_data.get('password'))

    return render(request, 'users/login.html',
                            {'form': form, 'next_url': next_url})
开发者ID:Web5design,项目名称:kuma,代码行数:18,代码来源:views.py

示例10: login

def login(request, template):
    """Try to log the user in."""
    if request.method == 'GET' and not request.MOBILE:
        url = reverse('users.auth') + '?' + request.GET.urlencode()
        return HttpResponsePermanentRedirect(url)

    next_url = get_next_url(request) or reverse('home')
    form = handle_login(request)

    if request.user.is_authenticated():
        res = HttpResponseRedirect(next_url)
        max_age = (None if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE
                        else settings.SESSION_COOKIE_AGE)
        res.set_cookie(settings.SESSION_EXISTS_COOKIE,
                       '1',
                       secure=False,
                       max_age=max_age)
        return res

    return user_auth(request, login_form=form)
开发者ID:victorneo,项目名称:kitsune,代码行数:20,代码来源:views.py

示例11: login

def login(request, mobile=False):
    """Try to log the user in."""
    form = handle_login(request)
    
    if mobile:
        next_url = _clean_next_url(request) or reverse('mobile.home')
        
        if request.user.is_authenticated():
            return HttpResponseRedirect(next_url)

        return jingo.render(request, 'users/mobile/login.html',
                            {'form': form, 'next_url': next_url})
    else: # ajax login
        if request.method == 'POST' and request.is_ajax():
            if not form.is_valid():
                return {'status': 'error',
                        'errors': dict(form.errors.iteritems())}
            else:
                return {'status': 'success',
                        'next': reverse('desktop.dashboard')}

        return HttpResponseBadRequest()
开发者ID:ryansnyder,项目名称:spark,代码行数:22,代码来源:views.py

示例12: aaq


#.........这里部分代码省略.........
                register_form = RegisterForm()
                return jingo.render(request, login_t,
                                    {'product': product, 'category': category,
                                     'title': search,
                                     'register_form': register_form,
                                     'login_form': login_form})
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
            # User is on the question details step
            statsd.incr('questions.aaq.details-form')
        else:
            form = None
            if search:
                # User is on the article and questions suggestions step
                statsd.incr('questions.aaq.suggestions')

        return jingo.render(request, template,
                            {'form': form,
                             'results': results,
                             'tried_search': tried_search,
                             'products': products,
                             'current_product': product,
                             'current_category': category,
                             'current_html': html,
                             'current_articles': articles,
                             'current_step': step,
                             'deadend': deadend,
                             'host': Site.objects.get_current().domain})

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get('login'):
            login_form = handle_login(request, only_active=False)
            statsd.incr('questions.user.login')
            register_form = RegisterForm()
        elif request.POST.get('register'):
            login_form = AuthenticationForm()
            email_template = 'questions/email/confirm_question.ltxt'
            email_subject = _('Please confirm your Firefox Help question')
            email_data = request.GET.get('search')
            register_form = handle_register(request, email_template,
                                            email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
                statsd.incr('questions.user.register')
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy('Request type not recognized.')
            return jingo.render(request, 'handlers/400.html',
                            {'message': message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL replacing the step parameter.
            # This is also required for the csrf middleware to set the auth'd
            # tokens appropriately.
            url = urlparams(request.get_full_path(), step='aaq-question')
            return HttpResponseRedirect(url)
        else:
            return jingo.render(request, login_t,
                                {'product': product, 'category': category,
                                 'title': request.POST.get('title'),
                                 'register_form': register_form,
                                 'login_form': login_form})
开发者ID:victorneo,项目名称:kitsune,代码行数:66,代码来源:views.py

示例13: new_question

def new_question(request, template=None):
    """Ask a new question."""

    product_key = request.GET.get("product")
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get("category")
    if product and category_key:
        category = product["categories"].get(category_key)
        if not category:
            raise Http404
        deadend = category.get("deadend", False)
        html = category.get("html")
        articles = category.get("articles")
    else:
        category = None
        deadend = product.get("deadend", False) if product else False
        html = product.get("html") if product else None
        articles = None
        if product:
            # User is on the select category step
            statsd.incr("questions.aaq.select-category")
        else:
            # User is on the select product step
            statsd.incr("questions.aaq.select-product")

    login_t = "questions/mobile/new_question_login.html" if request.MOBILE else "questions/new_question_login.html"
    if request.method == "GET":
        search = request.GET.get("search", "")
        if search:
            try:
                results = _search_suggestions(search, locale_or_default(request.locale), product.get("tags"))
            except SearchError:
                # Just quietly advance the user to the next step.
                results = []
            tried_search = True
        else:
            results = []
            tried_search = False
            if category:
                # User is on the "Ask This" step
                statsd.incr("questions.aaq.search-form")

        if request.GET.get("showform"):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                # User is on the login or register Step
                statsd.incr("questions.aaq.login-or-register")
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(
                    request,
                    login_t,
                    {
                        "product": product,
                        "category": category,
                        "title": search,
                        "register_form": register_form,
                        "login_form": login_form,
                    },
                )
            form = NewQuestionForm(product=product, category=category, initial={"title": search})
            # User is on the question details step
            statsd.incr("questions.aaq.details-form")
        else:
            form = None
            if search:
                # User is on the article and questions suggestions step
                statsd.incr("questions.aaq.suggestions")

        return jingo.render(
            request,
            template,
            {
                "form": form,
                "results": results,
                "tried_search": tried_search,
                "products": products,
                "current_product": product,
                "current_category": category,
                "current_html": html,
                "current_articles": articles,
                "deadend": deadend,
                "host": Site.objects.get_current().domain,
            },
        )

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get("login"):
            login_form = handle_login(request, only_active=False)
            statsd.incr("questions.user.login")
            register_form = RegisterForm()
        elif request.POST.get("register"):
            login_form = AuthenticationForm()
            email_template = "questions/email/confirm_question.ltxt"
            email_subject = _("Please confirm your Firefox Help question")
            email_data = request.GET.get("search")
            register_form = handle_register(request, email_template, email_subject, email_data)
#.........这里部分代码省略.........
开发者ID:fox2mike,项目名称:kitsune,代码行数:101,代码来源:views.py

示例14: new_question

def new_question(request, template=None):
    """Ask a new question."""

    product_key = request.GET.get('product')
    product = products.get(product_key)
    if product_key and not product:
        raise Http404
    category_key = request.GET.get('category')
    if product and category_key:
        category = product['categories'].get(category_key)
        if not category:
            raise Http404
        deadend = category.get('deadend', False)
        html = category.get('html')
        articles = category.get('articles')
    else:
        category = None
        deadend = product.get('deadend', False) if product else False
        html = product.get('html') if product else None
        articles = None

    login_t = ('questions/mobile/new_question_login.html' if request.MOBILE
               else 'questions/new_question_login.html')
    if request.method == 'GET':
        search = request.GET.get('search', '')
        if search:
            try:
                results = _search_suggestions(
                    search, locale_or_default(request.locale))
            except SearchError:
                # Just quietly advance the user to the next step.
                results = []
            tried_search = True
        else:
            results = []
            tried_search = False

        if request.GET.get('showform'):
            # Before we show the form, make sure the user is auth'd:
            if not request.user.is_authenticated():
                login_form = AuthenticationForm()
                register_form = RegisterForm()
                return jingo.render(request, login_t,
                                    {'product': product, 'category': category,
                                     'title': search,
                                     'register_form': register_form,
                                     'login_form': login_form})
            form = NewQuestionForm(product=product,
                                   category=category,
                                   initial={'title': search})
        else:
            form = None

        return jingo.render(request, template,
                            {'form': form,
                             'results': results,
                             'tried_search': tried_search,
                             'products': products,
                             'current_product': product,
                             'current_category': category,
                             'current_html': html,
                             'current_articles': articles,
                             'deadend': deadend,
                             'host': Site.objects.get_current().domain})

    # Handle the form post.
    if not request.user.is_authenticated():
        if request.POST.get('login'):
            login_form = handle_login(request, only_active=False)
            statsd.incr('questions.user.login')
            register_form = RegisterForm()
        elif request.POST.get('register'):
            login_form = AuthenticationForm()
            email_template = 'questions/email/confirm_question.ltxt'
            email_subject = _('Please confirm your Firefox Help question')
            email_data = request.GET.get('search')
            register_form = handle_register(request, email_template,
                                            email_subject, email_data)
            if register_form.is_valid():  # Now try to log in.
                user = auth.authenticate(username=request.POST.get('username'),
                                         password=request.POST.get('password'))
                auth.login(request, user)
                statsd.incr('questions.user.register')
        else:
            # L10n: This shouldn't happen unless people tamper with POST data.
            message = _lazy('Request type not recognized.')
            return jingo.render(request, 'handlers/400.html',
                            {'message': message}, status=400)
        if request.user.is_authenticated():
            # Redirect to GET the current URL.
            # This is required for the csrf middleware to set the auth'd tokens
            # appropriately.
            return HttpResponseRedirect(request.get_full_path())
        else:
            return jingo.render(request, login_t,
                                {'product': product, 'category': category,
                                 'title': request.POST.get('title'),
                                 'register_form': register_form,
                                 'login_form': login_form})

#.........这里部分代码省略.........
开发者ID:bowmasters,项目名称:kitsune,代码行数:101,代码来源:views.py

示例15: browserid_register

def browserid_register(request):
    """Handle user creation when assertion is valid, but no existing user"""
    redirect_to = request.session.get(SESSION_REDIRECT_TO,
        getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
    email = request.session.get(SESSION_VERIFIED_EMAIL, None)

    if not email:
        # This is pointless without a verified email.
        return HttpResponseRedirect(redirect_to)

    # Set up the initial forms
    register_form = BrowserIDRegisterForm()
    login_form = AuthenticationForm()

    if request.method == 'POST':

        # If the profile creation form was submitted...
        if 'register' == request.POST.get('action', None):
            register_form = BrowserIDRegisterForm(request.POST)
            if register_form.is_valid():
                try:
                    # If the registration form is valid, then create a new
                    # Django user, a new MindTouch user, and link the two
                    # together.
                    # TODO: This all belongs in model classes
                    username = register_form.cleaned_data['username']

                    user = User.objects.create(username=username, email=email)
                    user.set_unusable_password()
                    user.save()

                    profile = UserProfile.objects.create(user=user)
                    deki_user = DekiUserBackend.post_mindtouch_user(user)
                    profile.deki_user_id = deki_user.id
                    profile.save()

                    user.backend = 'django_browserid.auth.BrowserIDBackend'
                    auth.login(request, user)

                    # Bounce to the newly created profile page, since the user
                    # might want to review & edit.
                    redirect_to = request.session.get(SESSION_REDIRECT_TO,
                                                    profile.get_absolute_url())
                    return set_browserid_explained(
                        _redirect_with_mindtouch_login(redirect_to,
                                                       user.username))
                except MindTouchAPIError:
                    if user:
                        user.delete()
                    return jingo.render(request, '500.html',
                                        {'error_message': "We couldn't "
                                        "register a new account at this time. "
                                        "Please try again later."})

        else:
            # If login was valid, then set to the verified email
            login_form = handle_login(request)
            if login_form.is_valid():
                if request.user.is_authenticated():
                    # Change email to new verified email, for next time
                    user = request.user
                    user.email = email
                    user.save()
                    return _redirect_with_mindtouch_login(redirect_to,
                        login_form.cleaned_data.get('username'),
                        login_form.cleaned_data.get('password'))

    # HACK: Pretend the session was modified. Otherwise, the data disappears
    # for the next request.
    request.session.modified = True

    return jingo.render(request, 'users/browserid_register.html',
                        {'login_form': login_form,
                         'register_form': register_form})
开发者ID:kaiquewdev,项目名称:kuma,代码行数:74,代码来源:views.py


注:本文中的users.utils.handle_login函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。