Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
if a user's email address is changed, also send an email to the old a…
Browse files Browse the repository at this point in the history
…ddress
  • Loading branch information
karenetheridge committed Jan 19, 2021
1 parent 26fc1bb commit 7d9117e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 11 additions & 0 deletions lib/Conch/Controller/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ sub update ($c) {
orig_data => \%orig_columns,
new_data => \%dirty_columns,
);

# also send to old email address, if it was changed!
$c->send_mail(
template_file => 'updated_user_account',
From => 'noreply',
To => '"'.$orig_columns{name}.'" <'.$orig_columns{email}.'>',
Subject => 'Your Conch account has been updated',
orig_data => \%orig_columns,
new_data => \%dirty_columns,
)
if exists $dirty_columns{email} and fc $input->{email} ne fc $orig_columns{email};
}

$c->log->debug('updating user '.$user->email.': '.$c->req->text);
Expand Down
18 changes: 13 additions & 5 deletions t/integration/users.t
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,23 @@ subtest 'User' => sub {
{ email => '[email protected]' },
{ name => 'conch' };

$t->post_ok('/user/me', json => { email => 'rO_USer@cONCh.joyent.us', name => 'rO_USer' })
$t->post_ok('/user/me', json => { email => 'rO_USer_new@cONCh.joyent.us', name => 'rO_USer' })
->status_is(204)
->location_is('/user/'.$ro_user->id)
->email_cmp_deeply({
To => '"rO_USer" <[email protected]>',
->email_cmp_deeply([
{
To => '"rO_USer" <[email protected]>',
From => '[email protected]',
Subject => 'Your Conch account has been updated',
body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m),
});
body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer_new\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m),
},
{
To => '"ro_user" <[email protected]>',
From => '[email protected]',
Subject => 'Your Conch account has been updated',
body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer_new\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m),
},
]);

$ro_user->discard_changes;

Expand Down

0 comments on commit 7d9117e

Please sign in to comment.