From 32714afe3043fe7223189f6a08932b186885b029 Mon Sep 17 00:00:00 2001 From: hernani Date: Fri, 4 Jun 2010 01:43:02 +0000 Subject: [PATCH] Converts the welcome message to the new mail system and makes some changes to the newmember notification. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@371 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/actions/user.py | 7 ++- .../templates/auth/email_validation.html | 55 ++++++++++++++----- .../default/templates/notifications/base.html | 7 ++- .../templates/notifications/base_text.html | 8 ++- .../templates/notifications/newmember.html | 4 +- forum/views/auth.py | 16 +----- forum_modules/localauth/views.py | 7 +-- 7 files changed, 64 insertions(+), 40 deletions(-) diff --git a/forum/actions/user.py b/forum/actions/user.py index 6170a17..6c174ce 100644 --- a/forum/actions/user.py +++ b/forum/actions/user.py @@ -1,14 +1,19 @@ from django.utils.translation import ugettext as _ from django.db.models import F from forum.models.action import ActionProxy -from forum.models import Award, Badge +from forum.models import Award, Badge, ValidationHash from forum import settings from forum.settings import APP_SHORT_NAME +from forum.utils.mail import send_email, send_template_email class UserJoinsAction(ActionProxy): def repute_users(self): self.repute(self.user, int(settings.INITIAL_REP)) + def process_action(self): + hash = ValidationHash.objects.create_new(self.user, 'email', [self.user.email]) + send_template_email([self.user], "auth/email_validation.html", {'validation_code': hash}) + def describe(self, viewer=None): return _("%(user)s as joined the %(app_name)s Q&A community") % { 'user': self.hyperlink(self.user.get_profile_url(), self.friendly_username(viewer, self.user)), diff --git a/forum/skins/default/templates/auth/email_validation.html b/forum/skins/default/templates/auth/email_validation.html index 8a2d34f..8746e56 100644 --- a/forum/skins/default/templates/auth/email_validation.html +++ b/forum/skins/default/templates/auth/email_validation.html @@ -1,21 +1,46 @@ -{% extends "email_base.html" %} -{% load i18n %} -{% load extra_tags %} -{% load email_tags %} +{% load i18n extra_tags email_tags %} -{% block content %} -

{% trans "Greetings from the Q&A forum" %},

+{% declare %} + prefix = settings.EMAIL_SUBJECT_PREFIX + app_name = settings.APP_SHORT_NAME -

{% trans "To make use of the Forum, please follow the link below:" %}

+ exclude_greeting = True + exclude_finetune = True +{% enddeclare %} - {% fullurl auth_validate_email user=user.id,code=validation_code %} +{% email %} + {% subject %}{% blocktrans %}{{ prefix }} Welcome to {{ app_name }}{% endblocktrans %}{% endsubject %} -

{% trans "Following the link above will help us verify your email address." %}

+ {% htmlcontent notifications/base.html %} +

+ {% blocktrans %}Howdy and welcome to {{ app_name }}. We know you're busy, so we'll keep this real simple.{% endblocktrans %} %}, +

-

{% blocktrans %}If you beleive that this message was sent in mistake - - no further action is needed. Just ingore this email, we apologize - for any inconvenience{% endblocktrans %}

+

{% trans "Here's your login info (store it in a cool dry place):" %}

+ +

{% trans "Username: " %} {{ recipient.username }}
+ {% trans "Password: As IF we would send your password in cleartext!" %}

+ +

{% trans "The following link will help us verify your email address:" %}

+ + {% trans "Validate my email address" %} + +

{% trans "If the above link is not clickable, copy and paste this url into your web browser's address bar:" %}

+ +

{% fullurl auth_validate_email user=recipient.id,code=validation_code %}

+ {% endhtmlcontent %} + +{% textcontent notifications/base_text.html %} +{% blocktrans %}Howdy and welcome to {{ app_name }}. We know you're busy, so we'll keep this real simple.{% endblocktrans %} %}, +{% trans "Here's your login info (store it in a cool dry place):" %} + +{% trans "Username: " %} {{ recipient.username }} +{% trans "Password: As IF we would send your password in cleartext!" %} + +{% trans "Copy and paste this url into your web browser's address bar to help us verify your email address:" %} + +{% fullurl auth_validate_email user=recipient.id,code=validation_code %} +{% endtextcontent %} + +{% endemail %} -

{% blocktrans %}Sincerely,
- Forum Administrator{% endblocktrans %}

-{% endblock %} diff --git a/forum/skins/default/templates/notifications/base.html b/forum/skins/default/templates/notifications/base.html index 05de03f..9d09f59 100644 --- a/forum/skins/default/templates/notifications/base.html +++ b/forum/skins/default/templates/notifications/base.html @@ -16,12 +16,15 @@ {{settings.APP_TITLE}}
+{% if not exclude_greeting %}

{% trans "Hello" %} {{ recipient.username }},

-{% block content %} -{% endblock%} +{% endif %} +{% block content %}{% endblock%}

Thanks,
{{settings.APP_SHORT_NAME}}

+{% if not exclude_finetune %}

P.S. You can always fine-tune which notifications you receive here. +{% endif %}


{{ settings.EMAIL_FOOTER_TEXT }}

diff --git a/forum/skins/default/templates/notifications/base_text.html b/forum/skins/default/templates/notifications/base_text.html index 8d31c30..113e5fd 100644 --- a/forum/skins/default/templates/notifications/base_text.html +++ b/forum/skins/default/templates/notifications/base_text.html @@ -3,16 +3,18 @@ {% declare %} postal_address = "DZone, Inc. 140 Preston Executive Drive, Cary NC 27513, USA" {% enddeclare %} - +{% if not exclude_greeting %} {% trans "Hello" %} {{ recipient.username }}, +{% endif %} -{% block content %} -{% endblock%} +{% block content %}{% endblock%} {% trans "Thanks" %}, {{settings.APP_SHORT_NAME}} +{% if not exclude_finetune %} {% trans "P.S. You can always fine-tune which notifications you receive here:" %} {{ settings.APP_URL }}{% url user_subscriptions id=recipient.id %} +{% endif %} {{ postal_address }} \ No newline at end of file diff --git a/forum/skins/default/templates/notifications/newmember.html b/forum/skins/default/templates/notifications/newmember.html index 67fba1f..e189e3d 100644 --- a/forum/skins/default/templates/notifications/newmember.html +++ b/forum/skins/default/templates/notifications/newmember.html @@ -15,8 +15,8 @@ {% htmlcontent notifications/base.html %}

{% blocktrans %} - {{ newmember_link }} has just joined {{ app_name }}. You can visit {{ newmember_name }}'s profile using the following link:
- {{ newmember_name }} profile + {{ newmember_link }} has just joined {{ app_name }}. + View {{ newmember_name }}'s profile. {% endblocktrans %}

{% endhtmlcontent %} diff --git a/forum/views/auth.py b/forum/views/auth.py index d321c95..442bf01 100644 --- a/forum/views/auth.py +++ b/forum/views/auth.py @@ -14,7 +14,7 @@ import datetime from forum.authentication.forms import SimpleRegistrationForm, SimpleEmailSubscribeForm, \ TemporaryLoginRequestForm, ChangePasswordForm, SetPasswordForm -from forum.utils.mail import send_email +from forum.utils.mail import send_email, send_template_email from forum.authentication.base import InvalidAuthentication from forum.authentication import AUTH_PROVIDERS @@ -152,9 +152,6 @@ def external_register(request): user_.save() UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save() - if not user_.email_isvalid: - send_validation_email(user_) - try: assoc_key = request.session['assoc_key'] auth_provider = request.session['auth_provider'] @@ -172,7 +169,7 @@ def external_register(request): del request.session['assoc_key'] del request.session['auth_provider'] - return login_and_forward(request, user_) + return login_and_forward(request, user_, _("A welcome email has been sent to your email address. ")) else: provider_class = AUTH_PROVIDERS[request.session['auth_provider']].consumer user_data = provider_class.get_user_data(request.session['assoc_key']) @@ -241,14 +238,7 @@ def temp_signin(request, user, code): _("You are logged in with a temporary access key, please take the time to fix your issue with authentication.")) else: raise Http404() - -def send_validation_email(user): - hash = ValidationHash.objects.create_new(user, 'email', [user.email]) - send_email(_("Email Validation"), [(user.username, user.email)], "auth/email_validation.html", { - 'validation_code': hash, - 'user': user - }) - + def validate_email(request, user, code): user = get_object_or_404(User, id=user) diff --git a/forum_modules/localauth/views.py b/forum_modules/localauth/views.py index 8df278c..6416fee 100644 --- a/forum_modules/localauth/views.py +++ b/forum_modules/localauth/views.py @@ -5,7 +5,7 @@ from django.utils.translation import ugettext as _ from forms import ClassicRegisterForm from forum.authentication.forms import SimpleEmailSubscribeForm -from forum.views.auth import login_and_forward, send_validation_email +from forum.views.auth import login_and_forward from forum.actions import UserJoinsAction def register(request): @@ -26,13 +26,12 @@ def register(request): user_.save() UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save() - - send_validation_email(user_) + if email_feeds_form.cleaned_data['subscribe'] == 'n': user_.subscription_settings.enable_notifications = False user_.subscription_settings.save() - return login_and_forward(request, user_, None, _("A validation email has been sent to your email address. ")) + return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. ")) else: form = ClassicRegisterForm(initial={'next':'/'}) email_feeds_form = SimpleEmailSubscribeForm() -- 2.45.1