mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-20 10:58:33 +00:00
Use contact email in password resetting
This commit is contained in:
@@ -920,7 +920,8 @@ def user_reset(request, email):
|
|||||||
if IS_EMAIL_CONFIGURED:
|
if IS_EMAIL_CONFIGURED:
|
||||||
if SEND_EMAIL_ON_RESETTING_USER_PASSWD:
|
if SEND_EMAIL_ON_RESETTING_USER_PASSWD:
|
||||||
try:
|
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.') % \
|
msg = _('Successfully reset password to %(passwd)s, an email has been sent to %(user)s.') % \
|
||||||
{'passwd': new_password, 'user': user.email}
|
{'passwd': new_password, 'user': user.email}
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
|
from django.core import mail
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from constance import config
|
from constance import config
|
||||||
|
|
||||||
from seahub.base.accounts import User
|
from seahub.base.accounts import User
|
||||||
from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE,
|
from seahub.options.models import (UserOptions, KEY_FORCE_PASSWD_CHANGE,
|
||||||
VAL_FORCE_PASSWD_CHANGE)
|
VAL_FORCE_PASSWD_CHANGE)
|
||||||
|
from seahub.profile.models import Profile
|
||||||
from seahub.test_utils import BaseTestCase
|
from seahub.test_utils import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
@@ -13,6 +15,21 @@ class UserResetTest(BaseTestCase):
|
|||||||
|
|
||||||
self.login_as(self.admin)
|
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):
|
def test_can_reset_when_pwd_change_required(self):
|
||||||
config.FORCE_PASSWORD_CHANGE = 1
|
config.FORCE_PASSWORD_CHANGE = 1
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user