aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-04-19 15:58:02 +0100
committerStruan Donald <struan@exo.org.uk>2018-06-25 10:12:25 +0100
commit7c009ce048fbe36db24dd1a24f3542503db2e898 (patch)
treedba5f5e7d0b4bab9a5d3565781fe1bbd12aff807 /perllib/FixMyStreet/App/Controller/Admin.pm
parent43ef59400d632c3c29321c6908128932a31148a7 (diff)
add a send login email button to user edit page
Add a button to the user edit page that sends a login token email to the user. Helpful for user support situations where someone is having trouble logging in. Also for situations where you have added a user and want to get them logged in. Fixes #2041
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm43
1 files changed, 37 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 9d6c7d922..dfea6f8d4 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1417,12 +1417,6 @@ sub user_add : Path('user_edit') : Args(0) {
my $email_v = $c->get_param('email_verified');
my $phone_v = $c->get_param('phone_verified');
- unless ($email || $phone) {
- $c->stash->{field_errors}->{username} = _('Please enter a valid email or phone number');
- }
- if (!$email_v && !$phone_v) {
- $c->stash->{field_errors}->{username} = _('Please verify at least one of email/phone');
- }
if ($email && !is_valid_email($email)) {
$c->stash->{field_errors}->{email} = _('Please enter a valid email');
}
@@ -1430,6 +1424,13 @@ sub user_add : Path('user_edit') : Args(0) {
$c->stash->{field_errors}->{name} = _('Please enter a name');
}
+ unless ($email || $phone) {
+ $c->stash->{field_errors}->{username} = _('Please enter a valid email or phone number');
+ }
+ if (!$email_v && !$phone_v) {
+ $c->stash->{field_errors}->{username} = _('Please verify at least one of email/phone');
+ }
+
if ($phone_v) {
my $parsed_phone = $c->forward('phone_check', [ $phone ]);
$phone = $parsed_phone if $parsed_phone;
@@ -1503,6 +1504,11 @@ sub user_edit : Path('user_edit') : Args(1) {
$c->forward('user_hide_everywhere', [ $user ]);
} elsif ( $c->get_param('submit') and $c->get_param('remove_account') ) {
$c->forward('user_remove_account', [ $user ]);
+ } elsif ( $c->get_param('submit') and $c->get_param('send_login_email') ) {
+ my $email = lc $c->get_param('email');
+ my %args = ( email => $email );
+ $args{user_id} = $id if $user->email ne $email || !$user->email_verified;
+ $c->forward('send_login_email', [ \%args ]);
} elsif ( $c->get_param('submit') ) {
my $edited = 0;
@@ -1917,6 +1923,31 @@ sub user_hide_everywhere : Private {
$c->stash->{status_message} = _('That user’s reports and updates have been hidden.');
}
+sub send_login_email : Private {
+ my ( $self, $c, $args ) = @_;
+
+ my $token_data = {
+ email => $args->{email},
+ };
+
+ $token_data->{old_user_id} = $args->{user_id} if $args->{user_id};
+ $token_data->{name} = $args->{name} if $args->{name};
+
+ my $token_obj = $c->model('DB::Token')->create({
+ scope => 'email_sign_in',
+ data => $token_data,
+ });
+
+ $c->stash->{token} = $token_obj->token;
+ my $template = 'login.txt';
+
+ # do not use relative URIs in the email, obvs.
+ $c->uri_disposition('absolute');
+ $c->send_email( $template, { to => $args->{email} } );
+
+ $c->stash->{status_message} = _('The user has been sent a login email');
+}
+
# Anonymize and remove name from all problems/updates, disable all alerts.
# Remove their account's email address, phone number, password, etc.
sub user_remove_account : Private {