[Rt-commit] rt branch, 4.0/mobile-login, created. rt-4.0.4-146-g21ad631

? sunnavy sunnavy at bestpractical.com
Wed Jul 4 13:12:44 EDT 2012


The branch, 4.0/mobile-login has been created
        at  21ad631c27f021924db2346f8332503f986265e5 (commit)

- Log -----------------------------------------------------------------
commit a4acdcf4c3f6d9a24e7e2cffb05e34da4f4ee632
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Dec 14 13:27:10 2011 +0800

    show mobile login on mobile clients
    
    also, if user access urls starting with /m/, even though it's not a mobile
    client, we also show the mobile login.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 2e8a8f9..5f4dcd5 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -256,6 +256,10 @@ sub HandleRequest {
     # Process per-page authentication callbacks
     $HTML::Mason::Commands::m->callback( %$ARGS, CallbackName => 'Auth', CallbackPage => '/autohandler' );
 
+    if ( $ARGS->{'NotMobile'} ) {
+        $HTML::Mason::Commands::session{'NotMobile'} = 1;
+    }
+
     unless ( _UserLoggedIn() ) {
         _ForceLogout();
 
@@ -279,6 +283,12 @@ sub HandleRequest {
                 $m->comp('/NoAuth/Login.html', next => $next, actions => [$msg]);
                 $m->abort;
             }
+            # Specially handle /m/index.html so that we get a nicer URL
+            elsif ( $m->request_comp->path eq '/m/index.html' ) {
+                my $next = SetNextPage( RT->Config->Get('WebURL') . 'm' );
+                $m->comp('/m/login', next => $next, actions => [$msg]);
+                $m->abort;
+            }
             else {
                 TangentForLogin(results => ($msg ? LoginError($msg) : undef));
             }
@@ -360,7 +370,13 @@ the next page.  Optionally takes a hash which is dumped into query params.
 
 sub TangentForLogin {
     my $hash  = SetNextPage();
-    my %query = (@_, next => $hash);
+    my %query = (
+        $HTML::Mason::Commands::m->request_comp->path =~ '^/m/'
+        ? ( 'mobile' => 1 )
+        : (),
+        @_,
+        next => $hash
+    );
     my $login = RT->Config->Get('WebURL') . 'NoAuth/Login.html?';
     $login .= $HTML::Mason::Commands::m->comp('/Elements/QueryString', %query);
     Redirect($login);
diff --git a/share/html/NoAuth/Login.html b/share/html/NoAuth/Login.html
index b33bb0a..e35abca 100755
--- a/share/html/NoAuth/Login.html
+++ b/share/html/NoAuth/Login.html
@@ -49,4 +49,9 @@
 my ($good, $msg) = RT::Interface::Web::AttemptPasswordAuthentication(\%ARGS);
 $ARGS{'actions'} = [$msg] if not $good and $msg;
 </%init>
+
+% if ( RT::Interface::Web::MobileClient() || $ARGS{mobile} ) {
+<& /m/login, %ARGS &>
+% } else {
 <& /Elements/Login, %ARGS &>
+% }
diff --git a/share/html/m/_elements/wrapper b/share/html/m/_elements/wrapper
index e15ab46..4bff8ce 100644
--- a/share/html/m/_elements/wrapper
+++ b/share/html/m/_elements/wrapper
@@ -50,8 +50,7 @@ $title => ''
 $show_home_button => 1
 </%args>
 <%init>
-if ($m->request_args->{'NotMobile'}) {
-    $session{'NotMobile'} = 1;
+if ($session{'NotMobile'}) {
     RT::Interface::Web::Redirect(RT->Config->Get('WebURL'));
     $m->abort();
 }
diff --git a/share/html/m/login b/share/html/m/login
index e39953c..443d87d 100644
--- a/share/html/m/login
+++ b/share/html/m/login
@@ -105,7 +105,7 @@ unless (!defined($uri->authority) || $uri->authority eq $uri_base_url->authority
 <& /Elements/Submit, Label => loc('Login')&>
 
 % foreach my $key (keys %ARGS) {
-%  if (($key ne 'user') and ($key ne 'pass')) {
+%  if ( $key !~ /^(?:user|pass|actions)$/ ) {
 % 	if (ref($ARGS{$key}) =~ /ARRAY/) {
 % 		foreach my $val (@{$ARGS{$key}}) {
 <input type="hidden" class="hidden" name="<%$key %>" value="<% $val %>" />

commit 06e8731d9c6b99f055ba35e8e0f6d351270aa303
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jul 3 01:20:06 2012 +0800

    mimic the login error message for mobile login

diff --git a/share/html/m/_elements/raw_style b/share/html/m/_elements/raw_style
index 2f3f3fd..2b3ea77 100644
--- a/share/html/m/_elements/raw_style
+++ b/share/html/m/_elements/raw_style
@@ -485,3 +485,12 @@ textarea {
 a#fullsite {
     padding-left: 1em;
 }
+
+div.error .titlebox-title {
+    background-color: #f00;
+    color: #fff;
+}
+
+div.error div.error {
+    background-color: #fcc;
+}
diff --git a/share/html/m/login b/share/html/m/login
index 443d87d..c01b2f7 100644
--- a/share/html/m/login
+++ b/share/html/m/login
@@ -81,12 +81,12 @@ unless (!defined($uri->authority) || $uri->authority eq $uri_base_url->authority
 </style>
 <h1><&|/l, RT->Config->Get('rtname') &>RT for [_1]</&></h1>
 <div id="body" class="login-body">
-% if ($Error) {
-<&| "/Widgets/TitleBox", title => loc('Error'), hideable => 0, class => 'error'  &>
-<% $Error %>
-</&>
-% }
 
+<& /Elements/ListActions,
+    title       => loc('Error'),
+    titlebox    => { class => 'error', hideable => 0 },
+    actions     => $actions,
+&>
 
 <div id="login-box">
 <&| /Widgets/TitleBox, title => loc('Login'), hideable => 0 &>
@@ -127,5 +127,5 @@ unless (!defined($uri->authority) || $uri->authority eq $uri_base_url->authority
 $user => ""
 $pass => undef
 $goto => undef
-$Error => undef
+$actions => undef
 </%ARGS>

commit 21ad631c27f021924db2346f8332503f986265e5
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Dec 14 13:36:07 2011 +0800

    basic login test

diff --git a/t/web/login.t b/t/web/login.t
new file mode 100644
index 0000000..da14f22
--- /dev/null
+++ b/t/web/login.t
@@ -0,0 +1,133 @@
+use strict;
+use warnings;
+
+use RT::Test tests => 34;
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+my $ticket = RT::Test->create_ticket(
+    Subject => 'ticket_foo',
+    Queue   => 'General',
+);
+
+my ( $user, $pass ) = ( 'root', 'password' );
+
+diag "normal login";
+{
+    $m->get($baseurl);
+    $m->title_is('Login');
+    is( $m->uri, $baseurl, "right url" );
+
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => 'wrong pass',
+        }
+    );
+    $m->content_contains( "Your username or password is incorrect",
+        'login error message' );
+    $m->warning_like( qr/FAILED LOGIN for root/,
+        "got failed login warning" );
+
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => $pass,
+        }
+    );
+
+    $m->title_is( 'RT at a glance', 'logged in' );
+
+    $m->follow_link_ok( { text => 'Logout' }, 'follow logout' );
+    $m->title_is( 'Logout', 'logout' );
+}
+
+diag "tangent login";
+
+{
+    $m->get( $baseurl . '/Ticket/Display.html?id=1' );
+    $m->title_is('Login');
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => $pass,
+        }
+    );
+    like( $m->uri, qr{/Ticket/Display\.html}, 'normal ticket page' );
+    $m->follow_link_ok( { text => 'Logout' }, 'follow logout' );
+}
+
+diag "mobile login with not mobile client";
+{
+    $m->get( $baseurl . '/m' );
+    is( $m->uri, $baseurl . '/m', "right url" );
+    $m->content_contains( "/m/index.html?NotMobile=1", 'mobile login' );
+
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => 'wrong pass',
+        }
+    );
+    $m->content_contains( "Your username or password is incorrect",
+        'login error message' );
+    $m->warning_like( qr/FAILED LOGIN for root/,
+        "got failed login warning" );
+
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => $pass,
+        }
+    );
+    is( $m->uri, $baseurl . '/m', "mobile url" );
+    $m->follow_link_ok( { text => 'Logout' }, 'follow logout' );
+    $m->content_contains( "/m/index.html?NotMobile=1",
+        'back to mobile login page' );
+    $m->content_lacks( 'Logout', 'really logout' );
+}
+
+
+diag "mobile normal login";
+{
+
+    # default browser in android 2.3.6
+    $m->agent(
+"Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus One Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
+    );
+
+    $m->get($baseurl);
+    is( $m->uri, $baseurl, "right url" );
+    $m->content_contains( "/m/index.html?NotMobile=1", 'mobile login' );
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => $pass,
+        }
+    );
+    is( $m->uri, $baseurl . '/m/', "mobile url" );
+    $m->follow_link_ok( { text => 'Logout' }, 'follow logout' );
+    $m->content_contains( "/m/index.html?NotMobile=1", 'back to mobile login page' );
+    $m->content_lacks( 'Logout', 'really logout' );
+}
+
+diag "mobile tangent login";
+{
+    $m->get( $baseurl . '/Ticket/Display.html?id=1' );
+    $m->content_contains( "/m/index.html?NotMobile=1", 'mobile login' );
+    $m->submit_form(
+        form_id => 'login',
+        fields  => {
+            user => $user,
+            pass => $pass,
+        }
+    );
+    like( $m->uri, qr{/m/ticket/show}, 'mobile ticket page' );
+}
+

-----------------------------------------------------------------------


More information about the Rt-commit mailing list