本文整理汇总了Python中django.contrib.auth.forms.PasswordChangeForm方法的典型用法代码示例。如果您正苦于以下问题:Python forms.PasswordChangeForm方法的具体用法?Python forms.PasswordChangeForm怎么用?Python forms.PasswordChangeForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms
的用法示例。
在下文中一共展示了forms.PasswordChangeForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_password
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password(request):
if not password_management_enabled():
raise Http404
can_change_password = request.user.has_usable_password()
if can_change_password:
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
messages.success(request, _("Your password has been changed successfully!"))
return redirect('wagtailadmin_account')
else:
form = PasswordChangeForm(request.user)
else:
form = None
return TemplateResponse(request, 'wagtailadmin/account/change_password.html', {
'form': form,
'can_change_password': can_change_password,
})
示例2: change_password_view
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password_view(request):
if request.method == 'POST':
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
# so that user does not get logged out, not working as of now.
# TODO
update_session_auth_hash(request, form.user)
return redirect('/account/profile')
else:
return redirect('/account/change-password')
else:
form = PasswordChangeForm(user=request.user)
args = {'form': form}
return render(request, 'accounts/change_password.html', args)
示例3: change_password_view
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password_view(request):
if request.method == 'POST':
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
login(request, request.user)
messages.success(request, _('Password successfully changed.'))
return redirect('site.account')
else:
form = PasswordChangeForm(user=request.user)
for field in form.fields.values():
field.help_text = None
return render(request, 'site/account_form.html', {
'title': _('Change password'),
'back_url': reverse('site.account'),
'form': form
})
示例4: change_password_view
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password_view(request):
if request.method == 'POST':
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
login(request, request.user)
messages.success(request, _('Password successfully changed.'))
return redirect('editor.users.detail', pk=request.user.pk)
else:
form = PasswordChangeForm(user=request.user)
for field in form.fields.values():
field.help_text = None
return render(request, 'editor/account_form.html', {
'title': _('Change password'),
'back_url': reverse('site.account'),
'form': form
})
示例5: change_password
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password(request: Request) -> render:
"""Changes password."""
if request.method == "POST":
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important!
messages.success(request, "Your password was successfully updated!")
return redirect("change_password")
else:
messages.error(request, "Please correct the error below.")
else:
form = PasswordChangeForm(request.user)
return render(request, "accounts/change_password.html", {"form": form})
# just for MW demo
# ------------------------------------------------------------------------------
示例6: change_password
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user)
messages.success(
request, 'Your password was successfully updated!')
return redirect('settings')
else:
messages.warning(
request, 'There was an error changing your password!')
else:
form = PasswordChangeForm(request.user)
return render(request, 'change_password.html', {'form': form})
示例7: profile
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def profile(request):
"""View function for the user profile, profile.html."""
# Get the current user's user object
# user = request.user
# # Look-up the username in the database
# current_user_name = User.objects.get(username=user.username)
# current_user_avatar = UserProfile.objects.get(user=user.id)
# If ths is a POST, process it as a password update
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
# This is a VERY important step!
update_session_auth_hash(request, user)
messages.success(request,
'Your password was successfully updated!',
extra_tags='alert-success')
return redirect('profile')
else:
form = PasswordChangeForm(request.user)
return render(request, 'home/profile.html', {
'form': form,
# 'current_user': current_user_name,
# 'user_avatar': current_user_avatar
})
示例8: user_self_service
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def user_self_service(request):
user_fields = []
if settings.USER_SELF_SERVICE.get('CHANGE_EMAIL', True):
user_fields.append('email')
if settings.USER_SELF_SERVICE.get('CHANGE_NAMES', True):
user_fields.extend(('first_name', 'last_name'))
if len(user_fields):
user_form = modelform_factory(User, fields=user_fields)
else:
user_form = False
if settings.USER_SELF_SERVICE.get('CHANGE_PROFILE', True):
profile_form = modelform_factory(Profile, exclude=('user',))
else:
profile_form = False
if request.method == "POST":
post_data = request.POST.dict()
if user_form:
user_data = {field:post_data[field] for field in user_fields if field in post_data}
user_form = user_form(user_data, instance=request.user)
if user_form.is_valid():
user_form.save()
if profile_form:
profile_data = {field:post_data[field] for field in profile_form.base_fields.keys() if field in post_data}
profile_form = profile_form(profile_data, instance=request.user.profile)
if profile_form.is_valid():
profile_form.save()
else:
if user_form:
user_form = user_form(instance=request.user)
if profile_form:
profile_form = profile_form(instance=request.user.profile)
if settings.USER_SELF_SERVICE.get('CHANGE_PASSWORD', True):
password_form = PasswordChangeForm(request.user)
else:
password_form = False
return render(request, 'user/profile.html', {
'user_form': user_form,
'profile_form': profile_form,
'password_form': password_form
})
示例9: user_change_password
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def user_change_password(request):
if not settings.USER_SELF_SERVICE.get('CHANGE_PASSWORD', True):
messages.error(request, "Error: Password change administratively disabled.")
return HttpResponseServerError(dumps({'status': 'error', 'errors': ['password change disabled.',]}),
content_type="application/json")
if request.method == "POST":
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
messages.success(request, "Success! Password updated.")
return HttpResponse(dumps({'status': 'success'}), content_type="application/json")
ret = {'status': 'error', 'errors': form.errors}
messages.error(request, form.errors)
return HttpResponseServerError(dumps(ret), content_type="application/json")
示例10: change_password
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def change_password(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important!
messages.success(request, 'Your password was successfully updated!')
return redirect('/autograde')
else:
form = PasswordChangeForm(request.user)
return render(request, 'account/change_password.html', {
'form': form
})
示例11: password_change
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def password_change(request):
form = PasswordChangeForm(
user=request.user,
data=post_data(request))
if is_post(request) and form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
messages.info(request, _("Your password has been changed!"))
return redirect(reverse('spirit:user:update'))
return render(
request=request,
template_name='spirit/user/profile_password_change.html',
context={'form': form})
示例12: account_settings
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def account_settings(request):
password_change_form = PasswordChangeForm(request.user)
nick_change_form = NickChangeForm(request.user)
email_change_form = EmailChangeForm(request.user)
form = request.POST.get('form')
if form == 'change_pw':
password_change_form = PasswordChangeForm(request.user, request.POST)
if password_change_form.is_valid():
password_change_form.save()
update_session_auth_hash(request, request.user)
messages.success(request, _("Password was changed."))
return redirect('registration_account')
elif form == 'change_nick':
nick_change_form = NickChangeForm(request.user, request.POST)
if nick_change_form.is_valid():
nick_change_form.save()
messages.success(request, _('Your nickname is now {}.').format(
nick_change_form.cleaned_data['nickname']))
return redirect('registration_account')
elif form == 'change_email':
email_change_form = EmailChangeForm(request.user, request.POST)
if email_change_form.is_valid():
return _verify_email(request,
email_change_form.cleaned_data['email'])
return TemplateResponse(request, 'registration/account.html', {
'password_change_form': password_change_form,
'nick_change_form': nick_change_form,
'email_change_form': email_change_form,
'username': request.user.username,
})
示例13: profile
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def profile(request):
if request.method == "POST":
userform = UserForm(request.POST, instance=request.user)
passwordform = PasswordChangeForm(request.user, request.POST)
error = False
if userform.has_changed() and userform.is_valid():
userform.save()
elif not userform.has_changed():
userform = UserForm(instance=request.user)
else:
error = True
if passwordform.has_changed() and passwordform.is_valid():
passwordform.save()
elif not passwordform.has_changed():
passwordform = PasswordChangeForm(user=request.user)
else:
error = True
if not error:
redirect('login')
else:
userform = UserForm(instance=request.user)
passwordform = PasswordChangeForm(user=request.user)
ctx = {
'userform': userform,
'passwordform': passwordform,
}
return render(request, 'profile.html', ctx)
示例14: test_change_password_view
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def test_change_password_view(self):
""" A ``GET`` to the change password view """
self.client.login(username="john", password="blowfish")
response = self.client.get(
reverse("userena_password_change", kwargs={"username": "john"})
)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "userena/password_form.html")
self.assertTrue(response.context["form"], PasswordChangeForm)
示例15: get_context_data
# 需要导入模块: from django.contrib.auth import forms [as 别名]
# 或者: from django.contrib.auth.forms import PasswordChangeForm [as 别名]
def get_context_data(self, **kwargs):
context = super(UserDetailView, self).get_context_data(**kwargs)
context["language_form"] = SetLanguageForm(user=self.request.user)
context["password_form"] = PasswordChangeForm(user=self.request.user)
return context