Skip to content

Commit

Permalink
Fix password recovery and add an \!important
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiommendes committed Dec 11, 2018
1 parent 9892160 commit 4520445
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 40 deletions.
20 changes: 10 additions & 10 deletions src/ej/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import logging

from boogie.configurations import DjangoConf, env
from .apps import InstalledAppsConf
from .celery import CeleryConf
from .constance import ConstanceConf
from .email import EmailConf
from .log import LoggingConf
from .middleware import MiddlewareConf
from .options import EjOptions
from .paths import PathsConf
from .security import SecurityConf
from .themes import ThemesConf
from .email import EmailConf
from .. import fixes

log = logging.getLogger('ej')
Expand All @@ -36,7 +37,6 @@ class Conf(ThemesConf,
USING_DOCKER = env(False, name='USING_DOCKER')
HOSTNAME = env('localhost')


#
# Accounts
#
Expand Down Expand Up @@ -94,14 +94,14 @@ class Conf(ThemesConf,

# Use this variable to change the ej environment during the docker build step.
ENVIRONMENT = 'local'

if (ENVIRONMENT == 'production'):
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend';
# the api key will be informed during the docker build step.
ANYMAIL = {'MAILGUN_API_KEY': ''};
DEFAULT_FROM_EMAIL = "Empurrando Juntos <[email protected]>"
HOSTNAME = 'https://ejplatform.org'

DEFAULT_FROM_EMAIL = "Empurrando Juntos <[email protected]>"

def get_email_backend(self):
if self.ENVIRONMENT == 'production':
self.ANYMAIL = {'MAILGUN_API_KEY': ''}
return 'anymail.backends.mailgun.EmailBackend'
else:
return 'django.core.mail.backends.console.EmailBackend'


Conf.save_settings(globals())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endmacro %}

{% macro conversation_list_static(conversations, title, subtitle, caller_output=None) %}
<div class="ConversationList CenteredContainer">
<div class="ConversationList">
<div class="ConversationList-title">
<h1>{{ title }}</h1>
<p>{{ subtitle }}</p>
Expand Down
3 changes: 2 additions & 1 deletion src/ej_users/jinja2/ej_users/login.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

{% block content %}
<style>.Header-lowerNotLogged {
display: none;
/* Important not keep this! */
display: none !important;
}</style>

<div class="Login">
Expand Down
14 changes: 5 additions & 9 deletions src/ej_users/jinja2/ej_users/recover-password-message.jinja2
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{% block content %}
{{_(
"Hello !
You can use the following link to reset your password:
{{ link }}
Thanks,
Your friends at Empurrando Juntos."
)}}
{% endblock %}
{{ _('Hello!') }}

{{ gettext('You can use the following link to reset your password: %(url)s.', url=url) }}

{{ _('Thanks,\nYour friends at Empurrando Juntos.') }}
5 changes: 3 additions & 2 deletions src/ej_users/jinja2/ej_users/register.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

{% block content %}
<style>.Header-lowerNotLogged {
display: none;
/* Important not keep this! */
display: none !important;
}</style>

<div class="Register">
Expand All @@ -17,7 +18,7 @@
{{ field.errors }}
<p>
<input for="{{field.id_for_label}}"
name="{{field.name}}"
name="{{field.name}}"
placeholder="{{field.label}}"
aria-label="{{field.help_text}}"
type="{{field.field.widget.input_type}}"
Expand Down
38 changes: 21 additions & 17 deletions src/ej_users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.http import HttpResponseServerError
from django.shortcuts import redirect
from django.template.loader import get_template
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from rest_framework import status
from rest_framework.authtoken.models import Token
Expand Down Expand Up @@ -137,27 +138,24 @@ def recover_password(request):

if request.method == "POST" and form.is_valid():
success = True
if User.objects.filter(email=form.cleaned_data['email']).exists():
if settings.HOSTNAME == 'localhost':
host = 'http://localhost:8000'
email = form.cleaned_data['email']

else:
host = settings.HOSTNAME

user = User.objects.get_by_email(request.POST['email'])
try:
user = User.objects.get_by_email(email)
except User.DoesNotExist:
pass
else:
token = generate_token(user)
from_email = settings.DEFAULT_FROM_EMAIL
template_message = _recover_password_message(host + '/reset-password/' + token.url)
send_mail(_("Please reset your password"), template_message,
from_email, [request.POST['email']],
fail_silently=False)

return {
'user': user,
'form': form,
'success': success,
path = reverse('auth:reset-password', kwargs={'token': token})
template = get_template('ej_users/recover-password-message.jinja2')
email_body = template.render({'url': raw_url(request, path)}, request=request)
send_mail(subject=_("Please reset your password"),
message=email_body,
from_email=from_email,
recipient_list=[email])

}
return {'user': user, 'form': form, 'success': success}


@urlpatterns.route('profile/remove/', login=True)
Expand Down Expand Up @@ -200,3 +198,9 @@ def _recover_password_message(link):
{link}
Thanks,
Your friends at Empurrando Juntos.""")


def raw_url(request, path):
if not path.startswith('/'):
path = request.path.rstrip('/') + '/' + path
return f'{request.scheme}://{request.get_host()}{path}'

0 comments on commit 4520445

Please sign in to comment.