aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-09-18 15:54:24 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-09-30 13:02:09 +0100
commit6707cee96a465659e1da2d92addb3ebbbe201a8b (patch)
tree9a4a908829e9db09eaf566253f9c4be1e6f6beb7 /perllib/FixMyStreet/App/Controller/Auth/Profile.pm
parenta369e1c1a178697d0f92cf82c5bdb23c1883925e (diff)
Move some auth functions to their own controllers.
Move the social auth functions to Auth::Social, and the change email/password functions to Auth::Profile. There are no actual code changes.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Auth/Profile.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth/Profile.pm93
1 files changed, 93 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth/Profile.pm b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
new file mode 100644
index 000000000..68c40f9dc
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
@@ -0,0 +1,93 @@
+package FixMyStreet::App::Controller::Auth::Profile;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Auth::Profile - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Controller for all the authentication profile related pages - changing email,
+password.
+
+=head1 METHODS
+
+=cut
+
+sub auto {
+ my ( $self, $c ) = @_;
+
+ $c->detach( '/auth/redirect' ) unless $c->user;
+
+ return 1;
+}
+
+=head2 change_password
+
+Let the user change their password.
+
+=cut
+
+sub change_password : Path('/auth/change_password') {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{template} = 'auth/change_password.html';
+
+ $c->forward('/auth/get_csrf_token');
+
+ # If not a post then no submission
+ return unless $c->req->method eq 'POST';
+
+ $c->forward('/auth/check_csrf_token');
+
+ # get the passwords
+ my $new = $c->get_param('new_password') // '';
+ my $confirm = $c->get_param('confirm') // '';
+
+ # check for errors
+ my $password_error =
+ !$new && !$confirm ? 'missing'
+ : $new ne $confirm ? 'mismatch'
+ : '';
+
+ if ($password_error) {
+ $c->stash->{password_error} = $password_error;
+ $c->stash->{new_password} = $new;
+ $c->stash->{confirm} = $confirm;
+ return;
+ }
+
+ # we should have a usable password - save it to the user
+ $c->user->obj->update( { password => $new } );
+ $c->stash->{password_changed} = 1;
+
+}
+
+=head2 change_email
+
+Let the user change their email.
+
+=cut
+
+sub change_email : Path('/auth/change_email') {
+ my ( $self, $c ) = @_;
+
+ $c->stash->{template} = 'auth/change_email.html';
+
+ $c->forward('/auth/get_csrf_token');
+
+ # If not a post then no submission
+ return unless $c->req->method eq 'POST';
+
+ $c->forward('/auth/check_csrf_token');
+ $c->stash->{current_user} = $c->user;
+ $c->stash->{email_template} = 'change_email.txt';
+ $c->forward('/auth/email_sign_in');
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;