diff --git a/requirements/requirements.txt b/requirements/requirements.txt index c99b8303c..c6e9f2266 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,6 +1,9 @@ dj-database-url==0.4.1 django>=1.9,<1.10 -django-admin-bootstrapped==2.5.7 +# TODO O django-admin-bootstrapped 2.5.7 não inseriu a mudança que permite +# a compatibilidade com Django 1.9+. A linha abaixo será mudada quando uma +# nova versão do django-admin-bootstrapped for lançada +git+git://github.com/django-admin-bootstrapped/django-admin-bootstrapped.git django-bootstrap3==7.0.1 django-bower==5.1.0 django-braces==1.9.0 diff --git a/sapl/base/admin.py b/sapl/base/admin.py index ae581e031..02ccd3c60 100644 --- a/sapl/base/admin.py +++ b/sapl/base/admin.py @@ -8,6 +8,9 @@ register_all_models_in_admin(__name__) admin.site.unregister(ProblemaMigracao) +admin.site.site_title = 'Administração - SAPL' +admin.site.site_header = 'Administração - SAPL' + @admin.register(ProblemaMigracao) class ProblemaMigracaoAdmin(admin.ModelAdmin): diff --git a/sapl/base/forms.py b/sapl/base/forms.py index ea30726ae..98a567261 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -4,8 +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 -from django.contrib.auth.models import Group +from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm +from django.contrib.auth.models import Group, User from django.contrib.auth.password_validation import validate_password from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError @@ -695,3 +695,27 @@ class ConfiguracoesAppForm(ModelForm): 'texto_articulado_materia', 'texto_articulado_norma', 'proposicao_incorporacao_obrigatoria'] + + +class RecuperarSenhaForm(PasswordResetForm): + def __init__(self, *args, **kwargs): + row1 = to_row( + [('email', 12)]) + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset(_('Insira o e-mail cadastrado com a sua conta'), + row1, + form_actions(save_label='Enviar')) + ) + + super(RecuperarSenhaForm, self).__init__(*args, **kwargs) + + def clean(self): + email_existente = User.objects.filter( + email=self.data['email']).exists() + + if not email_existente: + msg = 'Não existe nenhum usuário cadastrado com este e-mail.' + raise ValidationError(msg) + + return self.cleaned_data diff --git a/sapl/base/urls.py b/sapl/base/urls.py index c2a9fdc4a..6a0473612 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -1,12 +1,17 @@ from django.conf.urls import include, url from django.contrib.auth import views +from django.contrib.auth.views import (password_reset, + password_reset_done, + password_reset_confirm, + password_reset_complete) from django.contrib.auth.decorators import permission_required from django.views.generic.base import TemplateView from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud from .apps import AppConfig -from .forms import LoginForm +from .forms import LoginForm, RecuperarSenhaForm +from sapl.settings import EMAIL_SEND_USER from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView, RelatorioAtasView, RelatorioHistoricoTramitacaoView, RelatorioMateriasPorAnoAutorTipoView, @@ -16,6 +21,32 @@ from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView, app_name = AppConfig.name +recuperar_senha = [ + url(r'^recuperar-senha/email/$', + password_reset, + {'post_reset_redirect': 'sapl.base:recuperar_senha_finalizado', + 'email_template_name': 'base/recuperar_senha_email.html', + 'html_email_template_name': 'base/recuperar_senha_email.html', + 'template_name': 'base/recuperar_senha_email_form.html', + 'from_email': EMAIL_SEND_USER, + 'password_reset_form': RecuperarSenhaForm}, + name='recuperar_senha_email'), + + url(r'^recuperar-senha/finalizado/$', + password_reset_done, + {'template_name': 'base/recupera_senha_email_enviado.html'}, + name='recuperar_senha_finalizado'), + + url(r'^recuperar-senha/(?P[0-9A-Za-z_\-]+)/(?P.+)/$', + password_reset_confirm, + {'post_reset_redirect': 'sapl.base:recuperar_senha_completo'}, + name='recuperar_senha_confirma'), + + url(r'^recuperar-senha/completo/$', + password_reset_complete, + name='recuperar_senha_completo'), +] + urlpatterns = [ url(r'^sistema/autor/tipo/', include(TipoAutorCrud.get_urls())), @@ -66,4 +97,4 @@ urlpatterns = [ name='login'), url(r'^logout/$', views.logout, {'next_page': '/login'}, name='logout'), -] +] + recuperar_senha diff --git a/sapl/templates/base/login.html b/sapl/templates/base/login.html index 78450f96a..c2c7aa2c6 100644 --- a/sapl/templates/base/login.html +++ b/sapl/templates/base/login.html @@ -18,7 +18,7 @@