Exemplo n.º 1
0
    def enroll(self, request, interface, insecure=False):
        totp_secret = request.POST.get('totp_secret')
        if totp_secret is not None:
            interface.secret = totp_secret

        if 'otp' in request.POST:
            form = TwoFactorForm(request.POST)
            password_form = ConfirmPasswordForm(request.user, request.POST)
            if 'password' in password_form.fields and password_form.is_valid():
                if request.user.check_password(password_form.cleaned_data['password']):
                    if form.is_valid() and interface.validate_otp(
                            form.cleaned_data['otp']):
                        return TwoFactorSettingsView.enroll(self, request, interface)
                    else:
                        form.errors['__all__'] = ['Invalid confirmation code.']
                else:
                    form.errors['__all__'] = ['Invalid password.']
            else:
                if form.is_valid() and interface.validate_otp(
                        form.cleaned_data['otp']):
                    return TwoFactorSettingsView.enroll(self, request, interface)
                else:
                    form.errors['__all__'] = ['Invalid confirmation code.']

        else:
            form = TwoFactorForm()
            password_form = ConfirmPasswordForm(request.user)

        context = self.make_context(request, interface)
        context['otp_form'] = form
        context['password_form'] = password_form
        context['provision_qrcode'] = interface.get_provision_qrcode(
            request.user.email)
        return render_to_response('sentry/account/twofactor/enroll_totp.html',
                                  context, request)
Exemplo n.º 2
0
    def enroll(self, request, interface, insecure=False):
        totp_secret = request.POST.get('totp_secret')
        if totp_secret is not None:
            interface.secret = totp_secret

        if 'otp' in request.POST:
            form = TwoFactorForm(request.POST)
            password_form = ConfirmPasswordForm(request.user, request.POST)
            if 'password' in password_form.fields:
                if password_form.is_valid():
                    if form.is_valid() and interface.validate_otp(
                            form.cleaned_data['otp']):
                        return TwoFactorSettingsView.enroll(self, request, interface)
                    else:
                        form.errors['__all__'] = ['Invalid confirmation code.']
                else:
                    form.errors['__all__'] = ['Invalid password.']
            else:
                if form.is_valid() and interface.validate_otp(
                        form.cleaned_data['otp']):
                    return TwoFactorSettingsView.enroll(self, request, interface)
                else:
                    form.errors['__all__'] = ['Invalid confirmation code.']

        else:
            form = TwoFactorForm()
            password_form = ConfirmPasswordForm(request.user)

        context = self.make_context(request, interface)
        context['otp_form'] = form
        context['password_form'] = password_form
        context['provision_qrcode'] = interface.get_provision_qrcode(
            request.user.email)
        return render_to_response('sentry/account/twofactor/enroll_totp.html',
                                  context, request)
Exemplo n.º 3
0
    def enroll(self, request, interface, insecure=False):
        stage = request.POST.get('stage') or 'initial'

        totp_secret = request.POST.get('totp_secret')
        if totp_secret is not None:
            interface.secret = totp_secret

        phone_number = request.POST.get('phone_number')
        if phone_number is not None:
            interface.phone_number = phone_number

        sms_form = SmsForm()
        otp_form = TwoFactorForm()

        if stage == 'pick_number':
            sms_form = SmsForm(request.POST)
            if sms_form.is_valid():
                interface.send_text(for_enrollment=True, request=request)
                stage = 'confirm'
        elif stage == 'confirm':
            otp_form = TwoFactorForm(request.POST)
            if otp_form.is_valid() and interface.validate_otp(
                    otp_form.cleaned_data['otp']):
                return TwoFactorSettingsView.enroll(self, request, interface)
            else:
                otp_form.errors['__all__'] = ['Invalid confirmation code.']

        context = self.make_context(request, interface)
        context['sms_form'] = sms_form
        context['otp_form'] = otp_form
        context['stage'] = stage
        return render_to_response('sentry/account/twofactor/enroll_sms.html',
                                  context, request)
Exemplo n.º 4
0
    def enroll(self, request, interface, insecure=False):
        stage = request.POST.get('stage') or 'initial'

        totp_secret = request.POST.get('totp_secret')
        if totp_secret is not None:
            interface.secret = totp_secret

        phone_number = request.POST.get('phone_number')
        if phone_number is not None:
            interface.phone_number = phone_number

        sms_form = SmsForm()
        otp_form = TwoFactorForm()

        if stage == 'pick_number':
            sms_form = SmsForm(request.POST)
            if sms_form.is_valid():
                interface.send_text(for_enrollment=True, request=request)
                stage = 'confirm'
        elif stage == 'confirm':
            otp_form = TwoFactorForm(request.POST)
            if otp_form.is_valid() and interface.validate_otp(
                    otp_form.cleaned_data['otp']):
                return TwoFactorSettingsView.enroll(self, request, interface)
            else:
                otp_form.errors['__all__'] = ['Invalid confirmation code.']

        context = self.make_context(request, interface)
        context['sms_form'] = sms_form
        context['otp_form'] = otp_form
        context['stage'] = stage
        return render_to_response('sentry/account/twofactor/enroll_sms.html',
                                  context, request)
Exemplo n.º 5
0
    def enroll(self, request, interface, insecure=False):
        stage = request.POST.get("stage") or "initial"

        totp_secret = request.POST.get("totp_secret")
        if totp_secret is not None:
            interface.secret = totp_secret

        phone_number = request.POST.get("phone_number")
        if phone_number is not None:
            interface.phone_number = phone_number

        sms_form = SmsForm()
        otp_form = TwoFactorForm()

        if stage == "pick_number":
            sms_form = SmsForm(request.POST)
            if sms_form.is_valid():
                interface.send_text(for_enrollment=True, request=request)
                stage = "confirm"
        elif stage == "confirm":
            otp_form = TwoFactorForm(request.POST)
            if otp_form.is_valid() and interface.validate_otp(otp_form.cleaned_data["otp"]):
                return TwoFactorSettingsView.enroll(self, request, interface)
            else:
                otp_form.errors["__all__"] = ["Invalid confirmation code."]

        context = self.make_context(request, interface)
        context["sms_form"] = sms_form
        context["otp_form"] = otp_form
        context["stage"] = stage
        return render_to_response("sentry/account/twofactor/enroll_sms.html", context, request)
Exemplo n.º 6
0
    def enroll(self, request, interface, insecure=False):
        totp_secret = request.POST.get("totp_secret")
        if totp_secret is not None:
            interface.secret = totp_secret

        if "otp" in request.POST:
            form = TwoFactorForm(request.POST)
            if form.is_valid() and interface.validate_otp(form.cleaned_data["otp"]):
                return TwoFactorSettingsView.enroll(self, request, interface)
            else:
                form.errors["__all__"] = ["Invalid confirmation code."]
        else:
            form = TwoFactorForm()

        context = self.make_context(request, interface)
        context["otp_form"] = form
        context["provision_qrcode"] = interface.get_provision_qrcode(request.user.email)
        return render_to_response("sentry/account/twofactor/enroll_totp.html", context, request)