当前位置: 首页>>代码示例>>Python>>正文


Python tokens.PasswordResetTokenGenerator类代码示例

本文整理汇总了Python中django.contrib.auth.tokens.PasswordResetTokenGenerator的典型用法代码示例。如果您正苦于以下问题:Python PasswordResetTokenGenerator类的具体用法?Python PasswordResetTokenGenerator怎么用?Python PasswordResetTokenGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PasswordResetTokenGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_or_login

def create_or_login(request):
    if not request.method == "POST":
        return HttpResponseRedirect(reverse(list))
    form = EmailForm(request.POST)
    if not form.is_valid():
        return render(request, "members/login.html", {"form": form})
    data = form.cleaned_data
    member = get_object_or_None(Member, email=data["email"])
    if not member:
        member = Member(email=data["email"])
        member.save()
    member_url = reverse(edit, kwargs={"key": member.key})
    token_gen = PasswordResetTokenGenerator()
    token = token_gen.make_token(member)
    try:
        send_mail(
            "Your Nick Reid Directory Profile",
            "Follow this link to update your profile: %s?token=%s" % (member_url, token),
            "[email protected]",
            [member.email],
            fail_silently=False,
        )
    except:
        messages.error(request, "There was an error sending email to %s", member.email)
    messages.success(request, "An email has been sent to %s." % (member.email))
    return HttpResponseRedirect(reverse(list))
开发者ID:nickdotreid,项目名称:directory,代码行数:26,代码来源:views.py

示例2: send_token_message

def send_token_message(host, user, template, subject, new_user=False, extra_context=None):
    """
    Send an email to the the user with a new token
    """
    token_generator = PasswordResetTokenGenerator()
  
    t = loader.get_template(template)
    c = {
            'email': user.email,
            'host':  host,
            'user_token': int_to_base36(user.id),
            'user': user,
            'key_token': token_generator.make_token(user),
            'new_user' : new_user,
        }

    if extra_context:
        # If we have extra_content we need for the template
        for key in extra_context:
            c[key] = extra_context[key]

    # send the user an email with the template filled out
    # the actual link can be created using:
    # {% url signup_login_by_email user_token key_token %}
    send_mail(subject, t.render(Context(c)), settings.EMAIL_HOST_USER, [user.email])
开发者ID:omkz,项目名称:signup,代码行数:25,代码来源:views.py

示例3: test_reset_password

    def test_reset_password(self):
        response = self.client.get(reverse('auth_password_reset'))
        self.assertEquals(response.status_code, 200)
        self.assertIn('Reset your password', response.content)

        response = self.client.post(reverse('auth_password_reset'),
                                    {'email': self.user.email}, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('email with a link to reset your password', response.content)

        pt = PasswordResetTokenGenerator()
        token = pt.make_token(self.user)
        uid = base64.b64encode(str(self.user.id)).strip('=')
        response = self.client.get(reverse('auth_password_reset_confirm',
                                           args=(uid, token)),
                                   follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('Enter your new password below', response.content)

        data = {
            'new_password1': 'newpassword',
            'new_password2': 'newpassword'
        }
        response = self.client.post(reverse('auth_password_reset_confirm', args=(uid, token)),
                                    data, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertIn('Your password has been reset!', response.content)
        result = self.client.login(username=self.user.username, password='newpassword')
        self.assertTrue(result)

        #reset password
        self.user.set_password('supersecret')
开发者ID:Fingel,项目名称:astrochallenge,代码行数:32,代码来源:test_views.py

示例4: _get_confirm_url

 def _get_confirm_url(self, user):
     token_maker = PasswordResetTokenGenerator()
     token = token_maker.make_token(user)
     uid = urlsafe_base64_encode(force_bytes(user.pk)) #same thing django does to generate uid
     confirm_url = reverse('auth_password_reset_confirm', 
                           kwargs={'token':token,
                                   'uidb64':uid})
     return confirm_url
开发者ID:georgedorn,项目名称:share2grandma,代码行数:8,代码来源:accounts.py

示例5: test_make_token

 def test_make_token(self):
     """
     Ensure that we can make a token and that it is valid
     """
     user = User.objects.create_user('tokentestuser', '[email protected]', 'testpw')
     p0 = PasswordResetTokenGenerator()
     tk1 = p0.make_token(user)
     self.assertTrue(p0.check_token(user, tk1))
开发者ID:0xmilk,项目名称:appscale,代码行数:8,代码来源:tokens.py

示例6: test_PasswordResetConfirmView_valid_token

 def test_PasswordResetConfirmView_valid_token(self):
     # PasswordResetConfirmView valid token
     default_token_generator = PasswordResetTokenGenerator()
     token = default_token_generator.make_token(self.user)
     uidb64 = force_text(urlsafe_base64_encode(force_bytes(self.user.pk)))
     response = PasswordResetConfirmView.as_view(success_url='dummy/')(self.request, uidb64=uidb64, token=token)
     self.assertContains(response, '<title>Enter new password</title>')
     self.assertContains(response, '<h1>Enter new password</h1>')
开发者ID:JBKahn,项目名称:django,代码行数:8,代码来源:test_templates.py

示例7: form_valid

    def form_valid(self, form):
        """
        Register a new user.
        """
        # Do not accept any valid form when registration is closed.
        if not settings.REGISTRATION_POSSIBLE:
            messages.error(self.request, _('I\'m sorry, but I can\'t let anyone register at the moment.'))
            return redirect(reverse_lazy('login'))

        # Create and save user
        user = LilyUser.objects.create_user(
            email=form.cleaned_data['email'],
            password=form.cleaned_data['password'],
            first_name=form.cleaned_data['first_name'],
            preposition=form.cleaned_data['preposition'],
            last_name=form.cleaned_data['last_name'],
        )

        user.is_active = False
        user.save()

        # Add to admin group
        account_admin = Group.objects.get_or_create(name='account_admin')[0]
        user.groups.add(account_admin)

        # Get the current site
        try:
            current_site = Site.objects.get_current()
        except Site.DoesNotExist:
            current_site = ''

        # Generate uidb36 and token for the activation link
        uidb36 = int_to_base36(user.pk)
        token_generator = PasswordResetTokenGenerator()
        token = token_generator.make_token(user)

        # Send an activation mail
        # TODO: only create/save contact when e-mail sent successfully
        send_templated_mail(
            template_name='activation',
            from_email=settings.DEFAULT_FROM_EMAIL,
            recipient_list=[form.cleaned_data['email']],
            context={
                'current_site': current_site,
                'protocol': self.request.is_secure() and 'https' or 'http',
                'user': user,
                'uidb36': uidb36,
                'token': token,
            }
        )

        # Show registration message
        messages.success(
            self.request,
            _('Registration completed. I\'ve sent you an email, please check it to activate your account.')
        )

        return self.get_success_url()
开发者ID:Fokko,项目名称:hellolily,代码行数:58,代码来源:views.py

示例8: authenticate

 def authenticate(self, user_token, key_token):
     try:
         token_generator=PasswordResetTokenGenerator()
         user = get_object_or_404(User, pk=base36_to_int(user_token))
         if token_generator.check_token( user, key_token) and user.is_active:
             logger.debug("User: %s authenticated via token" % user.username)
             return user
     except User.DoesNotExist:
         return None
开发者ID:bricetebbs,项目名称:sharider,代码行数:9,代码来源:views.py

示例9: get_token

def get_token(user):
    
    #assert request.user.is_authenticated()
    
    token_generator = PasswordResetTokenGenerator()
    
    token =  token_generator.make_token(user)
    
    return token
开发者ID:Aviah,项目名称:django-website,代码行数:9,代码来源:helpers.py

示例10: test_date_length

    def test_date_length(self):
        """
        Overly long dates, which are a potential DoS vector, aren't allowed.
        """
        user = User.objects.create_user('ima1337h4x0r', '[email protected]', 'p4ssw0rd')
        p0 = PasswordResetTokenGenerator()

        # This will put a 14-digit base36 timestamp into the token, which is too large.
        with self.assertRaises(ValueError):
            p0._make_token_with_timestamp(user, 175455491841851871349)
开发者ID:Hwesta,项目名称:django,代码行数:10,代码来源:test_tokens.py

示例11: test_PasswordResetConfirmView_valid_token

 def test_PasswordResetConfirmView_valid_token(self):
     # PasswordResetConfirmView valid token
     client = PasswordResetConfirmClient()
     default_token_generator = PasswordResetTokenGenerator()
     token = default_token_generator.make_token(self.user)
     uidb64 = force_text(urlsafe_base64_encode(force_bytes(self.user.pk)))
     url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
     response = client.get(url)
     self.assertContains(response, '<title>Enter new password</title>')
     self.assertContains(response, '<h1>Enter new password</h1>')
开发者ID:cloudera,项目名称:hue,代码行数:10,代码来源:test_templates.py

示例12: test_date_length

    def test_date_length(self):
        """
        Make sure we don't allow overly long dates, causing a potential DoS.
        """
        user = User.objects.create_user('ima1337h4x0r', '[email protected]', 'p4ssw0rd')
        p0 = PasswordResetTokenGenerator()

        # This will put a 14-digit base36 timestamp into the token, which is too large.
        tk1 = p0._make_token_with_timestamp(user, 175455491841851871349)
        self.assertFalse(p0.check_token(user, tk1))
开发者ID:0xmilk,项目名称:appscale,代码行数:10,代码来源:tokens.py

示例13: test_10265

 def test_10265(self):
     """
     The token generated for a user created in the same request
     will work correctly.
     """
     # See ticket #10265
     user = User.objects.create_user('comebackkid', '[email protected]', 'testpw')
     p0 = PasswordResetTokenGenerator()
     tk1 = p0.make_token(user)
     reload = User.objects.get(username='comebackkid')
     tk2 = p0.make_token(reload)
     self.assertEqual(tk1, tk2)
开发者ID:ArcTanSusan,项目名称:django,代码行数:12,代码来源:test_tokens.py

示例14: send_reset_password_email

def send_reset_password_email(user, request):
    token_generator = PasswordResetTokenGenerator()

    temp_key = token_generator.make_token(user)
    # send the password reset email
    path = reverse('account_reset_password_from_key',
                   kwargs=dict(uidb36=int_to_base36(user.id),
                               key=temp_key))
    url = request.build_absolute_uri(path)
    context = {'password_reset_url': url}
    subject = 'Reset your password'
    send_mail('account/email/forget_password.html', subject, user.email, context)
开发者ID:lettoosoft,项目名称:lettoo-weixin-platform-back,代码行数:12,代码来源:utils.py

示例15: send_email_auth_token

def send_email_auth_token(request, user, new_user=False):
    token_generator = PasswordResetTokenGenerator()
  
    t = loader.get_template('signup/email_auth_form.html')
    c = {
            'email': user.email,
            'host':  request.get_host(),
            'user_token': int_to_base36(user.id),
            'user': user,
            'key_token': token_generator.make_token(user),
            'new_user' : new_user,
        }
    send_mail(_("New Login token for %s") % request.get_host(), t.render(Context(c)), settings.EMAIL_HOST_USER, [user.email])
开发者ID:bricetebbs,项目名称:sharider,代码行数:13,代码来源:views.py


注:本文中的django.contrib.auth.tokens.PasswordResetTokenGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。