コード例 #1
0
ファイル: views.py プロジェクト: vegeclic/django-regularcom
def login(request):
    response = auth_views_login(request, extra_context={'section': 'login'}, authentication_form=forms.AccountAuthenticationForm)
    if request.method == 'POST':
        if 'context_data' in dir(response):
            form = response.context_data.get('form')
            if form:
                cv.messages_from_form(request, form)
                return response
        messages.success(request, _("You're logged in."))
    return response
コード例 #2
0
ファイル: user.py プロジェクト: stjordanis/vgg_frontend
 def login(self, request):
     """ Customized login page to be able to add extra content """
     home_location = settings.SITE_PREFIX + '/'
     if 'HTTP_X_FORWARDED_HOST' in request.META:
         home_location = 'http://' + request.META['HTTP_X_FORWARDED_HOST'] + home_location
     next_page = request.GET.get('next', None)
     context = {
     'NEXT': next_page,
     'SITE_PREFIX': settings.SITE_PREFIX,
     'HOME_LOCATION': home_location,
     }
     return auth_views_login(request, template_name='login.html', extra_context=context)
コード例 #3
0
def login(request, authentication_form=AuthenticationForm,
          *args, **kwargs):
    """
    Handles the login action.
    """
    json_response = lambda data: HttpResponse(json.dumps(data), mimetype='application/json')
    response_data = {'success':True}

    accept = request.META.get('HTTP_ACCEPT')
    if bool(accept) and 'application/json' in accept:

        if request.method == 'POST':

            form = authentication_form(data=request.POST)

            if form.is_valid():

                auth_login(request, form.get_user())

                if request.session.test_cookie_worked():
                    request.session.delete_test_cookie()

            else:

                response_data['success'] = False

                if bool(form.errors):
                    response_data['errors'] = form.errors

            return json_response(response_data)
        else:

            response_data['success'] = False
            response_data['errors'] = [u'Only the POST method is supported for this endpoint.']
            return json_response(response_data)

    return auth_views_login(request, *args, **kwargs)
コード例 #4
0
def login(*args, **kwargs):
    """Handles login and keeps category drop down with the page"""
    categories = Category.objects.all()
    extra_context = {'categories': categories}
    return auth_views_login(*args, extra_context=extra_context, **kwargs)
コード例 #5
0
def login(request,
          template_name='registration/login.html',
          authentication_form=AuthenticationFormWithInactiveUsersOkay,
          extra_context=None):

    # TODO: maybe to add expected user role (based on url) to extra_context
    response = auth_views_login(request,
                                authentication_form=authentication_form,
                                extra_context=extra_context)
    user = request.user

    if user.is_authenticated():
        # custom extra checking

        # TODO: temp temp temp
        # TODO: discuss "confirmation" feature
        # it should be deeply refactored in the first place
        # we need to (also) use "is_active" user flag for that stuff

        is_client = user.is_client
        is_advisor = user.is_advisor
        is_representative = user.is_authorised_representative
        # Geolocation restriction, configurable per account - set city to restrict
        if not user.is_superuser:
            city_lock = None
            if is_client:
                if user.client.geolocation_lock:
                    city_lock = user.client.geolocation_lock
            elif is_advisor:
                if user.advisor.geolocation_lock:
                    city_lock = user.advisor.geolocation_lock
            elif is_representative:
                if user.authorised_representative.geolocation_lock:
                    city_lock = user.authorised_representative.geolocation_lock

            if city_lock is not None and city_lock is not '':
                if not check_ip_city(request, city_lock) and (
                        ENVIRONMENT == 'demo' or ENVIRONMENT == 'production'):
                    messages.error(
                        request,
                        'Sorry, the BetaSmartz demo is only available to the %s area on this account.'
                        % city_lock)
                    form = authentication_form(request)
                    context = {'form': form}
                    return TemplateResponse(request, template_name, context)

        confirmed_client = is_client and user.client.is_confirmed
        confirmed_advisor = is_advisor and user.advisor.is_confirmed
        confirmed_representative = is_representative and user.authorised_representative.is_confirmed
        is_confirmed = confirmed_client or confirmed_advisor or confirmed_representative

        if not is_confirmed:
            # check if user is in the middle of onboarding
            if hasattr(user, 'invitation'):
                if user.invitation.status == 2 or user.invitation.status == 3:
                    # redirect to client onboarding
                    return redirect('/client/onboarding/' +
                                    user.invitation.invite_key)
            messages.error(request, 'Your account has not been confirmed yet.')
            form = authentication_form(request)
            context = {'form': form}

            return TemplateResponse(request, template_name, context)

        # custom redirect
        redirect_to = request.GET.get(
            'next',
            reverse_lazy('client:page', args=(user.client.id, ))
            if is_client else reverse_lazy('advisor:overview') if is_advisor
            else reverse_lazy('firm:overview') if is_representative else None)

        if redirect_to:
            response = HttpResponseRedirect(redirect_to)

    return response