plainblack.com
Username Password
search
Bookmark and Share
WebGUI::User has no way to get a user when you only know their username  (#448)
Issue

There is currently no method in WebGUI::User.pm for getting a user object when you only know the username. I needed that for a project I was working on, so I wrote one (it's pasted below).

It would be stellar if this or something w/ equivalent functionality ended up in WebGUI 7.4.

Thanks!

 

#-------------------------------------------------------------------

=head2 newByUsername ( session, username )

Instanciates a user by username. Returns undef if the username could not be found.

=head3 session

A reference to the current session.

=head3 username

The username to search for.

=cut

sub newByUsername {
  my $class = shift;
  my $session = shift;
  my $username = shift;
  my ($id) = $session->dbSlave->quickArray("select userId from users where username=?",[$username]);
  my $user = $class->new($session, $id);
  return undef if ($user->userId eq "1"); # visitor is never valid for this method
  return undef unless $user->username;
  return $user;
Solution Summary
Comments
perlDreamer
0
7/6/2007 11:59 am
I have this prototyped and tested for 7.4.  If it is approved, then I'll commit it.
JT
0
7/6/2007 12:02 pm
approved for
perlDreamer
0
7/6/2007 12:08 pm

Committed for 7.4.

cap10morgan, please contact me with your real name so that I can give you props in the changelog, for submitting a patch. 

cap10morgan
0
7/6/2007 12:38 pm
My real name is Wes Morgan. I work for U.S. PIRG (http://www.uspirg.org/). Thanks guys!
perlDreamer
0
7/12/2007 4:37 pm
This RFE has been added to the core, so it can be closed.
Details
Ticket Status Closed  
Rating0.0 
Submitted By cap10morgan  
Date Submitted2007-07-06 
Assigned To unassigned  
Date Assigned 2010-09-02  
Assigned By  
What to improve?  
URLbugs/tracker/webguiuser-has-no-way-to-get-a-user-when-you-only-know-their-username
Karma
Difficulty 1  
Karma So Far200
Karma Rank200.00
Keywords
Ticket History
© 2010 Plain Black Corporation | All Rights Reserved