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


Python forms.SetPasswordForm方法代码示例

本文整理汇总了Python中django.contrib.auth.forms.SetPasswordForm方法的典型用法代码示例。如果您正苦于以下问题:Python forms.SetPasswordForm方法的具体用法?Python forms.SetPasswordForm怎么用?Python forms.SetPasswordForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.forms的用法示例。


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

示例1: mutate_and_get_payload

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def mutate_and_get_payload(cls, input, context, info):
        Model = UserModel

        try:
            uid = force_text(uid_decoder(input.get('id')))
            user = Model.objects.get(pk=uid)
        except (TypeError, ValueError, OverflowError, Model.DoesNotExist):
            raise Exception('uid has an invalid value')

        data = {
            'uid': input.get('id'),
            'token': input.get('token'),
            'new_password1': input.get('password'),
            'new_password2': input.get('password')
        }

        reset_form = SetPasswordForm(user=user, data=data)

        if not reset_form.is_valid():
            raise Exception("The token is not valid")

        reset_form.save()

        return ResetPassword(ok=True, user=user) 
开发者ID:morgante,项目名称:django-graph-auth,代码行数:26,代码来源:schema.py

示例2: reset_confirm

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def reset_confirm(request, key):
    """
    Complete the password reset procedure.
    """
    key = get_object_or_404(ConfirmationKey, key=key)
    if request.method == 'POST':
        form = SetPasswordForm(user=key.user, data=request.POST)
        if form.is_valid():
            form.save()
            key.delete()
            messages.info(request, "Thank you! Your password has been reset. Please log in below.")
            return redirect('accounts:login')
    else:
        form = SetPasswordForm(user=key.user)
    return render(request, 'form.html', {
        'title': 'Set Password',
        'form': form,
        'description': "Please enter a new password for your account.",
        'action': 'Continue',
    }) 
开发者ID:2buntu,项目名称:2buntu-blog,代码行数:22,代码来源:views.py

示例3: validate

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def validate(self, attrs):
        self._errors = {}

        # Decode the uidb64 to uid to get User object
        try:
            uid = force_text(uid_decoder(attrs['uid']))
            self.user = UserModel._default_manager.get(pk=uid)
        except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
            raise ValidationError({'uid': ['Invalid value']})

        self.custom_validation(attrs)
        # Construct SetPasswordForm instance
        self.set_password_form = self.set_password_form_class(
            user=self.user, data=attrs
        )
        if not self.set_password_form.is_valid():
            raise serializers.ValidationError(self.set_password_form.errors)
        if not default_token_generator.check_token(self.user, attrs['token']):
            raise ValidationError({'token': ['Invalid value']})

        return attrs 
开发者ID:Tivix,项目名称:django-rest-auth,代码行数:23,代码来源:serializers.py

示例4: get_form_kwargs

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def get_form_kwargs(self):

        kwargs = super().get_form_kwargs()
        kwargs['user'] = self.object

        kwargs['disabled'] = False

        # Case when the admin manages no caisses of the edited user
        if(len(list(set(self.request.user.caisses.all())
           & set(self.object.caisses.all()))) == 0):

            # We disable every field of the SetPasswordForm
            kwargs['disabled'] = True

        return kwargs 
开发者ID:betagouv,项目名称:mrs,代码行数:17,代码来源:crudlfap.py

示例5: test_contains_form

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def test_contains_form(self):
        form = self.response.context.get('form')
        self.assertIsInstance(form, SetPasswordForm) 
开发者ID:sibtc,项目名称:django-beginners-guide,代码行数:5,代码来源:test_view_password_reset.py

示例6: password_reset_confirm

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
                           token_generator=default_token_generator, set_password_form=SetPasswordForm,
                           post_reset_redirect=None):
    """
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    """
    assert uidb36 is not None and token is not None # checked by URLconf
    if post_reset_redirect is None:
        post_reset_redirect = reverse('drawquest.apps.drawquest_auth.views.password_reset_complete')
    try:
        uid_int = base36_to_int(uidb36)
        user = User.objects.get(id=uid_int)
    except (ValueError, User.DoesNotExist):
        user = None

    ctx = {}

    if user is not None and token_generator.check_token(user, token):
        ctx['validlink'] = True
        if request.method == 'POST':
            form = set_password_form(user, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(post_reset_redirect)
        else:
            form = set_password_form(None)
    else:
        ctx['validlink'] = False
        form = None
    ctx['form'] = form
    return r2r_jinja(template_name, ctx, request) 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:34,代码来源:views.py

示例7: create_account

# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import SetPasswordForm [as 别名]
def create_account(request, info_token):
    if request.user.is_authenticated:
        return redirect('home')
    try:
        info = signing.loads(info_token, max_age=TOKEN_MAX_AGE)
    except signing.SignatureExpired:
        return TemplateResponse(request, 'registration/token_expired.html')
    except signing.BadSignature:
        return TemplateResponse(request, 'registration/token_invalid.html')

    username = info['username']

    if BitpollUser.objects.filter(username=username).exists():
        messages.warning(request, _("This User already exists"))
        return redirect('login')

    if request.method == 'POST':
        # using None as User as we do not have the user, we can not call form.save() as a result
        form = SetPasswordForm(None, request.POST)
        if form.is_valid():
            first_name = info.get('first_name')
            last_name = info.get('last_name')
            if not (first_name and last_name):
                return TemplateResponse(request, 'registration/token_invalid.html')
            email = info['email']
            user = BitpollUser(username=username,
                               email=email,
                               first_name=first_name,
                               last_name=last_name,
                               email_invitation=info['email_invitation'],
                               #  TODO: more fields?
                               )
            user.set_password(form.cleaned_data['new_password2'])
            user.save()
            user.backend = 'django.contrib.auth.backends.ModelBackend'

            login(request, user)
            return redirect('home')
    else:
        form = SetPasswordForm(None)

    return TemplateResponse(request, 'registration/create_account.html', {
        'form': form,
        'username': username
    }) 
开发者ID:fsinfuhh,项目名称:Bitpoll,代码行数:47,代码来源:views.py


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