Skip to content

Commit

Permalink
Included the htmls coto#243 Invite User by email workflow
Browse files Browse the repository at this point in the history
Added config and description for coto#251 User location based selection of TnC/AGB
Implemented coto#258 Ask for password reset after activation; does not lead to activation
  • Loading branch information
Sebastiaan van Doorn committed Sep 24, 2013
1 parent ee6f7fe commit 152ad39
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 20 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ Adding or updating text to be translated or adding new languages requires more w
1. Compile translations
Run: <tt>pybabel compile -f -d ./locale</tt>

1. In addition to this locale specific configuration files can be realized by using standard Jinja2 import functionality
For examples see register.html and account_activation.txt
{% include ['tnc-'+ locale_iso.language + '_'+locale_iso.territory+ '.html', 'tnc.html'] ignore missing %}


See [webapp2's tutorial](http://webapp-improved.appspot.com/tutorials/i18n.html) and [pybabel's docs](http://babel.edgewall.org/wiki/Documentation/cmdline.html) for more details.

**Disabling i18n**
Expand Down
36 changes: 24 additions & 12 deletions boilerplate/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ def post(self):
"app_name": self.app.config.get('app_name'),
"username": username,
"confirmation_url": confirmation_url,
"support_url": self.uri_for("contact", _full=True)
"support_url": self.uri_for("contact", _full=True),
"locale_iso": self.locale_iso,
}
body_path = "emails/account_activation.txt"
body = self.jinja2.render_template(body_path, **template_val)
Expand Down Expand Up @@ -1163,7 +1164,9 @@ def get(self, user_id, token):
"app_name": self.app.config.get('app_name'),
"username": user.username,
"confirmation_url": confirmation_url,
"support_url": self.uri_for("contact", _full=True)
"support_url": self.uri_for("contact", _full=True),
"locale_iso": self.locale_iso,

}
body_path = "emails/account_activation.txt"
body = self.jinja2.render_template(body_path, **template_val)
Expand Down Expand Up @@ -1432,7 +1435,7 @@ def post(self):
"first_name": user.name,
"username": user.username,
"email": user.email,
"reset_password_url": self.uri_for("password-reset", _full=True)
"verification_url": self.uri_for("password-reset", _full=True)
}
email_body_path = "emails/password_changed.txt"
email_body = self.jinja2.render_template(email_body_path, **template_val)
Expand Down Expand Up @@ -1635,28 +1638,37 @@ def post(self):
user_id = user.get_id()
token = models.User.create_auth_token(user_id)
email_url = self.uri_for('taskqueue-send-email')
reset_url = self.uri_for('password-reset-check', user_id=user_id, token=token, _full=True)
subject = _("%s Password Assistance" % self.app.config.get('app_name'))

if (user.activated == False):
subject = _("%s Account Verification" % self.app.config.get('app_name'))
verification_url = self.uri_for("account-activation",user_id=user_id,token=token,_full=True)
body_path = "emails/account_activation.txt"
else:
subject = _("%s Password Assistance" % self.app.config.get('app_name'))
verification_url = self.uri_for('password-reset-check', user_id=user_id, token=token, _full=True)
body_path = "emails/reset_password.txt"

# load email's template
template_val = {
"app_name": self.app.config.get('app_name'),
"username": user.username,
"email": user.email,
"reset_password_url": reset_url,
"verification_url": verification_url,
"support_url": self.uri_for("contact", _full=True),
"app_name": self.app.config.get('app_name'),
"locale_iso": self.locale_iso,
}

body_path = "emails/reset_password.txt"

body = self.jinja2.render_template(body_path, **template_val)
message = _('The verification email has been resent to %s. '
'Please check your email to activate your account.' % user.email)
self.add_message(message, 'success')
taskqueue.add(url=email_url, params={
'to': user.email,
'subject': subject,
'body': body,
'sender': self.app.config.get('contact_sender'),
})
self.add_message(_message, 'warning')
return self.redirect_to('login')
return self.redirect_to('home')


class PasswordResetCompleteHandler(BaseHandler):
Expand Down
8 changes: 6 additions & 2 deletions boilerplate/lib/basehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, request, response):
"""
self.initialize(request, response)
self.locale = i18n.set_locale(self)
self.view = ViewClass()
self.view = ViewClass()

def dispatch(self):
"""
Expand Down Expand Up @@ -124,6 +124,10 @@ def auth_config(self):
def language(self):
return str(Locale.parse(self.locale).language)

@webapp2.cached_property
def locale_iso(self):
return Locale.parse(self.locale)

@webapp2.cached_property
def user(self):
return self.auth.get_user_by_session()
Expand Down Expand Up @@ -283,7 +287,7 @@ def render_template(self, filename, **kwargs):
territory_id = locale_iso.territory
language = locale_iso.languages[language_id]
territory = locale_iso.territories[territory_id]

# make all self.view variables available in jinja2 templates
if hasattr(self, 'view'):
kwargs.update(self.view.__dict__)
Expand Down
13 changes: 9 additions & 4 deletions boilerplate/templates/emails/account_activation.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<p>Hello <strong>{{username}}</strong>,</p>

<p>
You just have registered in {{ app_name }} as @{{username}}. In order to activate your account,
please verify your email by clicking this link:
You just have registered in {{ app_name }} as @{{username}}. By activating your account you acknowledge to have read
and accepted our terms and conditions as shown at the end of this email.


In order to activate your account, please verify your email by clicking the following link:
</p>

{{confirmation_url}}
{{verification_url}}

<p>
If you have any question, please do not hesitate to contact us at:</br>
{{support_url}}
</p>

<p>Sincerely,<br>
{{ app_name }} Team
{{ app_name }} Team

{% include ['tnc-'+ locale_iso.language + '_'+locale_iso.territory+ '.html', 'tnc.html'] ignore missing %}
16 changes: 16 additions & 0 deletions boilerplate/templates/emails/account_invite.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p>Hello <strong>{{email}}</strong>,</p>

<p>
You just have been invited to {{ app_name }} as @{{username}}. In order to activate your account,
please verify your email by clicking this link:
</p>

{{confirmation_url}}

<p>
If you have any question, please do not hesitate to contact us at:</br>
{{support_url}}
</p>

<p>Sincerely,<br>
{{ app_name }} Team
2 changes: 1 addition & 1 deletion boilerplate/templates/emails/password_changed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ was recently changed. As a security precaution, this notification has been sent

<p>If you didn't change your password, your account might have been hijacked.
Please follow the link to regain control over your account:</p>
{{reset_password_url}}
{{verification_url}}

<p><strong>Important account security tips:</strong></p>
<p>
Expand Down
2 changes: 1 addition & 1 deletion boilerplate/templates/emails/reset_password.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<p>To initiate the password reset process for your {{ app_name }} Account ({{email}}), click the link below:</p>

{{reset_password_url}}
{{verification_url}}

<p>If clicking the link above doesn't work, please copy and paste the URL in a new browser window instead.</p>

Expand Down
36 changes: 36 additions & 0 deletions boilerplate/templates/invite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends base_layout %}

{% block header_title %}
{% trans %}Invite User{% endtrans %}
{% endblock %}

{% block content %}

<form id="form_invite" action="{{ url|safe }}" method="post" class="well form-horizontal">
<fieldset>
<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
{{ macros.field(form.username, label=_("Username"), placeholder=_("Enter a")+" "+_("Username"), class="input-xlarge focused required") }}
{{ macros.field(form.email, label=_("Email"), placeholder=_("Enter their")+" "+_("Email"), class="input-xlarge focused required email", type="email") }}
<div class="form-actions">
<button type="submit" class="btn btn-primary">{% trans %}Send Invite{% endtrans %}</button>
</div>
</fieldset>
</form>

{% endblock %}

{% block mediaJS %}
<script type="text/javascript">
$().ready(function() {
$("#form_invite").validate({
submitHandler: function(form) {
form.submit();
},
errorPlacement: function(error, element) {
element.parent().parent().addClass("error");
error.addClass("help-inline").appendTo( element.parent() );
}
});
});
</script>
{% endblock %}
54 changes: 54 additions & 0 deletions boilerplate/templates/invite_activate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{% extends base_layout %}

{% block header_title %}
{% trans %}Set your password{% endtrans %}
{% endblock %}

{% block content %}

<form id="form_edit_password" action="{{ url|safe }}" method="post" class="well form-horizontal">
<fieldset>
<input type="hidden" name="_csrf_token" value="{{ csrf_token() }}">
{{ macros.field(form.password, label=_("New Password"), placeholder=_("Enter your")+" "+_("New Password"), class="input-xlarge focused required", type="password") }}
{% if not is_mobile %}
{{ macros.field(form.c_password, label=_("Confirm Password"), placeholder=_("Confirm Password"), class="input-xlarge focused required", type="password") }}
{% endif %}
{{ macros.field(form.name, label=_("Name"), placeholder=_("Enter your")+" "+_("Name"), class="input-xlarge focused") }}
{{ macros.field(form.last_name, label=_("Last Name"), placeholder=_("Enter your")+" "+_("Last Name"), class="input-xlarge focused") }}
{{ macros.field(form.country, label=_("Country")) }}
<div class="form-actions">
<button type="submit" class="btn btn-primary">{% trans %}Set password{% endtrans %}</button>
</div>
</fieldset>
</form>

{% endblock %}

{% block mediaJS %}
<script type="text/javascript">
$().ready(function() {
$("#form_edit_password").validate({
submitHandler: function(form) {
form.submit();
},
rules: {
password: 'required',
c_password: {
required: true,
equalTo: '#password'
}
},
errorPlacement: function(error, element) {
element.parent().parent().addClass("error");
error.addClass("help-inline").appendTo( element.parent() );
}
});
$("#password").passStrength({
shortPassText: '{% trans %}Short Password{% endtrans %}',
badPassText: '{% trans %}Insecure Password{% endtrans %}',
goodPassText: '{% trans %}Good Password{% endtrans %}',
strongPassText: '{% trans %}Secure Password{% endtrans %}'
});
});
</script>
{% endblock %}
2 changes: 2 additions & 0 deletions boilerplate/templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
</fieldset>
</form>

{% include ['tnc-'+ locale_iso.language + '_'+locale_iso.territory+ '.html', 'tnc.html'] ignore missing %}

{% endblock %}

{% block mediaJS %}
Expand Down
2 changes: 2 additions & 0 deletions boilerplate/templates/tnc-de_DE.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Wenn Sie sich auf diese Seite registrieren, best&auml;tigen Sie dass Sie unsere AGB gelesen haben, und sie akzeptieren.
<H2>Das sind die de_DE AGB</H2>
2 changes: 2 additions & 0 deletions boilerplate/templates/tnc-en_US.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
By registering with this website you acknowledge that you have read and accepted the following terms and conditions
<H2>These are the en_US terms and conditions</H2>
2 changes: 2 additions & 0 deletions boilerplate/templates/tnc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
By registering with this website you acknowledge that you have read and accepted the following terms and conditions
<H2>These are the default terms and conditions</H2>

0 comments on commit 152ad39

Please sign in to comment.