[vhffs-dev] [1576] Added "IRC nick" in user preferences.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1576
Author:   guillaumito
Date:     2010-03-27 00:11:07 +0100 (Sat, 27 Mar 2010)
Log Message:
-----------
Added "IRC nick" in user preferences. This new option is only
available to modo / admins as it doesn't make sense for non
moderating users.
Also added a get_by_ircnick function to fetch users by their
ircnick. This function has not been tested and is intended
to be used by pacman.
The new field in vhffs_users may need an unique constraint
and/or an index...

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-panel/templates/user/prefs.tmpl
    trunk/vhffs-panel/user/prefs.pl

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2010-03-26 00:28:08 UTC (rev 1575)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2010-03-26 23:11:07 UTC (rev 1576)
@@ -89,7 +89,7 @@
 
 
 sub _new {
-    my ($class, $main, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $lastloginpanel, $date_creation, $description, $state) = @_;
+    my ($class, $main, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $lastloginpanel, $ircnick, $date_creation, $description, $state) = @_;
     my $self = $class->SUPER::_new($main, $oid, $uid, $gid, $date_creation, $description, '', $state, Vhffs::Constants::TYPE_USER);
     return undef unless(defined $self);
     $self->{uid} = $uid;
@@ -111,6 +111,7 @@
     $self->{language} = $language;
     $self->{theme} = $theme;
     $self->{lastloginpanel} = $lastloginpanel;
+    $self->{ircnick} = $ircnick;
     return $self;
 }
 
@@ -270,11 +271,12 @@
     
     return -1 if( $self->SUPER::commit < 0 );
     
-    my $sql = 'UPDATE vhffs_users SET shell = ?, passwd = ?, admin = ?, firstname = ?, lastname = ?, address = ?, zipcode = ?, country = ?, mail = ?, city = ?, gpg_key = ? , note = ? , lastloginpanel = ? WHERE uid = ?';
+    my $sql = 'UPDATE vhffs_users SET shell = ?, passwd = ?, admin = ?, firstname = ?, lastname = ?, address = ?, zipcode = ?, country = ?, mail = ?, city = ?, gpg_key = ? , note = ? , lastloginpanel = ? , ircnick = ? WHERE uid = ?';
     my $sth = $self->{db}->prepare($sql) or return -1;
     $sth->execute($self->{'shell'}, $self->{'passwd'}, $self->{'admin'}, 
         $self->{'firstname'}, $self->{'lastname'}, $self->{'address'}, $self->{'zipcode'},
-        $self->{'country'}, $self->{'mail'}, $self->{'city'}, $self->{'gpg_key'}, $self->{'note'}, $self->{'lastloginpanel'}, $self->{'uid'}) or return -3;
+        $self->{'country'}, $self->{'mail'}, $self->{'city'}, $self->{'gpg_key'}, $self->{'note'}, $self->{'lastloginpanel'},
+        $self->{'ircnick'}, $self->{'uid'}) or return -3;
 
     return 1;
 }
@@ -524,6 +526,12 @@
     return( $self->{'lastloginpanel'} );
 }
 
+sub get_ircnick
+{
+    my $self = shift;
+    return( $self->{'ircnick'} );
+}
+
 sub set_shell
 {
     my $self = shift;
@@ -619,6 +627,13 @@
 	$self->{'lastloginpanel'} = time();
 }
 
+sub set_ircnick
+{
+    my $self = shift;
+    my $value = shift;
+    $self->{'ircnick'} = $value;
+}
+
 sub set_admin
 {
     my ( $self , $value ) = @_;
@@ -864,7 +879,7 @@
 
 sub get_by_uid {
     my ($main, $uid) = @_;
-    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
+    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
     my $dbh = $main->get_db_object;
     my @params = $dbh->selectrow_array($query, undef, $uid);
     return undef unless(@params);
@@ -886,7 +901,7 @@
 
 sub get_by_username {
     my ($main, $username) = @_;
-    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
+    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
     my $dbh = $main->get_db_object;
     my @params = $dbh->selectrow_array($query, undef, $username);
     return undef unless(@params);
@@ -896,6 +911,27 @@
 
 }
 
+=head2 get_by_ircnick
+
+    my $user = Vhffs::User::get_by_ircnick($main, $ircnick);
+    die('User not found') unless defined($user);
+
+Fetches an user using its IRC nick. Returned user is fully functional.
+
+=cut
+
+sub get_by_ircnick {
+    my ($main, $ircnick) = @_;
+    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.ircnick = ?';
+    my $dbh = $main->get_db_object;
+    my @params = $dbh->selectrow_array($query, undef, $ircnick);
+    return undef unless(@params);
+    my $user = _new Vhffs::User($main, @params);
+    $user->{group} = Vhffs::Group::get_by_gid($main, $user->get_gid);
+    return $user;
+
+}
+
 =head2 fill_object
 
 See C<Vhffs::Object::fill_object>.

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2010-03-26 00:28:08 UTC (rev 1575)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2010-03-26 23:11:07 UTC (rev 1576)
@@ -127,7 +127,9 @@
 	theme varchar(250),
 -- Last date user logged in
 	lastloginpanel int8,
-	CONSTRAINT vhffs_users_pkey PRIMARY KEY (uid)
+	CONSTRAINT vhffs_users_pkey PRIMARY KEY (uid),
+-- IRC nick
+	ircnick varchar(16)
 ) WITH OIDS;
 
 SELECT setval('vhffs_users_uid_seq', @MINUID@) ;

Modified: trunk/vhffs-panel/templates/user/prefs.tmpl
===================================================================
--- trunk/vhffs-panel/templates/user/prefs.tmpl	2010-03-26 00:28:08 UTC (rev 1575)
+++ trunk/vhffs-panel/templates/user/prefs.tmpl	2010-03-26 23:11:07 UTC (rev 1576)
@@ -76,6 +76,12 @@
 					<input type="checkbox" name="NEWSLETTER" id="NEWSLETTER" <TMPL_IF NAME="NEWSLETTER_CHECKED">checked="checked"</TMPL_IF>/>
 				</p>
 </TMPL_IF>
+<TMPL_IF NAME="MODO">
+                                <p>
+                                        <label for="IRCNICK"><TMPL_VAR ESCAPE=1 NAME="TEXT_IRCNICK"> :</label>
+                                        <input name="IRCNICK" id="IRCNICK" value="<TMPL_VAR ESCAPE=1 NAME="VALUE_IRCNICK">" type="text" />
+                                </p>
+</TMPL_IF>
 				<TMPL_VAR ESCAPE=0 NAME="MAILUSER">
 				
 				<p class="button" id="buttonModify">

Modified: trunk/vhffs-panel/user/prefs.pl
===================================================================
--- trunk/vhffs-panel/user/prefs.pl	2010-03-26 00:28:08 UTC (rev 1575)
+++ trunk/vhffs-panel/user/prefs.pl	2010-03-26 23:11:07 UTC (rev 1576)
@@ -98,6 +98,7 @@
 			my $shell = $cgi->param( 'SHELL' );
 			my $newslettercheckbox = $cgi->param('NEWSLETTER');
 			$newslettercheckbox = ( defined $newslettercheckbox && $newslettercheckbox eq 'on' );
+			my $ircnick = $cgi->param('IRCNICK');
 
 			my $pwd_change = 0;
 			my $mail_change = 0;
@@ -154,6 +155,9 @@
 				else {
 					$shell = Vhffs::Panel::User::default_shell( $ vhffs );
 				}
+				if( $ircnick !~ /^[^<">]+$/ ) {
+					$panel->add_error( gettext( 'IRC nick is not correct !') );
+				}
 
 				if(! $panel->has_errors) {
 					$userp->set_firstname(  $firstname );
@@ -163,6 +167,7 @@
 					$userp->set_country( $country );
 					$userp->set_address( $address );
 					$userp->set_shell( $shell );
+					$userp->set_ircnick( $ircnick );
 
 					if( ( length( $pass1 ) > 1 ) && ( $pass1 eq $pass2 ) ) { 
 						$pwd_change = 1;
@@ -469,6 +474,12 @@
 		}
 	}
 
+    if($userp->is_moderator || $userp->is_admin) {
+        $template->param( TEXT_IRCNICK => gettext('IRC nick') );
+        $template->param( VALUE_IRCNICK => $userp->get_ircnick);
+        $template->param( MODO => 1 );
+    }
+
     if($user->is_admin) {
     	my $adminpart = Vhffs::Panel::Object::admin_part( $panel, $userp );
     	$template->param( ADMIN_PART => $adminpart->output ) if( defined $adminpart );


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/