示例#1
0
    def send_reset_request_email(self, domain_override=None,
             subject_template_name='password_reset/validate/email_subject.html',
             email_template_name='password_reset/validate/email.html',
             use_https=False,token_generator=default_token_generator,
             from_email=None, request=None):


        for user in self.users_cache:

            if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
            else:
                site_name = domain = domain_override

            context = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'uid': int_to_base36(user.pk),
                'user': user,
                'token': token_generator.make_token(user),
                'protocol': use_https and 'https' or 'http',
            }

            send_html_email( [user.email], from_email, subject_template_name, email_template_name, context)
示例#2
0
    def send_reset_request_email(
            self,
            domain_override=None,
            subject_template_name='password_reset/validate/email_subject.html',
            email_template_name='password_reset/validate/email.html',
            use_https=False,
            token_generator=default_token_generator,
            from_email=None,
            request=None):

        for user in self.users_cache:

            if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
            else:
                site_name = domain = domain_override

            context = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'uid': int_to_base36(user.pk),
                'user': user,
                'token': token_generator.make_token(user),
                'protocol': use_https and 'https' or 'http',
            }

            send_html_email([user.email], from_email, subject_template_name,
                            email_template_name, context)
示例#3
0
    def send_retrieve_email(
            self,
            domain_override=None,
            subject_template_name='username_retrieve/email_subject.html',
            email_template_name='username_retrieve/email.html',
            use_https=False,
            from_email=None,
            request=None):

        for user in self.users_cache:

            if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
            else:
                site_name = domain = domain_override

            context = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'user': user,
                'protocol': use_https and 'https' or 'http',
            }

            send_html_email([user.email], from_email, subject_template_name,
                            email_template_name, context)
示例#4
0
def password_reset_request(request, uidb36=None, token=None,domain_override=None,
                           request_email_subject_template='password_reset/request/email_subject.html',
                           request_email_template='password_reset/request/email.html',
                           request_email_done='password_reset/request/done.html',
                           token_generator=default_token_generator,
                           current_app=None, extra_context=None, use_https=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    UserModel = get_user_model()
    assert uidb36 is not None and token is not None  # checked by URLconf

    try:
        uid_int = base36_to_int(uidb36)
        user = UserModel._default_manager.get(pk=uid_int)
    except (ValueError, OverflowError, UserModel.DoesNotExist):
        user = None

    if user is not None and token_generator.check_token(user, token):
        validlink = True

        if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
        else:
                site_name = domain = domain_override

        context = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'uid': int_to_base36(user.pk),
                'user': user,
                'token': token_generator.make_token(user),
                'protocol': use_https and 'https' or 'http',
        }

        send_html_email( [HELPDESK_EMAIL], settings.DEFAULT_FROM_EMAIL , request_email_subject_template , request_email_template , context)

    else:
        validlink = False

    context = {
        'validlink': validlink,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, request_email_done, context,
                            current_app=current_app)
示例#5
0
    def send_retrieve_email(self, domain_override=None,
             subject_template_name='username_retrieve/email_subject.html',
             email_template_name='username_retrieve/email.html',
             use_https=False,from_email=None, request=None):


        for user in self.users_cache:

            if not domain_override:
                current_site = get_current_site(request)
                site_name = current_site.name
                domain = current_site.domain
            else:
                site_name = domain = domain_override

            context = {
                'email': user.email,
                'domain': domain,
                'site_name': site_name,
                'user': user,
                'protocol': use_https and 'https' or 'http',
            }

            send_html_email( [user.email], from_email, subject_template_name, email_template_name, context)
示例#6
0
def password_reset_process(request, uidb36=None, token=None,
                           domain_override = None,
                           template_name='password_reset/process/reset_form.html',
                           process_email_subject_template = 'password_reset/process/email_subject.html',
                           process_email_template = 'password_reset/process/email.html',
                           token_generator=default_token_generator,
                           set_password_form=SetPasswordForm,
                           post_reset_redirect=None,
                           use_https=False,
                           current_app=None, extra_context=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    UserModel = get_user_model()
    assert uidb36 is not None and token is not None  # checked by URLconf
    if post_reset_redirect is None:
        post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete')
    try:
        uid_int = base36_to_int(uidb36)
        user = UserModel._default_manager.get(pk=uid_int)
    except (ValueError, OverflowError, UserModel.DoesNotExist):
        user = None

    if user is not None and token_generator.check_token(user, token):
        validlink = True
        if request.method == 'POST':
            form = set_password_form(user, request.POST)
            if form.is_valid():
                form.save()

                if not domain_override:
                    current_site = get_current_site(request)
                    site_name = current_site.name
                    domain = current_site.domain
                else:
                    site_name = domain = domain_override

                context = {
                    'email': user.email,
                    'domain': domain,
                    'site_name': site_name,
                    'user': user,
                    'password' : form.cleaned_data['new_password1'],
                    'protocol': use_https and 'https' or 'http',
                }

                send_html_email( [user.email], settings.DEFAULT_FROM_EMAIL, process_email_subject_template , process_email_template , context)
                return HttpResponseRedirect(post_reset_redirect)
        else:
            form = set_password_form(None)
    else:
        validlink = False
        form = None
    context = {
        'form': form,
        'validlink': validlink,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, template_name, context,
                            current_app=current_app)
示例#7
0
def password_reset_process(
        request,
        uidb36=None,
        token=None,
        domain_override=None,
        template_name='password_reset/process/reset_form.html',
        process_email_subject_template='password_reset/process/email_subject.html',
        process_email_template='password_reset/process/email.html',
        token_generator=default_token_generator,
        set_password_form=SetPasswordForm,
        post_reset_redirect=None,
        use_https=False,
        current_app=None,
        extra_context=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    UserModel = get_user_model()
    assert uidb36 is not None and token is not None  # checked by URLconf
    if post_reset_redirect is None:
        post_reset_redirect = reverse(
            'django.contrib.auth.views.password_reset_complete')
    try:
        uid_int = base36_to_int(uidb36)
        user = UserModel._default_manager.get(pk=uid_int)
    except (ValueError, OverflowError, UserModel.DoesNotExist):
        user = None

    if user is not None and token_generator.check_token(user, token):
        validlink = True
        if request.method == 'POST':
            form = set_password_form(user, request.POST)
            if form.is_valid():
                form.save()

                if not domain_override:
                    current_site = get_current_site(request)
                    site_name = current_site.name
                    domain = current_site.domain
                else:
                    site_name = domain = domain_override

                context = {
                    'email': user.email,
                    'domain': domain,
                    'site_name': site_name,
                    'user': user,
                    'password': form.cleaned_data['new_password1'],
                    'protocol': use_https and 'https' or 'http',
                }

                send_html_email([user.email], settings.DEFAULT_FROM_EMAIL,
                                process_email_subject_template,
                                process_email_template, context)
                return HttpResponseRedirect(post_reset_redirect)
        else:
            form = set_password_form(None)
    else:
        validlink = False
        form = None
    context = {
        'form': form,
        'validlink': validlink,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request,
                            template_name,
                            context,
                            current_app=current_app)
示例#8
0
def password_reset_request(
        request,
        uidb36=None,
        token=None,
        domain_override=None,
        request_email_subject_template='password_reset/request/email_subject.html',
        request_email_template='password_reset/request/email.html',
        request_email_done='password_reset/request/done.html',
        token_generator=default_token_generator,
        current_app=None,
        extra_context=None,
        use_https=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    UserModel = get_user_model()
    assert uidb36 is not None and token is not None  # checked by URLconf

    try:
        uid_int = base36_to_int(uidb36)
        user = UserModel._default_manager.get(pk=uid_int)
    except (ValueError, OverflowError, UserModel.DoesNotExist):
        user = None

    if user is not None and token_generator.check_token(user, token):
        validlink = True

        if not domain_override:
            current_site = get_current_site(request)
            site_name = current_site.name
            domain = current_site.domain
        else:
            site_name = domain = domain_override

        context = {
            'email': user.email,
            'domain': domain,
            'site_name': site_name,
            'uid': int_to_base36(user.pk),
            'user': user,
            'token': token_generator.make_token(user),
            'protocol': use_https and 'https' or 'http',
        }

        send_html_email([HELPDESK_EMAIL], settings.DEFAULT_FROM_EMAIL,
                        request_email_subject_template, request_email_template,
                        context)

    else:
        validlink = False

    context = {
        'validlink': validlink,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request,
                            request_email_done,
                            context,
                            current_app=current_app)