aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2011-06-24 12:03:48 +0100
committerMatthew Somerville <matthew@mysociety.org>2011-06-24 12:03:48 +0100
commitedf59d8605000c4363ce4d79f270559c522bc63e (patch)
tree4bb2950a68f66a998165e5a8b15e5bba08f551c5
parent8e6c6833afaf8b4cb820bffb4fa2adf44c0ca24d (diff)
Allow people to give name/pw on auth page.
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm21
-rw-r--r--perllib/FixMyStreet/TestMech.pm2
-rw-r--r--t/app/controller/auth.t4
-rw-r--r--templates/web/default/auth/general.html60
4 files changed, 58 insertions, 29 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index 5767a0a82..2277639df 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -50,9 +50,9 @@ Allow the user to legin with a username and a password.
sub login : Private {
my ( $self, $c ) = @_;
- my $email = $c->req->param('email') || '';
- my $password = $c->req->param('password') || '';
- my $remember_me = $c->req->param('remember_me') || 0;
+ my $email = $c->req->param('email') || '';
+ my $password = $c->req->param('password_login') || '';
+ my $remember_me = $c->req->param('remember_me') || 0;
# logout just in case
$c->logout();
@@ -108,6 +108,8 @@ sub email_login : Private {
data => {
email => $good_email,
r => $c->req->param('r'),
+ name => $c->req->param('name'),
+ password => $c->req->param('password_register'),
}
}
);
@@ -143,16 +145,19 @@ sub token : Path('/M') : Args(1) {
$c->logout();
# get the email and scrap the token
- my $email = $token_obj->data->{email};
- my $redirect = $token_obj->data->{r};
+ my $data = $token_obj->data;
$token_obj->delete;
- # find or create the user related to the token and delete the token
- my $user = $c->model('DB::User')->find_or_create( { email => $email } );
+ # find or create the user related to the token.
+ my $user = $c->model('DB::User')->find_or_create( { email => $data->{email} } );
+ $user->name( $data->{name} ) if $data->{name};
+ $user->password( $data->{password} ) if $data->{password};
+ $user->update;
+
$c->authenticate( { email => $user->email }, 'no_password' );
# send the user to their page
- $c->detach( 'redirect_on_signin', [ $redirect ] );
+ $c->detach( 'redirect_on_signin', [ $data->{r} ] );
}
=head2 redirect_on_signin
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 9913f5cde..13f1b10cf 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -94,7 +94,7 @@ sub log_in_ok {
# log in
$mech->get_ok('/auth');
$mech->submit_form_ok(
- { with_fields => { email => $email, password => 'secret' } },
+ { with_fields => { email => $email, password_login => 'secret' } },
"login using form" );
$mech->logged_in_ok;
diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t
index 79db69704..056dea225 100644
--- a/t/app/controller/auth.t
+++ b/t/app/controller/auth.t
@@ -189,7 +189,7 @@ foreach my $remember_me ( '1', '0' ) {
form_name => 'general_auth',
fields => {
email => $test_email,
- password => $test_password,
+ password_login => $test_password,
remember_me => ( $remember_me ? 1 : undef ),
},
button => 'login',
@@ -217,7 +217,7 @@ $mech->submit_form_ok(
form_name => 'general_auth',
fields => {
email => $test_email,
- password => 'not the password',
+ password_login => 'not the password',
},
button => 'login',
},
diff --git a/templates/web/default/auth/general.html b/templates/web/default/auth/general.html
index 5a5e63480..b5e6bf6e0 100644
--- a/templates/web/default/auth/general.html
+++ b/templates/web/default/auth/general.html
@@ -1,6 +1,6 @@
[% INCLUDE 'header.html', title = loc('Sign in or create an account') %]
-<h1>[% loc('Sign in or create an account') %]</h1>
+<h1>[% loc('Sign in') %]</h1>
<form action="[% c.uri_for() %]" method="post" name="general_auth">
<input type="hidden" name="r" value="[% c.req.params.r | html %]">
@@ -17,41 +17,65 @@
loc_email_error = errors.$email_error || errors.other;
END %]
-
<div id="fieldset">
[% IF loc_email_error %]
<div class="form-error">[% loc_email_error %]</div>
[% ELSIF login_error %]
- <div class="form-error">Email or password wrong - please try again.</div>
+ <div class="form-error">[% loc('Email or password wrong - please try again.') %]</div>
[% END %]
- <div class="form-field">
- <label for="email">[% loc('Email:') %]</label>
- <input type="text" name="email" value="[% email || '' | html %]">
- </div>
<div class="form-field">
- <label for="password">[% loc('Password:') %]</label>
- <input type="password" name="password" value="">
+ <label class="n" for="email">[% loc('Your email address:') %]</label>
+ <input type="email" size="30" id="email" name="email" value="[% email | html %]">
</div>
- <div class="checkbox">
+ <h3 style="margin-bottom:0">[% loc("Do you have a FixMyStreet password?") %]</h3>
+
+<div style="float: left; width: 48%; border-right: solid 1px #999999;">
+
+ <p>
+ <label class="n" for="password_login">[% loc('<strong>Yes</strong>, I have a password:') %]</label>
+ <input type="password" name="password_login" id="password_login" value="">
+ </p>
+
+ <p>
<input type="checkbox" name="remember_me" value='1'[% ' checked' IF remember_me %]>
- <label for="remember_me">
- [% loc('Remember me - do not use on a public computer') %]
+ <label class="n" for="remember_me">
+ [% loc('Keep me signed in on this computer') %]
</label>
- </div>
+ </p>
- <div class="checkbox">
- <input type="submit" name="login" value="[% loc('Sign me in') %]">
+ <p>
+ <input type="submit" name="login" value="[% loc('Sign in') %]">
+ </p>
+
+</div>
+<div style="float: right; width: 48%; clear:none;">
+
+ <p>[% loc('<strong>No</strong>, I do not, let me sign in by email:') %]</p>
+
+ <div class="form-field">
+ <label for="name">[% loc('Your name:') %]</label>
+ <input type="text" name="name" value="">
</div>
- <h3>I don't have an account, or I've forgotten my password...</h3>
- <div class="checkbox">
- <input type="submit" name="email_login" value="[% loc('Email the details I need to the address I entered above') %]">
+ <div class="form-field">
+ <label for="password_register">[% loc('Enter a new password:') %]</label>
+ <input type="password" name="password_register" id="password_register" value="">
</div>
+ <p><small>Providing a name and password is optional, but doing so
+ will allow you to more easily report problems, leave updates and
+ manage your reports.</small></p>
+
+ <p>
+ <input type="submit" name="email_login" value="[% loc('Sign in by email') %]">
+ </p>
+
+</div>
+
</div>
</form>