Browse Source

Finaliza a recuperacao de senha

pull/877/head
Eduardo Calil 8 years ago
committed by Leandro Roberto da Silva
parent
commit
ff785ebf85
  1. 5
      requirements/requirements.txt
  2. 3
      sapl/base/admin.py
  3. 28
      sapl/base/forms.py
  4. 35
      sapl/base/urls.py
  5. 13
      sapl/templates/base/login.html
  6. 14
      sapl/templates/base/recupera_senha_email_enviado.html
  7. 13
      sapl/templates/base/recuperar_senha_email.html
  8. 1
      sapl/templates/base/recuperar_senha_email_form.html

5
requirements/requirements.txt

@ -1,6 +1,9 @@
dj-database-url==0.4.1 dj-database-url==0.4.1
django>=1.9,<1.10 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-bootstrap3==7.0.1
django-bower==5.1.0 django-bower==5.1.0
django-braces==1.9.0 django-braces==1.9.0

3
sapl/base/admin.py

@ -8,6 +8,9 @@ register_all_models_in_admin(__name__)
admin.site.unregister(ProblemaMigracao) admin.site.unregister(ProblemaMigracao)
admin.site.site_title = 'Administração - SAPL'
admin.site.site_header = 'Administração - SAPL'
@admin.register(ProblemaMigracao) @admin.register(ProblemaMigracao)
class ProblemaMigracaoAdmin(admin.ModelAdmin): class ProblemaMigracaoAdmin(admin.ModelAdmin):

28
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 import forms
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm
from django.contrib.auth.models import Group from django.contrib.auth.models import Group, User
from django.contrib.auth.password_validation import validate_password from django.contrib.auth.password_validation import validate_password
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -695,3 +695,27 @@ class ConfiguracoesAppForm(ModelForm):
'texto_articulado_materia', 'texto_articulado_materia',
'texto_articulado_norma', 'texto_articulado_norma',
'proposicao_incorporacao_obrigatoria'] '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

35
sapl/base/urls.py

@ -1,12 +1,17 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib.auth import views 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.contrib.auth.decorators import permission_required
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud
from .apps import AppConfig 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, from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView,
RelatorioAtasView, RelatorioHistoricoTramitacaoView, RelatorioAtasView, RelatorioHistoricoTramitacaoView,
RelatorioMateriasPorAnoAutorTipoView, RelatorioMateriasPorAnoAutorTipoView,
@ -16,6 +21,32 @@ from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView,
app_name = AppConfig.name 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<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',
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 = [ urlpatterns = [
url(r'^sistema/autor/tipo/', include(TipoAutorCrud.get_urls())), url(r'^sistema/autor/tipo/', include(TipoAutorCrud.get_urls())),
@ -66,4 +97,4 @@ urlpatterns = [
name='login'), name='login'),
url(r'^logout/$', views.logout, {'next_page': '/login'}, name='logout'), url(r'^logout/$', views.logout, {'next_page': '/login'}, name='logout'),
] ] + recuperar_senha

13
sapl/templates/base/login.html

@ -18,7 +18,7 @@
<div class="col-md-4 col-md-offset-4"> <div class="col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default"> <div class="login-panel panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Entrar</h3> <h3 class="panel-title"><center>Entrar</center></h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<form id="login-form" method="post" action="{% url 'sapl.base:login' %}"> <form id="login-form" method="post" action="{% url 'sapl.base:login' %}">
@ -32,18 +32,19 @@
{% endif %} {% endif %}
<tr> <tr>
<td><b>Usuário</b></td> <p><b><center>Usuário</center></b></p>
<td>{{ form.username }}</td> {{ form.username }}
</tr> </tr>
<tr> <tr>
<td><b>Senha</b></td> <p><b><center>Senha</center></b></p>
<td>{{ form.password }}</td> {{ form.password }}
</tr> </tr>
</table> </table>
</p> </p>
<h5><a href="{% url 'sapl.base:recuperar_senha_email' %}"><center>Esqueceu sua senha?</center></a></h6>
<p class="bs-component"> <p class="bs-component">
<center> <center>
<input class="btn btn-success btn-sm" type="submit" value="login" /> <input class="btn btn-lg btn-success btn-block" type="submit" value="login" />
</center> </center>
</p> </p>
<input type="hidden" name="next" value="{{ next }}" /> <input type="hidden" name="next" value="{{ next }}" />

14
sapl/templates/base/recupera_senha_email_enviado.html

@ -0,0 +1,14 @@
{% extends "crud/detail.html" %}
{% load i18n crispy_forms_tags %}
{% block base_content %}
<div class="container">
{% csrf_token %}
<div class="row">
<p>Foi enviado um e-mail para o endereço inserido. Verifique-o e siga as instruções.</p>
<p>Caso não receba, procure-o na caixa de spam.</p>
</div>
</div>
{%endblock%}

13
sapl/templates/base/recuperar_senha_email.html

@ -0,0 +1,13 @@
<p>Você está recebendo este e-mail pois solicitou recuperação de senha de sua conta no site <b>SAPL</b>.</p></br></p>
<p>Por favor clique no link a seguir e redefina sua senha:</p></br>
<p><a href="{{ protocol }}://{{ domain }}{% url 'sapl.base:recuperar_senha_confirma' uidb64=uid token=token %}">
Clique aqui</a></p></br>.
<p>Caso não tenha solicitado a alteração de sua senha, favor ignorar este e-mail.</p></br>
<p>Atenciosamente,</p>
<p>A equipe <b>SAPL</b></p>

1
sapl/templates/base/recuperar_senha_email_form.html

@ -0,0 +1 @@
{% extends "crud/form.html" %}
Loading…
Cancel
Save