[vhffs-dev] [2189] improved user preferences, lang, theme, and shell are now handled the same way other entries are

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


Revision: 2189
Author:   gradator
Date:     2012-05-12 16:43:36 +0200 (Sat, 12 May 2012)
Log Message:
-----------
improved user preferences, lang, theme, and shell are now handled the same way other entries are

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/User.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-panel/templates/user/prefs.tt

Modified: trunk/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/User.pm	2012-05-12 14:02:23 UTC (rev 2188)
+++ trunk/vhffs-api/src/Vhffs/Panel/User.pm	2012-05-12 14:43:36 UTC (rev 2189)
@@ -57,23 +57,6 @@
 Provides methods which can be used when you need informations
 about users put don't want to use heavy objects.
 
-=head1 CONSTANTS
-
-=head2 RELATION_OWNER
-
-Constant to pass to C<get_groups> to restrict fetched groups
-to owned projects.
-
-=head2 RELATION_CONTRIB
-
-Constant to pass to C<get_groups> to restrict fetched groups
-to projects where user is not the owner.
-
-=cut
-
-our $RELATION_OWNER = 1;
-our $RELATION_CONTRIB = 2;
-
 =pod
 =head1 METHODS
 =cut
@@ -86,8 +69,7 @@
 
 =cut
 
-sub get_last_users
-{
+sub get_last_users {
 	my ($vhffs) = @_;
 
 	my $sql = 'SELECT u.uid, u.username, u.firstname, u.lastname '.
@@ -224,70 +206,19 @@
 	return \@users;
 }
 
-sub set_lang
-{
-	my $user = shift;
-	my $lang = shift;
-	return -1 unless defined $user and defined $lang;
-
-	my $sql = 'UPDATE vhffs_users SET language = ? WHERE uid = ?';
-	my $sth = $user->get_db->prepare($sql);
-	$sth->execute($lang, $user->get_uid) or return -1;
-	$user->{'language'} = $lang;
-	setlocale(LC_ALL, $lang);
-}
-
-
-sub set_theme
-{
-	my $user = shift;
-	my $theme = shift;
-	return -1 unless defined $user and defined $theme;
-
-	my $sql = 'UPDATE vhffs_users SET theme = ? WHERE uid = ?';
-	my $dbh = $user->get_db;
-	my $sth = $dbh->prepare($sql);
-	$sth->execute($theme, $user->get_uid) or return -1;
-	$user->{'theme'} = $theme;
-}
-
-sub get_lang {
-	my $user = shift;
-	return -1 unless defined $user;
-	return $user->get_lang;
-}
-
-
-sub get_theme {
-	my $user = shift;
-	return -1 unless defined $user;
-	my $theme = $user->get_theme;
-	$theme = $user->get_vhffs->get_config->get_panel->{'default_theme'} unless defined $theme;
-	return $theme;
-}
-
-
-sub get_shell {
-	my $user = shift;
-	return -1 unless defined $user;
-	return $user->get_shell;
-}
-
-
-sub list_shells {
+sub get_available_shells {
 	my $vhffs = shift;
 	return -1 unless defined $vhffs;
-	return split(/ /,$vhffs->get_config->get_users->{'available_shells'});
+	return split(/\s+/,$vhffs->get_config->get_users->{'available_shells'});
 }
 
 
-sub default_shell {
+sub get_default_shell {
 	my $vhffs = shift;
 	return -1 unless defined $vhffs;
 	return $vhffs->get_config->get_users->{'default_shell'};
 }
 
-
 sub prefs {
 	my $panel = shift;
 
@@ -338,17 +269,8 @@
 			my $pwd_change = 0;
 			my $mail_change = 0;
 
-			if( $userp->{'uid'} == $user->{'uid'} )  {
-				# Checks data and perform requested modifications
-				$panel->add_cookie( $cgi->cookie( -name=>'theme', -value=>$theme, -expires=>'+10y' ) );
-				Vhffs::Panel::User::set_theme( $userp, $theme );
-
-				$panel->add_cookie( $cgi->cookie( -name=>'language', -value=>$lang, -expires=>'+10y' ) );
-				Vhffs::Panel::User::set_lang( $userp, $lang );
-			}
-
 			# Commit all the changes for the current user
-			unless( defined $firstname and defined $lastname and defined $city and defined $mail and defined $zipcode and defined $country and defined $address and defined $shell )  {
+			unless( defined $firstname and defined $lastname and defined $city and defined $mail and defined $zipcode and defined $country and defined $address and defined $shell and defined $lang and defined $theme )  {
 				$panel->add_error( gettext( 'CGI Error !' ) );
 			}
 			else {
@@ -365,16 +287,22 @@
 				$panel->add_error( gettext( "Passwords don't match" ) ) unless defined $pass1 and defined $pass2 and $pass1 eq $pass2;
 
 				if( $userp->have_activegroups > 0 ) {
-					my $valid=0;
-					foreach( Vhffs::Panel::User::list_shells( $vhffs ) ) {
-						$valid = 1 if $shell eq $_;
+					unless( grep { $_ eq $shell } Vhffs::Panel::User::get_available_shells( $vhffs ) ) {
+						$panel->add_error( gettext( 'Wanted shell is not in the shell list' ) );
 					}
-					$panel->add_error( gettext( 'Wanted shell is not in the shell list' ) ) unless $valid;
 				}
 				else {
-					$shell = Vhffs::Panel::User::default_shell( $ vhffs );
+					$shell = Vhffs::Panel::User::get_default_shell( $vhffs );
 				}
 
+				unless( grep { $_ eq $lang } $vhffs->get_config->get_available_languages ) {
+					$panel->add_error( gettext( 'Wanted language is not in the language list' ) );
+				}
+
+				unless( grep { $_ eq $theme } $panel->get_available_themes ) {
+					$panel->add_error( gettext( 'Wanted theme is not in the theme list' ) );
+				}
+
 				unless( $panel->has_errors) {
 					$userp->set_firstname( $firstname );
 					$userp->set_lastname( $lastname );
@@ -382,6 +310,8 @@
 					$userp->set_zipcode( $zipcode );
 					$userp->set_country( $country );
 					$userp->set_address( $address );
+					$userp->set_lang( $lang );
+					$userp->set_theme( $theme );
 					$userp->set_shell( $shell );
 
 					if( length( $pass1 ) > 1 and $pass1 eq $pass2 ) {
@@ -564,18 +494,15 @@
 
 	$panel->set_title( gettext('User Preferences') );
 	$vars->{user} = $userp;
-	$vars->{current_language} = Vhffs::Panel::User::get_lang( $userp );
 	my @themes = $panel->get_available_themes;
 	$vars->{themes} = \@themes;
-	$vars->{current_theme} = Vhffs::Panel::User::get_theme( $userp );
 	$vars->{user_help_url} = $vhffs->get_config->get_users()->{url_doc};
 
-	if( $userp->have_activegroups )  {
-	        my @shells = Vhffs::Panel::User::list_shells( $vhffs );
+	if( $userp->have_activegroups > 0 )  {
+	        my @shells = Vhffs::Panel::User::get_available_shells( $vhffs );
 	        $vars->{shells} = \@shells;
-		$vars->{current_shell} = Vhffs::Panel::User::get_shell( $userp );
 	} else {
-	        $vars->{shells} = [ Vhffs::Panel::User::default_shell( $vhffs ) ];
+	        $vars->{shells} = [ Vhffs::Panel::User::get_default_shell( $vhffs ) ];
 	}
 
 	my $newsletter = new Vhffs::Services::Newsletter( $vhffs , $userp );

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2012-05-12 14:02:23 UTC (rev 2188)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2012-05-12 14:43:36 UTC (rev 2189)
@@ -372,11 +372,12 @@
 	return -1 unless defined $self->{'passwd'} and $self->{'passwd'} ne '';
 	return -2 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 = ? , ircnick = ? WHERE uid = ?';
+	my $sql = 'UPDATE vhffs_users SET shell = ?, passwd = ?, admin = ?, firstname = ?, lastname = ?, address = ?, zipcode = ?, country = ?, mail = ?, city = ?, gpg_key = ?, note = ?, language = ?, theme = ?, lastloginpanel = ?, ircnick = ? WHERE uid = ?';
 	my $sth = $self->get_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->{'country'}, $self->{'mail'}, $self->{'city'}, $self->{'gpg_key'}, $self->{'note'},
+		$self->{'language'}, $self->{'theme'}, $self->{'lastloginpanel'},
 		$self->{'ircnick'}, $self->{'uid'}) or return -3;
 
 	return 1;
@@ -941,6 +942,36 @@
 
 =pod
 
+=head2 set_lang
+
+	$user->set_lang( $langl );
+
+Set user language.
+
+=cut
+sub set_lang {
+	my $self = shift;
+	my $value = shift;
+	$self->{'language'} = $value;
+}
+
+=pod
+
+=head2 set_theme
+
+	$user->set_theme( $themel );
+
+Set user themeuage.
+
+=cut
+sub set_theme {
+	my $self = shift;
+	my $value = shift;
+	$self->{'theme'} = $value;
+}
+
+=pod
+
 =head2 update_lastloginpanel
 
 	$user->update_lastloginpanel;

Modified: trunk/vhffs-panel/templates/user/prefs.tt
===================================================================
--- trunk/vhffs-panel/templates/user/prefs.tt	2012-05-12 14:02:23 UTC (rev 2188)
+++ trunk/vhffs-panel/templates/user/prefs.tt	2012-05-12 14:43:36 UTC (rev 2189)
@@ -53,7 +53,7 @@
 					<label for="lang">[% 'Panel language:' | i18n | html %]</label>
                     <select name="lang" id="lang">
 [% FOREACH l IN languages %]
-                        <option value="[% l | html %]"[% ' selected="selected"' IF current_language == l %]>[% l | html %]</option>
+                        <option value="[% l | html %]"[% ' selected="selected"' IF user.get_lang == l %]>[% l | html %]</option>
 [% END %]
 					</select>
 				</p>
@@ -62,7 +62,7 @@
 					<label for="theme">[% 'Panel UI theme:' | i18n | html %]</label>
 					<select name="theme" id="theme">
 [% FOREACH t IN themes %]
-                        <option value="[% t | html %]"[% ' selected="selected"' IF current_theme == t %]>[% t | html %]</option>
+                        <option value="[% t | html %]"[% ' selected="selected"' IF user.get_theme == t %]>[% t | html %]</option>
 [% END %]
 					</select>
 				</p>
@@ -71,7 +71,7 @@
 					<label for="shell">[% 'Shell:' | i18n | html %]</label>
 					<select name="shell" id="shell">
 [% FOREACH s IN shells %]
-                        <option value="[% s | html %]"[% ' selected="selected"' IF current_shell == s %]>[% s | html %]</option>
+                        <option value="[% s | html %]"[% ' selected="selected"' IF user.get_shell == s %]>[% s | html %]</option>
 [% END %]
 					</select>
 				</p>


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