本文整理汇总了Python中django.contrib.auth.forms.AdminPasswordChangeForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python AdminPasswordChangeForm.is_valid方法的具体用法?Python AdminPasswordChangeForm.is_valid怎么用?Python AdminPasswordChangeForm.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.AdminPasswordChangeForm
的用法示例。
在下文中一共展示了AdminPasswordChangeForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: recover_pass
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def recover_pass(request):
if Perfil.objects.filter(code_activation = request.GET['code']):
perfil = Perfil.objects.get(code_activation = request.GET['code'])
usuario = User.objects.get(id = perfil.usuario_id)
categorias = Categorias.objects.all()
envio = perfil.time + timedelta(hours=2)
hoy = datetime.now()
if envio.strftime("%Y-%m-%d %H:%M") >= hoy.strftime("%Y-%m-%d %H:%M"):
if request.method == 'POST':
formulario = AdminPasswordChangeForm(user=usuario, data=request.POST)
if formulario.is_valid():
formulario.save()
perfil.code_activation += usuario.username
perfil.save()
sms = "Contraseña Cambiada Correctamente"
messages.success(request, sms)
return HttpResponseRedirect(reverse(loguet_in))
else:
formulario = AdminPasswordChangeForm(user=usuario)
return render(request, 'users/change_pass.html', {
'formulario':formulario,
'categorias':categorias,
})
else:
sms = "El Enlace ya expiro por favor solicite uno nuevo"
messages.error(request, sms, 'danger')
return HttpResponseRedirect(reverse(sent_code_reset_pass))
else:
sms = "Enlace no Valido"
messages.error(request, sms, 'danger')
return HttpResponseRedirect(reverse(sent_code_reset_pass))
示例2: test_password_whitespace_not_stripped
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def test_password_whitespace_not_stripped(self):
user = User.objects.get(username="testclient")
data = {"password1": " pass ", "password2": " pass "}
form = AdminPasswordChangeForm(user, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data["password1"], data["password1"])
self.assertEqual(form.cleaned_data["password2"], data["password2"])
示例3: user_change_password
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def user_change_password(request, id):
if not request.user.has_perm('auth.change_user'):
raise PermissionDenied
user = get_object_or_404(User, pk=id)
if request.method == 'POST':
form = AdminPasswordChangeForm(user, request.POST)
if form.is_valid():
new_user = form.save()
msg = _('Password changed successfully.')
request.user.message_set.create(message=msg)
return HttpResponseRedirect('..')
else:
form = AdminPasswordChangeForm(user)
return render_to_response('admin/auth/user/change_password.html', {
'title': _('Change password: %s') % escape(user.username),
'form': form,
'is_popup': '_popup' in request.REQUEST,
'add': True,
'change': False,
'has_delete_permission': False,
'has_change_permission': True,
'has_absolute_url': False,
'opts': User._meta,
'original': user,
'show_save': True,
}, context_instance=RequestContext(request))
示例4: user_recoverpass
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def user_recoverpass(request, user_id, code):
if ActivationCode.objects.filter(user_id = user_id, state = True, code = code, description='Reset Pass'):
activation = ActivationCode.objects.get(user_id = user_id, state = True, code = code, description='Reset Pass')
user = User.objects.get(id = user_id)
envio = activation.send_time + timedelta(hours=24)
today = datetime.now()
if envio.strftime("%Y-%m-%d %H:%M") >= today.strftime("%Y-%m-%d %H:%M"):
if request.method == 'POST':
form = AdminPasswordChangeForm(user=user, data=request.POST)
if form.is_valid():
form.save()
activation.state = False
activation.save()
sms = "Contraseña Cambiada Correctamente"
messages.success(request, sms)
return HttpResponseRedirect(reverse(user_login))
else:
form = AdminPasswordChangeForm(user=user)
return render(request, 'users/reset_pass.html', {
'form':form,
})
else:
sms = "El Enlace ya expiro por favor solicite uno nuevo"
messages.error(request, sms, 'danger')
return HttpResponseRedirect(reverse(user-user-user_sendcoderesetpass))
else:
sms = "Enlace no Valido"
messages.error(request, sms, 'danger')
return HttpResponseRedirect('/')
示例5: password_nuevo
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def password_nuevo(request):
algo=""
if request.method == 'POST' :
formulario2=newpass(request.POST)
if formulario2.is_valid():
contrasena=request.POST['actual_password']
usuario=request.user
acceso=authenticate(username=usuario,password=contrasena)
if acceso is not None:
formulario = AdminPasswordChangeForm(user=usuario, data=request.POST)
if formulario.is_valid():
formulario.save()
logout(request)
return HttpResponseRedirect("/db/menu/loginlink/")
pass
else:
formulario = AdminPasswordChangeForm(user=request.user)
formulario2 = newpass()
algo="Las contrasena actual no es la misma"
return render_to_response('repassword.html', {'formulario' :formulario, "formulario2": formulario2, "algo": algo}, context_instance=RequestContext(request))
pass
else:
formulario = AdminPasswordChangeForm(user=request.user)
formulario2 = newpass()
return render_to_response('repassword.html', {'formulario' :formulario, "formulario2": formulario2}, context_instance=RequestContext(request))
示例6: reset_pass
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def reset_pass(request):
if request.method == 'POST' :
formulario = AdminPasswordChangeForm(user=request.user, data=request.POST)
if formulario.is_valid():
formulario.save()
return HttpResponseRedirect('/user/login')
else:
formulario = AdminPasswordChangeForm(user=request.user)
return render_to_response('user/reset_pass.html', {'formulario' :formulario}, context_instance=RequestContext(request))
示例7: test_success
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def test_success(self, password_changed):
user = User.objects.get(username="testclient")
data = {"password1": "test123", "password2": "test123"}
form = AdminPasswordChangeForm(user, data)
self.assertTrue(form.is_valid())
form.save(commit=False)
self.assertEqual(password_changed.call_count, 0)
form.save()
self.assertEqual(password_changed.call_count, 1)
示例8: test_password_whitespace_not_stripped
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def test_password_whitespace_not_stripped(self):
user = User.objects.get(username='testclient')
data = {
'password1': ' pass ',
'password2': ' pass ',
}
form = AdminPasswordChangeForm(user, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['password1'], data['password1'])
self.assertEqual(form.cleaned_data['password2'], data['password2'])
示例9: modifica_password_utente
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def modifica_password_utente(request,utente_id):
user = User.objects.get(id=utente_id)
if request.method == 'POST': # If the form has been submitted...
form = AdminPasswordChangeForm(user=user, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/utenti/') # Redirect after POST
else:
form = AdminPasswordChangeForm(user=user)
return render(request,'form_password_utente.html',{'request':request, 'form': form, 'user': user,})
示例10: password_change
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def password_change(req):
user_to_edit = User.objects.get(id=req.user.id)
if req.method == 'POST':
password_form = AdminPasswordChangeForm(user_to_edit, req.POST)
if password_form.is_valid():
password_form.save()
return HttpResponseRedirect('/')
else:
password_form = AdminPasswordChangeForm(user_to_edit)
template_name="password_change.html"
return render_to_response(req, template_name, {"form" : password_form})
示例11: cambiar_password
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def cambiar_password(request):
if request.method == 'POST' :
formulario = AdminPasswordChangeForm(user=request.user, data=request.POST)
if formulario.is_valid():
formulario.save()
return HttpResponseRedirect(reverse(iniciar_sesion))
else:
formulario = AdminPasswordChangeForm(user=request.user)
return render(request, 'users/reset_pass.html', {
'formulario' :formulario,
})
示例12: user_changepassword
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def user_changepassword(request):
if request.method == 'POST' :
form = AdminPasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse(user_notification))
else:
form= AdminPasswordChangeForm(user=request.user)
return render(request, 'users/change_pass.html', {
'form' :form,
})
示例13: password_change
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def password_change(req, id):
user_to_edit = User.objects.get(id=id)
print req.user
if req.method == "POST":
password_form = AdminPasswordChangeForm(user_to_edit, req.POST)
if password_form.is_valid():
password_form.save()
return HttpResponseRedirect("/iavi/users/%s/edit" % user_to_edit.id)
else:
password_form = AdminPasswordChangeForm(user_to_edit)
template_name = "iavi/password_change.html"
return render_to_response(req, template_name, {"current_user": user_to_edit, "form": password_form})
示例14: update_user_password
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def update_user_password(request, user_id):
user = User.objects.get(id=user_id)
if request.method == 'GET':
form = AdminPasswordChangeForm(user, None)
return render_to_response('update_password.html', {'form':form, 'editing':True, 'site_user':user}, context_instance=RequestContext(request))
if request.method == 'POST':
form = AdminPasswordChangeForm(user,request.POST)
if form.is_valid():
form.save()
return redirect(reverse_lazy('users:edit_user',kwargs={'user_id':str(user.id)}))
return render_to_response('update_password.html', {'form':form, 'editing':True, 'site_user':user}, context_instance=RequestContext(request))
示例15: reset_pass
# 需要导入模块: from django.contrib.auth.forms import AdminPasswordChangeForm [as 别名]
# 或者: from django.contrib.auth.forms.AdminPasswordChangeForm import is_valid [as 别名]
def reset_pass(request):
perfil = Perfil.objects.get(usuario = request.user)
if request.method == 'POST' :
formulario = AdminPasswordChangeForm(user=request.user, data=request.POST)
if formulario.is_valid():
formulario.save()
return HttpResponseRedirect(reverse(loguet_in))
else:
formulario = AdminPasswordChangeForm(user=request.user)
return render(request, 'users/reset_pass.html', {
'formulario' :formulario,
'perfil':perfil,
})