コード例 #1
0
ファイル: accounts.py プロジェクト: yanheven/sentry
def register(request):
    from django.conf import settings

    if not (settings.SENTRY_ALLOW_REGISTRATION
            or request.session.get('can_register')):
        return HttpResponseRedirect(reverse('sentry'))

    form = RegistrationForm(request.POST or None,
                            captcha=bool(request.session.get('needs_captcha')))
    if form.is_valid():
        user = form.save()

        # can_register should only allow a single registration
        request.session.pop('can_register', None)

        # HACK: grab whatever the first backend is and assume it works
        user.backend = settings.AUTHENTICATION_BACKENDS[0]

        login_user(request, user)

        request.session.pop('needs_captcha', None)

        return login_redirect(request)

    elif request.POST and not request.session.get('needs_captcha'):
        request.session['needs_captcha'] = 1
        form = RegistrationForm(request.POST or None, captcha=True)
        form.errors.pop('captcha', None)

    return render_to_response(
        'sentry/register.html', {
            'form': form,
            'AUTH_PROVIDERS': get_auth_providers(),
            'SOCIAL_AUTH_CREATE_USERS': settings.SOCIAL_AUTH_CREATE_USERS,
        }, request)
コード例 #2
0
def register(request):
    from django.conf import settings

    if not (features.has('auth:register')
            or request.session.get('can_register')):
        return HttpResponseRedirect(reverse('sentry'))

    form = RegistrationForm(request.POST or None,
                            captcha=bool(request.session.get('needs_captcha')))
    if form.is_valid():
        user = form.save()

        # TODO(dcramer): ideally this would be handled by a special view
        # specifically for organization registration
        if settings.SENTRY_SINGLE_ORGANIZATION:
            org = Organization.get_default()

            defaults = {
                'has_global_access': True,
                'type': OrganizationMemberType.MEMBER,
            }
            try:
                auth_provider = AuthProvider.objects.get(organization=org.id, )
            except AuthProvider.DoesNotExist:
                pass
            else:
                defaults.update({
                    'has_global_access': auth_provider.default_global_access,
                    'type': auth_provider.default_role,
                })

            org.member_set.create(user=user, **defaults)

        # can_register should only allow a single registration
        request.session.pop('can_register', None)

        # HACK: grab whatever the first backend is and assume it works
        user.backend = settings.AUTHENTICATION_BACKENDS[0]

        login_user(request, user)

        request.session.pop('needs_captcha', None)

        return login_redirect(request)

    elif request.POST and not request.session.get('needs_captcha'):
        request.session['needs_captcha'] = 1
        form = RegistrationForm(request.POST or None, captcha=True)
        form.errors.pop('captcha', None)

    return render_to_response('sentry/register.html', {
        'form': form,
    }, request)
コード例 #3
0
ファイル: auth_login.py プロジェクト: zhouyu0615/sentry
 def get_register_form(self, request, initial=None):
     op = request.POST.get("op")
     return RegistrationForm(
         request.POST if op == "register" else None,
         initial=initial,
         # Custom auto_id to avoid ID collision with AuthenticationForm.
         auto_id="id_registration_%s",
     )
コード例 #4
0
ファイル: auth_login.py プロジェクト: tanlovetanh/sentry
 def get_register_form(self, request, initial=None):
     op = request.POST.get('op')
     return RegistrationForm(
         request.POST if op == 'register' else None,
         initial=initial,
     )
コード例 #5
0
 def get_register_form(self, request):
     op = request.POST.get('op')
     return RegistrationForm(
         request.POST if op == 'register' else None,
         captcha=bool(request.session.get('needs_captcha')),
     )
コード例 #6
0
 def get_register_form(self, request, initial=None):
     op = request.POST.get("op")
     return RegistrationForm(request.POST if op == "register" else None,
                             initial=initial)