WebGUI
      Click here to register.
      
irc://irc.freenode.net#webgui

iPhoneGuy: WebGUI is a pile of crap.
rizen: If WebGUI is such a pile of crap, why do you use it?
iPhoneGuy: Because it's the best pile of crap out there.

If this is what people who hate us are saying, imagine what people who love us will say. Come join us on IRC.


     Request Features > Request For Enhancement

WebGUI::User has no way to get a user when you only know their username

User cap10morgan
Date 7/6/2007 10:58 am
Version WebGUI 7.3.19
Views 418
Rating 5    Rate [
|
]
Difficulty 1
Karma So Far 200
Karma Rank 200.000000
Transfer Karma
Previous · Next
User Message
cap10morgan

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;
}

Back to Top  
 
colink
I have this prototyped and tested for 7.4.  If it is approved, then I'll commit it.


Back to Top  
 
JT
approved for 7.4

Back to Top  
 
colink

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. 



Back to Top  
 
cap10morgan
My real name is Wes Morgan. I work for U.S. PIRG (http://www.uspirg.org/). Thanks guys!


Back to Top  
 
colink
This RFE has been added to the core, so it can be closed.

Back to Top