From d1b2cdc04aaddacc28bbbbc8ed741d98c9200e0b Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Thu, 15 Dec 2016 10:38:25 -0200 Subject: [PATCH] =?UTF-8?q?Faz=20mudan=C3=A7as=20sugeridas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/forms.py | 18 ++++++++++++++++- sapl/base/urls.py | 7 +++++-- sapl/templates/base/nova_senha_form.html | 1 + .../base/recuperar_senha_completo.html | 5 +++++ .../templates/base/recuperar_senha_email.html | 2 +- sapl/test_urls.py | 20 +++++++------------ 6 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 sapl/templates/base/nova_senha_form.html create mode 100644 sapl/templates/base/recuperar_senha_completo.html diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 98a567261..7f1eef180 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -4,7 +4,8 @@ from crispy_forms.layout import HTML, Button, Div, Field, Fieldset, Layout, Row from django import forms from django.conf import settings from django.contrib.auth import get_user_model -from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm +from django.contrib.auth.forms import (AuthenticationForm, PasswordResetForm, + SetPasswordForm) from django.contrib.auth.models import Group, User from django.contrib.auth.password_validation import validate_password from django.contrib.contenttypes.models import ContentType @@ -719,3 +720,18 @@ class RecuperarSenhaForm(PasswordResetForm): raise ValidationError(msg) return self.cleaned_data + + +class NovaSenhaForm(SetPasswordForm): + def __init__(self, user, *args, **kwargs): + self.user = user + super(NovaSenhaForm, self).__init__(user, *args, **kwargs) + + row1 = to_row( + [('new_password1', 6), + ('new_password2', 6)]) + + self.helper = FormHelper() + self.helper.layout = Layout( + row1, + form_actions(save_label='Enviar')) diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 6a0473612..08f456f3b 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -10,7 +10,7 @@ from django.views.generic.base import TemplateView from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud from .apps import AppConfig -from .forms import LoginForm, RecuperarSenhaForm +from .forms import LoginForm, NovaSenhaForm, RecuperarSenhaForm from sapl.settings import EMAIL_SEND_USER from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView, RelatorioAtasView, RelatorioHistoricoTramitacaoView, @@ -39,11 +39,14 @@ recuperar_senha = [ url(r'^recuperar-senha/(?P[0-9A-Za-z_\-]+)/(?P.+)/$', password_reset_confirm, - {'post_reset_redirect': 'sapl.base:recuperar_senha_completo'}, + {'post_reset_redirect': 'sapl.base:recuperar_senha_completo', + 'template_name': 'base/nova_senha_form.html', + 'set_password_form': NovaSenhaForm}, name='recuperar_senha_confirma'), url(r'^recuperar-senha/completo/$', password_reset_complete, + {'template_name': 'base/recuperar_senha_completo.html'}, name='recuperar_senha_completo'), ] diff --git a/sapl/templates/base/nova_senha_form.html b/sapl/templates/base/nova_senha_form.html new file mode 100644 index 000000000..9dd798df0 --- /dev/null +++ b/sapl/templates/base/nova_senha_form.html @@ -0,0 +1 @@ +{% extends "crud/form.html" %} diff --git a/sapl/templates/base/recuperar_senha_completo.html b/sapl/templates/base/recuperar_senha_completo.html new file mode 100644 index 000000000..05f796e5f --- /dev/null +++ b/sapl/templates/base/recuperar_senha_completo.html @@ -0,0 +1,5 @@ +{% extends "crud/detail.html" %} + +{% block table_content %} +A sua senha foi alterada com sucesso! Clique aqui e faça seu login. +{% endblock %} \ No newline at end of file diff --git a/sapl/templates/base/recuperar_senha_email.html b/sapl/templates/base/recuperar_senha_email.html index 09debe699..e6ac318a1 100644 --- a/sapl/templates/base/recuperar_senha_email.html +++ b/sapl/templates/base/recuperar_senha_email.html @@ -4,7 +4,7 @@

-Clique aqui


. +Clique aqui


Caso não tenha solicitado a alteração de sua senha, favor ignorar este e-mail.


diff --git a/sapl/test_urls.py b/sapl/test_urls.py index 2dda9cce6..a8df77d13 100644 --- a/sapl/test_urls.py +++ b/sapl/test_urls.py @@ -145,6 +145,7 @@ def test_crudaux_list_do_crud_esta_na_pagina_sistema(url_item, admin_client): Se encontra em %s.urls """ % (url, app_name) + apps_url_patterns_prefixs_and_users = { 'api': { 'prefixs': [ @@ -158,6 +159,7 @@ apps_url_patterns_prefixs_and_users = { '/logout', '/ajuda', '/email', + '/recuperar-senha' ]}, 'comissoes': { 'users': {'operador_geral': ['/sistema', '/comissao'], @@ -235,13 +237,6 @@ apps_url_patterns_prefixs_and_users = { @pytest.mark.parametrize('url_item', _lista_urls) def test_urlpatterns(url_item, admin_client): - urls_reset_password = [ - '/recuperar-senha/1/1/', - '/recuperar-senha/completo/', - '/recuperar-senha/email/', - '/recuperar-senha/finalizado/', - ] - key, url, var, app_name = url_item url = '/' + (url % {v: 1 for v in var}) @@ -264,12 +259,11 @@ def test_urlpatterns(url_item, admin_client): isvalid = True break - if url not in urls_reset_password: - assert isvalid, """ - O prefixo da url (%s) não está no padrão de sua app (%s). - Os prefixos permitidos são: - %s - """ % (url, app_name, prefixs) + assert isvalid, """ + O prefixo da url (%s) não está no padrão de sua app (%s). + Os prefixos permitidos são: + %s + """ % (url, app_name, prefixs) urls_publicas_excecoes = {