aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm54
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm11
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm2
-rw-r--r--perllib/FixMyStreet/TestMech.pm6
4 files changed, 38 insertions, 35 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 2277639df..8aed746ec 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -14,14 +14,14 @@ FixMyStreet::App::Controller::Auth - Catalyst Controller
=head1 DESCRIPTION
-Controller for all the authentication related pages - create account, login,
-logout.
+Controller for all the authentication related pages - create account, sign in,
+sign out.
=head1 METHODS
=head2 index
-Present the user with a login / create account page.
+Present the user with a sign in / create account page.
=cut
@@ -36,25 +36,27 @@ sub general : Path : Args(0) {
return unless $req->method eq 'POST';
# decide which action to take
- $c->detach('email_login') if $req->param('email_login');
- $c->detach('login'); # default
+ $c->detach('email_sign_in') if $req->param('email_sign_in');
+
+ $c->forward( 'sign_in' )
+ && $c->detach( 'redirect_on_signin', [ $req->param('r') ] );
}
-=head2 login
+=head2 sign_in
-Allow the user to legin with a username and a password.
+Allow the user to sign in with a username and a password.
=cut
-sub login : Private {
- my ( $self, $c ) = @_;
+sub sign_in : Private {
+ my ( $self, $c, $email ) = @_;
- my $email = $c->req->param('email') || '';
- my $password = $c->req->param('password_login') || '';
- my $remember_me = $c->req->param('remember_me') || 0;
+ $email ||= $c->req->param('email') || '';
+ my $password = $c->req->param('password_sign_in') || '';
+ my $remember_me = $c->req->param('remember_me') || 0;
- # logout just in case
+ # Sign out just in case
$c->logout();
if ( $email
@@ -66,22 +68,22 @@ sub login : Private {
$c->set_session_cookie_expire(0)
unless $remember_me;
- $c->detach( 'redirect_on_signin', [ $c->req->param('r') ] );
+ return 1;
}
- # could not authenticate - show an error
- $c->stash->{login_error} = 1;
+ $c->stash->{sign_in_error} = 1;
+ return;
}
-=head2 email_login
+=head2 email_sign_in
-Email the user the details they need to log in. Don't check for an account - if
+Email the user the details they need to sign in. Don't check for an account - if
there isn't one we can create it when they come back with a token (which
contains the email addresss).
=cut
-sub email_login : Private {
+sub email_sign_in : Private {
my ( $self, $c ) = @_;
# check that the email is valid - otherwise flag an error
@@ -104,7 +106,7 @@ sub email_login : Private {
my $token_obj = $c->model('DB::Token') #
->create(
{
- scope => 'email_login',
+ scope => 'email_sign_in',
data => {
email => $good_email,
r => $c->req->param('r'),
@@ -121,7 +123,7 @@ sub email_login : Private {
=head2 token
-Handle the 'email_login' tokens. Find the account for the email address
+Handle the 'email_sign_in' tokens. Find the account for the email address
(creating if needed), authenticate the user and delete the token.
=cut
@@ -132,7 +134,7 @@ sub token : Path('/M') : Args(1) {
# retrieve the token or return
my $token_obj = $url_token
? $c->model('DB::Token')->find( {
- scope => 'email_login', token => $url_token
+ scope => 'email_sign_in', token => $url_token
} )
: undef;
@@ -141,7 +143,7 @@ sub token : Path('/M') : Args(1) {
return;
}
- # logout in case we are another user
+ # Sign out in case we are another user
$c->logout();
# get the email and scrap the token
@@ -175,7 +177,7 @@ sub redirect_on_signin : Private {
=head2 redirect
-Used when trying to view a page that requires login when you're not.
+Used when trying to view a page that requires sign in when you're not.
=cut
@@ -228,13 +230,13 @@ sub change_password : Local {
}
-=head2 logout
+=head2 sign_out
Log the user out. Tell them we've done so.
=cut
-sub logout : Local {
+sub sign_out : Local {
my ( $self, $c ) = @_;
$c->logout();
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 44a7fa6bc..a6be6c90c 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -28,8 +28,6 @@ Create a new report, or complete a partial one .
=head2 flow control
-submit_map: true if we reached this page by clicking on the map
-
submit_problem: true if a problem has been submitted
=head2 location (required)
@@ -912,9 +910,12 @@ sub redirect_or_confirm_creation : Private {
}
# otherwise create a confirm token and email it to them.
- my $token =
- $c->model("DB::Token")
- ->create( { scope => 'problem', data => $report->id } );
+ my $token = $c->model("DB::Token")->create( {
+ scope => 'problem',
+ data => {
+ id => $report->id
+ }
+ } );
$c->stash->{token_url} = $c->uri_for_email( '/P', $token->token );
$c->send_email( 'problem-confirm.txt', {
to => [ [ $report->user->email, $report->name ] ],
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 111508e60..c9c9f3ab7 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -32,7 +32,7 @@ sub confirm_problem : Path('/P') {
$c->forward( 'load_auth_token', [ $token_code, 'problem' ] );
# Load the problem
- my $problem_id = $auth_token->data;
+ my $problem_id = $auth_token->data->{id};
my $problem = $c->cobrand->problems->find( { id => $problem_id } )
|| $c->detach('token_error');
$c->stash->{problem} = $problem;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 13f1b10cf..1391254b6 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -94,8 +94,8 @@ sub log_in_ok {
# log in
$mech->get_ok('/auth');
$mech->submit_form_ok(
- { with_fields => { email => $email, password_login => 'secret' } },
- "login using form" );
+ { with_fields => { email => $email, password_sign_in => 'secret' } },
+ "sign in using form" );
$mech->logged_in_ok;
# restore the password (if there was one)
@@ -114,7 +114,7 @@ Log out the current user
sub log_out_ok {
my $mech = shift;
- $mech->get_ok('/auth/logout');
+ $mech->get_ok('/auth/sign_out');
$mech->not_logged_in_ok;
}