From: Tara L Andrews <tla@mit.edu> Date: Thu, 12 Jul 2012 21:07:42 +0000 (+0200) Subject: integrate login/register functionality more properly with app X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eb38afbcd0ef1e20b95b9954a0b8d0f107d0c342;p=scpubgit%2Fstemmaweb.git integrate login/register functionality more properly with app --- diff --git a/Makefile.PL b/Makefile.PL index 7c833af..40572d0 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -24,7 +24,7 @@ requires 'Catalyst::Plugin::Authentication'; requires 'Catalyst::Plugin::Session'; requires 'Catalyst::Plugin::Session::Store::File'; requires 'Catalyst::Plugin::Session::State::Cookie'; -requires 'CatalystX::Controller::Auth'; +requires 'CatalystX::Controller::Auth' => '0.22'; requires 'Catalyst::TraitFor::Controller::reCAPTCHA'; requires 'LWP::Protocol::https'; ## diff --git a/lib/stemmaweb.pm b/lib/stemmaweb.pm index 4563222..ba6ea4a 100644 --- a/lib/stemmaweb.pm +++ b/lib/stemmaweb.pm @@ -99,9 +99,9 @@ __PACKAGE__->config( model => 'User', login_id_field => 'username', login_db_field => 'username', - action_after_login => '/index', - action_after_register => '/index', - register_email_from => '"MyApp" <somebody@example.com>', + action_after_login => '/users/success', + action_after_register => '/users/success', + register_email_from => '"Stemmaweb" <stemmaweb@byzantini.st>', register_email_subject => 'Registration to stemmaweb', register_email_template_plain => 'register-plain.tt', realm => 'default', @@ -114,8 +114,8 @@ __PACKAGE__->config( }, recaptcha => { - pub_key => '', - priv_key => '', + pub_key => '6LfR19MSAAAAACy2meHvLfZGRn3PM2rRYIAfh665', + priv_key => '6LfR19MSAAAAAMlQb8BdyecWNRE1bAL2YSgz2sah', }, ); diff --git a/lib/stemmaweb/Controller/Users.pm b/lib/stemmaweb/Controller/Users.pm index 8a5c6ac..32f629f 100644 --- a/lib/stemmaweb/Controller/Users.pm +++ b/lib/stemmaweb/Controller/Users.pm @@ -47,7 +47,7 @@ sub index :Path :Args(0) { Logging in with openid/google requires two passes through the login action, on the 2nd pass the C<openid-check> value is passed in when the openid providing webserver links the user back to the stemmaweb -site. This adaption to the C<login> action sets the realm we are +site. This adaptation to the C<login> action sets the realm we are authenticating against to be C<openid> in this case. =cut @@ -86,6 +86,31 @@ before register => sub { } }; +=head2 success + +A stub page returned on login / registration success. + +=cut + +sub success :Local :Args(0) { + my ( $self, $c ) = @_; + + $c->load_status_msgs; + $c->stash->{template} = 'auth/success.tt'; +} + +=head2 post_logout + +Return to the index page, not to the login page. + +=cut + +sub post_logout { + my( $self, $c ) = @_; + $c->response->redirect( $c->uri_for_action( '/index' ) ); + $c->detach; +} + =head1 AUTHOR A clever guy diff --git a/root/css/auth.css b/root/css/auth.css new file mode 100644 index 0000000..0717b5f --- /dev/null +++ b/root/css/auth.css @@ -0,0 +1,8 @@ +#topbanner { + width: 100%; + height: 50px; + margin-top: 20px; +} +.error { + color: #d24848; +} diff --git a/root/css/style.css b/root/css/style.css index a3047f9..4aaa2b9 100644 --- a/root/css/style.css +++ b/root/css/style.css @@ -58,6 +58,22 @@ div.button:hover span { background-position: bottom left; } +#topbanner { + width: 100%; + height: 100px; + margin-top: 20px; +} +#bannerinfo { + float: right; + margin-right: 12%; + margin-top: 15px; +} +.navlink { + color: #488dd2; + text-decoration: underline; +} + + /* Index page components */ diff --git a/root/src/auth/login.tt b/root/src/auth/login.tt index 7779789..61575b1 100644 --- a/root/src/auth/login.tt +++ b/root/src/auth/login.tt @@ -1,3 +1,30 @@ +[% WRAPPER header.tt + pagetitle = "Stemmaweb - Sign in" + applicationstyle = c.uri_for('/css/auth.css') +%] + <script type="text/javascript"> +$(document).ready(function() { + // call out to load the directory div + $('#login_actions').accordion(); + $('.login_button').button(); + $('#submit').button(); + + var status = '[% status_msg %]'; + if( status == 'Logged in!' ) { + setInterval( function ( e ) { + window.opener.location.reload(true); + window.close(); + e.preventDefault(); + }, 2000 ); + } +}); + </script> +[% END %] + <div id="topbanner"> + <h1>Stemmaweb - Sign in</h1> + </div> + +<div id="login_status"> [% IF status_msg %] <p>[% status_msg | html %]</p> [% END %] @@ -14,25 +41,47 @@ [% END %] </ul> [% END %] +</div> +[% UNLESS status_msg == 'Logged in!' %] +<div id="login_actions"> + <h3><a href="#">Sign in with Google</a></h3> + <div> + <p>If you have a Google account, you may use it to sign into Stemmaweb.</p> + <form method="post" action="[% c.uri_for_action('/users/login') | html %]" autocomplete="off"> + <input type="hidden" name="realm" value="openid"/> + <input type="hidden" name="openid_identifier" value="https://www.google.com/accounts/o8/id"/> + <input type="submit" class="login_button" id="#login_google" value="Sign in with Google"></input> + </form> + </div> - <form method="post" action="[% c.uri_for_action('/users/login').hostless | html %]" autocomplete="off"> - - <input type="hidden" name="realm" value="openid"/> - <input type="hidden" name="openid_identifier" value="https://www.google.com/accounts/o8/id"/> - <input type="submit" value="Sign in with Google"/> - - </form> + <h3><a href="#">Sign in with OpenID</a></h3> + <div> + <p>If you have an account with an <a href="http://openid.net/get-an-openid/" target="_blank">OpenID provider</a> (e.g. WordPress, Blogger, Flickr, Yahoo), you may use it to sign into Stemmaweb. + <form method="post" action="[% c.uri_for_action('/users/login') | html %]" autocomplete="off"> + <input type="hidden" name="realm" value="openid"/> + <input type="text" name="openid_identifier"/> + <input type="submit" class="login_button" id="#login_openid" value="Sign in with OpenID"/> + </form> + </div> [% UNLESS c.req.param('realm') == 'openid' %] - <form method="post" action="[% c.uri_for_action('/users/login').hostless | html %]" autocomplete="off"> - - <input type="hidden" name="realm" value="default"/> - - [% form.field('username').render %] - [% form.field('password').render %] - [% form.field('remember').render %] - - [% form.field('submit').render %] - - </form> -[% END %] \ No newline at end of file + <h3><a href="#">Sign in with Stemmaweb</a></h3> + <div> + <p>If you do not have Google or another OpenID account, you may <a href="[% c.uri_for_action('/users/register') | html %]">register</a> for a user account here with its own password. Once you are registered, you can use this form to sign in.</p> + <form id="login_local_form" method="post" action="[% c.uri_for_action('/users/login') | html %]" autocomplete="off"> + <input type="hidden" name="realm" value="default"/> + [% userlabel = form.field('username').label('Email address') %] + [% form.field('username').render %] + [% form.field('password').render %] + + [% rememberlabel = form.field('remember').label('Remember me') %] + [% form.field('remember').render %] + + [% submitbutton = form.field('submit').value('Sign in with Stemmaweb') %] + [% form.field('submit').render %] + </form> + </div> +[% END %] +</div> +[% END %] +[% PROCESS footer.tt %] \ No newline at end of file diff --git a/root/src/auth/register.tt b/root/src/auth/register.tt index 2f91791..97384be 100644 --- a/root/src/auth/register.tt +++ b/root/src/auth/register.tt @@ -1,3 +1,7 @@ +[% PROCESS header.tt + pagetitle = "Stemmaweb - Register" + applicationstyle = c.uri_for('/css/auth.css') +%] [% IF status_msg %] <p>[% status_msg | html %]</p> [% END %] @@ -15,9 +19,10 @@ </ul> [% END %] - <form method="post" action="[% c.uri_for_action('/users/register').hostless | html %]" autocomplete="off"> + <form method="post" action="[% c.uri_for_action('/users/register') | html %]" autocomplete="off"> - [% form.field('username').render %] (email) + [% userlabel = form.field('username').label('Email address') %] + [% form.field('username').render %] [% form.field('password').render %] [% form.field('confirm_password').render %] @@ -28,4 +33,5 @@ [% form.field('submit').render %] - </form> \ No newline at end of file + </form> +[% PROCESS footer.tt %] \ No newline at end of file diff --git a/root/src/auth/success.tt b/root/src/auth/success.tt new file mode 100644 index 0000000..39189cf --- /dev/null +++ b/root/src/auth/success.tt @@ -0,0 +1,29 @@ +[% WRAPPER header.tt + pagetitle = "Stemmaweb - Logged in" + applicationstyle = c.uri_for('/css/auth.css') +%] + <script type="text/javascript"> +$(document).ready(function() { + var status = '[% status_msg %]'; + var error = '[% error_msg %]'; + if( status && !error ) { + setInterval( function ( e ) { + window.opener.location.reload(true); + window.close(); + e.preventDefault(); + }, 2000 ); + } +}); + </script> +[% END %] + <div id="topbanner"> + <h1>Stemmaweb - Signed in</h1> + </div> + +<div id="login_status"> +[% IF status_msg %] + <p>[% status_msg | html %]</p> + <p>Please wait...</p> +[% END %] +</div> +[% PROCESS footer.tt %] \ No newline at end of file diff --git a/root/src/index.tt b/root/src/index.tt index 68cebc7..4131aeb 100644 --- a/root/src/index.tt +++ b/root/src/index.tt @@ -14,7 +14,7 @@ $(document).ready(function() { <div id="topbanner"> <h1>Stemmaweb - a collection of tools for analysis of collated texts</h1> - <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] [% ELSE %]<a href="[% c.uri_for('/login') %]">Login</a> | <a href="[% c.uri_for('/register') %]">Register</a> | [% END %]<a href="[% c.uri_for( 'about.html' ) %]">About<a> | <a href="[% c.uri_for( 'doc.html' ) %]">Help</a></span> + <span class="mainnav">[% IF c.user_exists %]Hello! [% c.user.get_object.email %] <a class="navlink" href="[% c.uri_for( '/logout' ) %]">Sign out</a> | [% ELSE %]<a class="navlink" onclick="window.open('[% c.uri_for( '/login' ) %]', 'loginwindow', 'height=385,width=445')">Login</a> | <a class="navlink" onclick="window.open('[% c.uri_for( '/register' ) %]', 'regwindow', 'height=385,width=445')">Register</a> | [% END %]<a class="navlink" href="[% c.uri_for( 'about.html' ) %]">About<a> </span> </div> <div id="directory_container"> <h2>Text directory</h2>