コード例 #1
0
ファイル: views.py プロジェクト: whucaichen/Spirit
def register(request, registration_form=RegistrationForm):
    if request.user.is_authenticated:
        return redirect(request.GET.get('next', reverse('spirit:user:update')))

    form = registration_form(data=post_data(request))
    if (is_post(request) and
            not request.is_limited() and
            form.is_valid()):
        user = form.save()
        send_activation_email(request, user)
        messages.info(
            request, _(
                "We have sent you an email to %(email)s "
                "so you can activate your account!") % {'email': form.get_email()})

        # TODO: email-less activation
        # if not settings.REGISTER_EMAIL_ACTIVATION_REQUIRED:
        # login(request, user)
        # return redirect(request.GET.get('next', reverse('spirit:user:update')))

        return redirect(reverse(settings.LOGIN_URL))
    return render(
        request=request,
        template_name='spirit/user/auth/register.html',
        context={'form': form})
コード例 #2
0
def resend_activation_email(request):
    if request.user.is_authenticated:
        return redirect(request.GET.get('next', reverse('spirit:user:update')))

    form = ResendActivationForm(data=post_data(request))
    if is_post(request):
        if not request.is_limited() and form.is_valid():
            user = form.get_user()
            send_activation_email(request, user)

        # TODO: show if is_valid only
        messages.info(
            request,
            _("If you don't receive an email, please make sure you've entered "
              "the address you registered with, and check your spam folder."))
        return redirect(reverse(settings.LOGIN_URL))
    return render(request=request,
                  template_name='spirit/user/auth/activation_resend.html',
                  context={'form': form})