diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-07-06 17:35:35 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-07-07 14:13:18 +0100 |
commit | a978c0a1ad216f7004ef88b8a58b9731242155dc (patch) | |
tree | 58ec3daece503b314bb1dfe54ab2d0c0e80cb24e /perllib/FixMyStreet/App/Controller/Auth.pm | |
parent | beb7e1f345ace940c542d93768ec44bfd6f5dc21 (diff) |
Factor out all uses of param()/params.
Use a central get_param and get_param_list functions dependent on
whether we're after a scalar or a list (almost always a scalar). This
prevents any possibility of confusion where param() could return a list,
or params->{} an arrayref.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Auth.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index fad8941c5..66cf3979c 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -28,22 +28,21 @@ Present the user with a sign in / create account page. sub general : Path : Args(0) { my ( $self, $c ) = @_; - my $req = $c->req; - $c->detach( 'redirect_on_signin', [ $req->param('r') ] ) - if $c->user && $req->param('r'); + $c->detach( 'redirect_on_signin', [ $c->get_param('r') ] ) + if $c->user && $c->get_param('r'); # all done unless we have a form posted to us - return unless $req->method eq 'POST'; + return unless $c->req->method eq 'POST'; # decide which action to take - my $has_password = $req->param('sign_in') || $req->param('password_sign_in'); - my $has_email = $req->param('email_sign_in') || $req->param('name') || $req->param('password_register'); + my $has_password = $c->get_param('sign_in') || $c->get_param('password_sign_in'); + my $has_email = $c->get_param('email_sign_in') || $c->get_param('name') || $c->get_param('password_register'); $c->detach('email_sign_in') if $has_email && !$has_password; $c->forward( 'sign_in' ) - && $c->detach( 'redirect_on_signin', [ $req->param('r') ] ); + && $c->detach( 'redirect_on_signin', [ $c->get_param('r') ] ); } @@ -56,9 +55,9 @@ Allow the user to sign in with a username and a password. sub sign_in : Private { my ( $self, $c, $email ) = @_; - $email ||= $c->req->param('email') || ''; - my $password = $c->req->param('password_sign_in') || ''; - my $remember_me = $c->req->param('remember_me') || 0; + $email ||= $c->get_param('email') || ''; + my $password = $c->get_param('password_sign_in') || ''; + my $remember_me = $c->get_param('remember_me') || 0; # Sign out just in case $c->logout(); @@ -95,7 +94,7 @@ sub email_sign_in : Private { my ( $self, $c ) = @_; # check that the email is valid - otherwise flag an error - my $raw_email = lc( $c->req->param('email') || '' ); + my $raw_email = lc( $c->get_param('email') || '' ); my $email_checker = Email::Valid->new( -mxcheck => 1, @@ -112,8 +111,8 @@ sub email_sign_in : Private { } my $user_params = {}; - $user_params->{password} = $c->req->param('password_register') - if $c->req->param('password_register'); + $user_params->{password} = $c->get_param('password_register') + if $c->get_param('password_register'); my $user = $c->model('DB::User')->new( $user_params ); my $token_obj = $c->model('DB::Token') # @@ -122,8 +121,8 @@ sub email_sign_in : Private { scope => 'email_sign_in', data => { email => $good_email, - r => $c->req->param('r'), - name => $c->req->param('name'), + r => $c->get_param('r'), + name => $c->get_param('name'), password => $user->password, } } @@ -221,8 +220,8 @@ sub change_password : Local { return unless $c->req->method eq 'POST'; # get the passwords - my $new = $c->req->param('new_password') // ''; - my $confirm = $c->req->param('confirm') // ''; + my $new = $c->get_param('new_password') // ''; + my $confirm = $c->get_param('confirm') // ''; # check for errors my $password_error = |