示例#1
0
def login(request, template_name='im/login.html', extra_context=None):
    """
    Renders login page.

    **Arguments**

    ``template_name``
        A custom login template to use. This is optional; if not specified,
        this will default to ``im/login.html``.

    ``extra_context``
        An dictionary of variables to add to the template context.
    """

    extra_context = extra_context or {}

    third_party_token = request.GET.get('key', False)
    if third_party_token:
        messages.info(request, astakos_messages.AUTH_PROVIDER_LOGIN_TO_ADD)

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('landing'))

    return render_response(template_name,
                           login_form=LoginForm(request=request),
                           context_instance=get_context(
                               request, extra_context))
示例#2
0
文件: im.py 项目: vgerak/synnefo
def login(request, template_name='im/login.html', extra_context=None):
    """
    Renders login page.

    **Arguments**

    ``template_name``
        A custom login template to use. This is optional; if not specified,
        this will default to ``im/login.html``.

    ``extra_context``
        An dictionary of variables to add to the template context.
    """

    return handle_get_to_login_view(request, primary_provider=PRIMARY_PROVIDER,
                                    login_form=LoginForm(request),
                                    template_name=template_name,
                                    extra_context=extra_context)
示例#3
0
def login(request, on_failure='im/login.html'):
    """
    on_failure: the template name to render on login failure
    """
    if request.method == 'GET':
        return HttpResponseRedirect(reverse('login'))

    was_limited = getattr(request, 'limited', False)
    form = LoginForm(data=request.POST,
                     was_limited=was_limited,
                     request=request)
    next = get_query(request).get('next', '')
    third_party_token = get_query(request).get('key', False)
    provider = auth.get_provider('local')

    if not form.is_valid():
        if third_party_token:
            messages.info(request, provider.get_login_to_add_msg)

        return render_to_response(on_failure, {
            'login_form': form,
            'next': next,
            'key': third_party_token
        },
                                  context_instance=RequestContext(request))

    # get the user from the cache
    user = form.user_cache
    provider = auth.get_provider('local', user)

    if not provider.get_login_policy:
        message = provider.get_login_disabled_msg
        messages.error(request, message)
        return HttpResponseRedirect(reverse('login'))

    message = None
    if not user:
        message = provider.get_authentication_failed_msg
    elif not user.is_active:
        message = user.get_inactive_message('local')

    elif not user.has_auth_provider('local'):
        # valid user logged in with no auth providers set, add local provider
        # and let him log in
        if not user.get_available_auth_providers():
            user.add_auth_provider('local')
        else:
            message = _(astakos_messages.NO_LOCAL_AUTH)

    if message:
        messages.error(request, message)
        return render_to_response(on_failure, {'login_form': form},
                                  context_instance=RequestContext(request))

    response = prepare_response(request, user, next)
    if third_party_token:
        # use requests to assign the account he just authenticated with with
        # a third party provider account
        try:
            request.user.add_pending_auth_provider(third_party_token)
        except PendingThirdPartyUser.DoesNotExist:
            provider = auth.get_provider('local', request.user)
            messages.error(request, provider.get_add_failed_msg)

    provider = user.get_auth_provider('local')
    messages.success(request, provider.get_login_success_msg)
    response.set_cookie('astakos_last_login_method', 'local')
    return response
示例#4
0
文件: local.py 项目: AthinaB/synnefo
def login(request, template_name="im/login.html", on_failure='im/login.html',
          extra_context=None):
    """
    on_failure: the template name to render on login failure
    """
    if request.method == 'GET':
        extra_context = extra_context or {}

        third_party_token = request.GET.get('key', False)
        if third_party_token:
            messages.info(request, astakos_messages.AUTH_PROVIDER_LOGIN_TO_ADD)

        if request.user.is_authenticated():
            return HttpResponseRedirect(reverse('landing'))

        extra_context["primary_provider"] = LOCAL_PROVIDER

        return render_response(
            template_name,
            login_form=LoginForm(request=request),
            context_instance=get_context(request, extra_context)
        )

    was_limited = getattr(request, 'limited', False)
    form = LoginForm(data=request.POST,
                     was_limited=was_limited,
                     request=request)
    next = get_query(request).get('next', '')
    third_party_token = get_query(request).get('key', False)
    provider = auth.get_provider('local')

    if not form.is_valid():
        if third_party_token:
            messages.info(request, provider.get_login_to_add_msg)

        return render_to_response(
            on_failure,
            {'login_form': form,
             'next': next,
             'key': third_party_token},
            context_instance=get_context(request,
                                         primary_provider=LOCAL_PROVIDER))

    # get the user from the cache
    user = form.user_cache
    provider = auth.get_provider('local', user)

    if not provider.get_login_policy:
        message = provider.get_login_disabled_msg
        messages.error(request, message)
        return HttpResponseRedirect(reverse('login'))

    message = None
    if not user:
        message = provider.get_authentication_failed_msg
    elif not user.is_active:
        message = user.get_inactive_message('local')

    elif not user.has_auth_provider('local'):
        # valid user logged in with no auth providers set, add local provider
        # and let him log in
        if not user.get_available_auth_providers():
            user.add_auth_provider('local')
        else:
            message = _(astakos_messages.NO_LOCAL_AUTH)

    if message:
        messages.error(request, message)
        return render_to_response(on_failure,
                                  {'login_form': form},
                                  context_instance=RequestContext(request))

    response = prepare_response(request, user, next)
    if third_party_token:
        # use requests to assign the account he just authenticated with with
        # a third party provider account
        try:
            request.user.add_pending_auth_provider(third_party_token)
        except PendingThirdPartyUser.DoesNotExist:
            provider = auth.get_provider('local', request.user)
            messages.error(request, provider.get_add_failed_msg)

    provider = user.get_auth_provider('local')
    messages.success(request, provider.get_login_success_msg)
    response.set_cookie('astakos_last_login_method', 'local')
    provider.update_last_login_at()

    return response
示例#5
0
urlpatterns = patterns(
    'astakos.im.views',
    url(r'^$', 'index', {}, name='index'),
    url(r'^login/?$', 'login', {}, name='login'),
    url(r'^landing/?$', 'landing', {}, name='landing'),
    url(r'^profile/update_token?$', 'update_token', {}, name='update_token'),
    url(r'^profile/?$', 'edit_profile', {}, name='edit_profile'),
    url(r'^api_access/?$', 'api_access', {}, name='api_access'),
    url(r'^\.kamakirc/?$', 'api_access_config', {}, name='api_access_config'),
    url(r'^feedback/?$', 'feedback', {}, name='feedback'),
    url(r'^signup/?$',
        'signup', {
            'on_success': 'index',
            'extra_context': {
                'login_form': LoginForm()
            }
        },
        name='signup'),
    url(r'^logout/?$',
        'logout', {
            'template': 'im/login.html',
            'extra_context': {
                'login_form': LoginForm()
            }
        },
        name='logout'),
    url(r'^activate/?$', 'activate', {}, name='activate'),
    url(r'^approval_terms/?$', 'approval_terms', {}, name='latest_terms'),
    url(r'^approval_terms/(?P<term_id>\d+)/?$', 'approval_terms'),
    url(r'^send/activation/(?P<user_id>\d+)/?$',
示例#6
0
    ExtendedPasswordChangeForm,
    ExtendedSetPasswordForm, LoginForm)

from astakos.im import settings

urlpatterns = patterns(
    'astakos.im.views',
    url(r'^$', 'index', {}, name='index'),
    url(r'^login/?$', 'login', {}, name='login'),
    url(r'^landing/?$', 'landing', {}, name='landing'),
    url(r'^profile/update_token?$', 'update_token', {}, name='update_token'),
    url(r'^profile/?$','edit_profile', {}, name='edit_profile'),
    url(r'^api_access/?$','api_access', {}, name='api_access'),
    url(r'^\.kamakirc/?$','api_access_config', {}, name='api_access_config'),
    url(r'^feedback/?$', 'feedback', {}, name='feedback'),
    url(r'^signup/?$', 'signup', {'on_success': 'index', 'extra_context': {'login_form': LoginForm()}}, name='signup'),
    url(r'^logout/?$', 'logout', {'template': 'im/login.html', 'extra_context': {'login_form': LoginForm()}}, name='logout'),
    url(r'^activate/?$', 'activate', {}, name='activate'),
    url(r'^approval_terms/?$', 'approval_terms', {}, name='latest_terms'),
    url(r'^approval_terms/(?P<term_id>\d+)/?$', 'approval_terms'),
    url(r'^send/activation/(?P<user_id>\d+)/?$', 'send_activation', {}, name='send_activation'),
    url(r'^resources/?$', 'resource_usage', {}, name='resource_usage'),

#    url(r'^billing/?$', 'billing', {}, name='billing'),
#    url(r'^timeline/?$', 'timeline', {}, name='timeline'),

    url(r'^projects/add/?$', 'project_add', {}, name='project_add'),
    url(r'^projects/?$', 'project_list', {}, name='project_list'),
    url(r'^projects/search/?$', 'project_search', {}, name='project_search'),
    url(r'^projects/(?P<chain_id>\d+)/?$', 'project_detail', {}, name='project_detail'),
    url(r'^projects/(?P<chain_id>\d+)/join/?$', 'project_join', {}, name='project_join'),