Commit e2125441 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

fix password_reset email link & subject

Refs: #1935 
parent 7d7f1f1b
......@@ -59,7 +59,7 @@ from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.models import Site
from astakos.im.models import AstakosUser, Invitation
from astakos.im.util import isoformat, get_context
from astakos.im.util import isoformat, get_context, get_current_site
from astakos.im.forms import *
from astakos.im.backends import get_backend
from astakos.im.views import render_response, index
......@@ -308,16 +308,16 @@ def pending_users(request, template_name='pending_users.html', extra_context={})
context_instance = get_context(request, extra_context,**kwargs))
def _send_greeting(request, user, template_name):
site = Site.objects.get_current()
subject = _('Welcome to %s' % site.name)
sitename, sitedomain = get_current_site(request, use_https=request.is_secure())
subject = _('Welcome to %s' % sitename)
baseurl = request.build_absolute_uri('/').rstrip('/')
message = render_to_string(template_name, {
'user': user,
'url': site.domain,
'url': sitedomain,
'baseurl': baseurl,
'site_name': site.name,
'support': settings.DEFAULT_CONTACT_EMAIL % site.name.lower()})
sender = settings.DEFAULT_FROM_EMAIL % site.name
'site_name': sitename,
'support': settings.DEFAULT_CONTACT_EMAIL % sitename.lower()})
sender = settings.DEFAULT_FROM_EMAIL % sitename
send_mail(subject, message, sender, [user.email])
logging.info('Sent greeting %s', user)
......
......@@ -3,7 +3,7 @@
"model": "sites.site",
"pk": 1,
"fields": {
"domain": "https://pithos.dev.grnet.gr/im",
"domain": "pithos.dev.grnet.gr/im",
"name": "Pithos"
}
}
......
......@@ -33,14 +33,19 @@
from django import forms
from django.utils.translation import ugettext as _
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordResetForm
from django.conf import settings
from django.core.validators import email_re
from django.conf import settings
from django.core.mail import send_mail
from django.contrib.auth.tokens import default_token_generator
from django.template import Context, loader
from django.utils.http import int_to_base36
from hashlib import new as newhasher
from astakos.im.models import AstakosUser
from astakos.im.util import get_current_site
import logging
import uuid
......@@ -172,4 +177,33 @@ class SendInvitationForm(forms.Form):
email = forms.EmailField(required = True, label = 'Email address')
first_name = forms.EmailField(label = 'First name')
last_name = forms.EmailField(label = 'Last name')
class ExtendedPasswordResetForm(PasswordResetForm):
"""
Extends PasswordResetForm by overriding save method:
passes a custom from_email in send_mail.
Since Django 1.3 this is useless since ``django.contrib.auth.views.reset_password``
accepts a from_email argument.
"""
def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator, request=None):
"""
Generates a one-use only link for resetting password and sends to the user.
"""
for user in self.users_cache:
site_name, sitedomain = get_current_site(request, use_https=use_https)
t = loader.get_template(email_template_name)
c = {
'email': user.email,
'domain': sitedomain.split('://')[-1],
'site_name': site_name,
'uid': int_to_base36(user.id),
'user': user,
'token': token_generator.make_token(user),
'protocol': use_https and 'https' or 'http',
}
from_email = settings.DEFAULT_FROM_EMAIL % site_name
send_mail(_("Password reset on %s") % site_name,
t.render(Context(c)), from_email, [user.email])
......@@ -35,6 +35,8 @@ from django.conf import settings
from django.conf.urls.defaults import patterns, include, url
from django.core.urlresolvers import reverse
from astakos.im.forms import ExtendedPasswordResetForm
urlpatterns = patterns('astakos.im.views',
url(r'^$', 'index'),
url(r'^login/?$', 'index'),
......@@ -65,7 +67,8 @@ if 'local' in settings.IM_MODULES:
)
urlpatterns += patterns('django.contrib.auth.views',
url(r'^local/password_reset/?$', 'password_reset',
{'email_template_name':'registration/password_email.txt'}),
{'email_template_name':'registration/password_email.txt',
'password_reset_form':ExtendedPasswordResetForm}),
url(r'^local/password_reset_done/?$', 'password_reset_done'),
url(r'^local/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
'password_reset_confirm'),
......
......@@ -36,6 +36,7 @@ import logging
from datetime import tzinfo, timedelta
from django.conf import settings
from django.template import RequestContext
from django.contrib.sites.models import Site
from astakos.im.models import AstakosUser
......@@ -83,3 +84,11 @@ def get_context(request, extra_context={}, **kwargs):
extra_context = {}
extra_context.update(kwargs)
return RequestContext(request, extra_context)
def get_current_site(request, use_https=False):
"""
returns the current site name and full domain (including prorocol)
"""
protocol = use_https and 'https' or 'http'
site = Site.objects.get_current()
return site.name, '%s://%s' % (protocol, site.domain)
\ No newline at end of file
......@@ -63,7 +63,7 @@ from django.contrib.auth.forms import UserCreationForm
#from astakos.im.openid_store import PithosOpenIDStore
from astakos.im.models import AstakosUser, Invitation
from astakos.im.util import isoformat, get_context
from astakos.im.util import isoformat, get_context, get_current_site
from astakos.im.backends import get_backend
from astakos.im.forms import ProfileForm, FeedbackForm, LoginForm
......@@ -122,16 +122,16 @@ def _generate_invitation_code():
return code
def _send_invitation(request, baseurl, inv):
site = Site.objects.get_current()
subject = _('Invitation to %s' % site.name)
url = settings.SIGNUP_TARGET % (baseurl, inv.code, quote(site.domain))
sitename, sitedomain = get_current_site(request, use_https=request.is_secure())
subject = _('Invitation to %s' % sitename)
url = settings.SIGNUP_TARGET % (baseurl, inv.code, quote(sitedomain))
message = render_to_string('invitation.txt', {
'invitation': inv,
'url': url,
'baseurl': baseurl,
'service': site.name,
'support': settings.DEFAULT_CONTACT_EMAIL % site.name.lower()})
sender = settings.DEFAULT_FROM_EMAIL % site.name
'service': sitename,
'support': settings.DEFAULT_CONTACT_EMAIL % sitename.lower()})
sender = settings.DEFAULT_FROM_EMAIL % sitename
send_mail(subject, message, sender, [inv.username])
logging.info('Sent invitation %s', inv)
......@@ -353,10 +353,10 @@ def send_feedback(request, template_name='feedback.html', email_template_name='f
form = FeedbackForm(request.POST)
if form.is_valid():
site = Site.objects.get_current()
subject = _("Feedback from %s" % site.name)
sitename, sitedomain = get_current_site(request, use_https=request.is_secure())
subject = _("Feedback from %s" % sitename)
from_email = request.user.email
recipient_list = [settings.DEFAULT_CONTACT_EMAIL]
recipient_list = [settings.DEFAULT_CONTACT_EMAIL % sitename.lower()]
content = render_to_string(email_template_name, {
'message': form.cleaned_data('feedback_msg'),
'data': form.cleaned_data('feedback_data'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment