Merge pull request #25185 from edx/aali/fix_password_sent_email
fix email to which reset link was sent
This commit is contained in:
@@ -40,7 +40,7 @@ class Command(BaseCommand):
|
||||
send password reset email.
|
||||
|
||||
csv file is expected to have one row per user with the format:
|
||||
username, email, new_email
|
||||
username, current_email, desired_email
|
||||
|
||||
Example:
|
||||
$ ... recover_account csv_file_path
|
||||
@@ -76,34 +76,34 @@ class Command(BaseCommand):
|
||||
|
||||
for row in csv_reader:
|
||||
username = row['username']
|
||||
email = row['email']
|
||||
new_email = row['new_email']
|
||||
current_email = row['current_email']
|
||||
desired_email = row['desired_email']
|
||||
|
||||
try:
|
||||
user = get_user_model().objects.get(Q(username__iexact=username) | Q(email__iexact=email))
|
||||
user.email = new_email
|
||||
user = get_user_model().objects.get(Q(username__iexact=username) | Q(email__iexact=current_email))
|
||||
user.email = desired_email
|
||||
user.save()
|
||||
self.send_password_reset_email(user, email, site)
|
||||
successful_updates.append(new_email)
|
||||
self.send_password_reset_email(user, site)
|
||||
successful_updates.append(desired_email)
|
||||
except Exception as exc: # pylint: disable=broad-except
|
||||
logger.exception('Unable to send email to {email} and exception was {exp}'.
|
||||
format(email=email, exp=exc)
|
||||
logger.exception('Unable to send email to {desired_email} and exception was {exp}'.
|
||||
format(desired_email=desired_email, exp=exc)
|
||||
)
|
||||
|
||||
failed_updates.append(email)
|
||||
failed_updates.append(current_email)
|
||||
|
||||
logger.info('Successfully updated {successful} accounts. Failed to update {failed} '
|
||||
'accounts'.format(successful=successful_updates, failed=failed_updates)
|
||||
)
|
||||
|
||||
def send_password_reset_email(self, user, email, site):
|
||||
def send_password_reset_email(self, user, site):
|
||||
"""
|
||||
Send email to learner with reset password link
|
||||
:param user:
|
||||
:param email:
|
||||
:param site:
|
||||
"""
|
||||
message_context = get_base_template_context(site)
|
||||
email = user.email
|
||||
message_context.update({
|
||||
'email': email,
|
||||
'platform_name': configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME),
|
||||
|
||||
@@ -32,7 +32,7 @@ class RecoverAccountTests(TestCase):
|
||||
|
||||
def _write_test_csv(self, csv, lines):
|
||||
"""Write a test csv file with the lines provided"""
|
||||
csv.write(b"username,email,new_email\n")
|
||||
csv.write(b"username,current_email,desired_email\n")
|
||||
for line in lines:
|
||||
csv.write(six.b(line))
|
||||
csv.seek(0)
|
||||
@@ -80,7 +80,7 @@ class RecoverAccountTests(TestCase):
|
||||
with NamedTemporaryFile() as csv:
|
||||
csv = self._write_test_csv(csv, lines=['amm,amy@myedx.com,amy@newemail.com\n'])
|
||||
|
||||
expected_message = 'Unable to send email to amy@myedx.com and ' \
|
||||
expected_message = 'Unable to send email to amy@newemail.com and ' \
|
||||
'exception was User matching query does not exist.'
|
||||
|
||||
with LogCapture(LOGGER_NAME) as log:
|
||||
@@ -109,7 +109,7 @@ class RecoverAccountTests(TestCase):
|
||||
|
||||
def test_account_recovery_from_config_model(self):
|
||||
"""Verify learners account recovery using config model."""
|
||||
lines = 'username,email,new_email\namy,amy@edx.com,amy@newemail.com\n'
|
||||
lines = 'username,current_email,desired_email\namy,amy@edx.com,amy@newemail.com\n'
|
||||
|
||||
csv_file = SimpleUploadedFile(name='test.csv', content=lines.encode('utf-8'), content_type='text/csv')
|
||||
AccountRecoveryConfiguration.objects.create(enabled=True, csv_file=csv_file)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 2.2.16 on 2020-10-21 12:56
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('student', '0037_linkedinaddtoprofileconfiguration_updates'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='accountrecoveryconfiguration',
|
||||
name='csv_file',
|
||||
field=models.FileField(help_text='It expect that the data will be provided in a csv file format with first row being the header and columns will be as follows: username, current_email, desired_email', upload_to='', validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['csv'])]),
|
||||
),
|
||||
]
|
||||
@@ -3035,7 +3035,7 @@ class AccountRecoveryConfiguration(ConfigurationModel):
|
||||
validators=[FileExtensionValidator(allowed_extensions=[u'csv'])],
|
||||
help_text=_(u"It expect that the data will be provided in a csv file format with \
|
||||
first row being the header and columns will be as follows: \
|
||||
username, email, new_email")
|
||||
username, current_email, desired_email")
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user