1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 02:48:51 +00:00

Use contact email in password resetting

This commit is contained in:
zhengxie
2017-01-16 15:46:00 +08:00
parent e04005770e
commit df70fd1b5e
2 changed files with 19 additions and 1 deletions

View File

@@ -920,7 +920,8 @@ def user_reset(request, email):
if IS_EMAIL_CONFIGURED:
if SEND_EMAIL_ON_RESETTING_USER_PASSWD:
try:
send_user_reset_email(request, user.email, new_password)
contact_email = Profile.objects.get_contact_email_by_user(user.email)
send_user_reset_email(request, contact_email, new_password)
msg = _('Successfully reset password to %(passwd)s, an email has been sent to %(user)s.') % \
{'passwd': new_password, 'user': user.email}
messages.success(request, msg)

View File

@@ -1,9 +1,11 @@
from django.core import mail
from django.core.urlresolvers import reverse
from constance import config
from seahub.base.accounts import User
from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE,
VAL_FORCE_PASSWD_CHANGE)
from seahub.profile.models import Profile
from seahub.test_utils import BaseTestCase
@@ -13,6 +15,21 @@ class UserResetTest(BaseTestCase):
self.login_as(self.admin)
def test_can_send_reset_email_to_contact_email(self):
p = Profile.objects.add_or_update(self.user.username, '')
p.contact_email = 'contact@mail.com'
p.save()
self.assertEqual(len(mail.outbox), 0)
resp = self.client.post(
reverse('user_reset', args=[self.user.email])
)
self.assertEqual(302, resp.status_code)
assert mail.outbox[0].to[0] != self.user.username
assert mail.outbox[0].to[0] == 'contact@mail.com'
self.assertEqual(len(mail.outbox), 1)
def test_can_reset_when_pwd_change_required(self):
config.FORCE_PASSWORD_CHANGE = 1