[Jifty-commit] r5820 - jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action

Jifty commits jifty-commit at lists.jifty.org
Fri Sep 12 12:21:13 EDT 2008


Author: sunnavy
Date: Fri Sep 12 12:21:12 2008
New Revision: 5820

Modified:
   jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm

Log:
extend Jifty/Plugin/Authentication/Password/Action/Login.pm so people can use username to login. email takes precedence of username

Modified: jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Authentication/Password/Action/Login.pm	Fri Sep 12 12:21:12 2008
@@ -21,9 +21,13 @@
 
 sub arguments { 
     return( { email => { label => _('Email'),
-                           mandatory => 1,
+                           mandatory => 0,
                            ajax_validates => 1,
-                            }  ,
+                            },
+              username => { label => _('Username'),
+                           mandatory => 0,
+                           ajax_validates => 1,
+                            },
 
               password => { type => 'password',
                             label => _('Password'),
@@ -58,12 +62,43 @@
     my $self  = shift;
     my $email = shift;
 
-    my $u = $self->load_user($email);
-    return $self->validation_error(email => _("It doesn't look like there's an account by that name.")) unless ($u->id);
+    unless ( $self->_validate_email_or_username(email => $email) ) {
+        return 1;
+    }
+    else {
+        return $self->validate_username( $self->argument_value('username') );
+    }
+}
+
+=head2 validate_username ADDRESS
+
+there's a user in the database with it.
+
+Overridden from Jifty::Action::Record.
+
+=cut
+
+sub validate_username {
+    my $self     = shift;
+    my $username = shift;
 
-    return $self->validation_ok('email');
+    return $self->_validate_email_or_username(username => $username);
 }
 
+sub _validate_email_or_username {
+    my $self  = shift;
+    my $name  = shift;
+    my $value = shift;
+
+    if ($value) {
+        my $u = $self->load_user($value);
+        return $self->validation_error(
+            $name => _("It doesn't look like there's an account by that name.")
+        ) unless ( $u->id );
+        return $self->validation_ok($name);
+    }
+    return;
+}
 
 =head2 validate_password PASSWORD
 
@@ -130,7 +165,9 @@
 
 sub take_action {
     my $self = shift;
-    my $user = $self->load_user( $self->argument_value('email') );
+    my $user =
+      $self->load_user( $self->argument_value('email')
+          || $self->argument_value('username') );
     my $password = $self->argument_value('password');
     my $token    = $self->argument_value('token') || '';
     my $hashedpw = $self->argument_value('hashed_password');


More information about the Jifty-commit mailing list