[vhffs-dev] [2191] Added language field on Vhffs::User::create.

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


Revision: 2191
Author:   gradator
Date:     2012-05-12 17:40:18 +0200 (Sat, 12 May 2012)
Log Message:
-----------
Added language field on Vhffs::User::create.
Now using the current panel cookie language into user preferences in the subscription process.
Added welcome mail messages to gettext strings.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Subscribe.pm
    trunk/vhffs-api/src/Vhffs/Panel.pm
    trunk/vhffs-api/src/Vhffs/Robots/User.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-tools/src/vhffs-useradd

Modified: trunk/vhffs-api/src/Vhffs/Panel/Subscribe.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Subscribe.pm	2012-05-12 15:02:45 UTC (rev 2190)
+++ trunk/vhffs-api/src/Vhffs/Panel/Subscribe.pm	2012-05-12 15:40:18 UTC (rev 2191)
@@ -105,8 +105,8 @@
 		$panel->add_error( gettext('Please enter a correct country') ) unless defined $country and $country !~ /^[<>"]+$/;
 
 		unless( $panel->has_errors ) {
-			my $user = Vhffs::User::create( $vhffs, $username, Vhffs::Functions::generate_random_password(),
-			  0, $mail, $firstname, $lastname, $city, $zipcode, $country, $address, '');
+			my $user = Vhffs::User::create( $vhffs, $username, undef, 0,
+			  $mail, $firstname, $lastname, $city, $zipcode, $country, $address, undef, $panel->get_lang);
 
 			unless( defined $user )  {
 				$panel->add_error( gettext('Cannot create user, the username you entered already exists') );

Modified: trunk/vhffs-api/src/Vhffs/Panel.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel.pm	2012-05-12 15:02:45 UTC (rev 2190)
+++ trunk/vhffs-api/src/Vhffs/Panel.pm	2012-05-12 15:40:18 UTC (rev 2191)
@@ -342,6 +342,16 @@
 	$panel->{infos} = [];
 }
 
+sub get_lang {
+	my $panel = shift;
+	return $panel->{lang};
+}
+
+sub get_theme {
+	my $panel = shift;
+	return $panel->{theme};
+}
+
 =head2 $panel->render($file, $vars, $layout)
 
 Renders given template with substitution variables C<$vars>.

Modified: trunk/vhffs-api/src/Vhffs/Robots/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/User.pm	2012-05-12 15:02:45 UTC (rev 2190)
+++ trunk/vhffs-api/src/Vhffs/Robots/User.pm	2012-05-12 15:40:18 UTC (rev 2191)
@@ -68,8 +68,8 @@
 	chown $user->get_uid, $user->get_gid, $dir;
 	chmod 0700, $dir;
 
-	my $subject = sprintf("Account created on %s", $vhffs->get_config->get_host_name );
-	my $content = sprintf("Hello %s %s,\n\nWe are pleased to announce that your account is now fully created on\n%s.\nYou can now login on the panel.\n\n%s Administrators\n",
+	my $subject = sprintf( gettext('Account created on %s'), $vhffs->get_config->get_host_name );
+	my $content = sprintf( gettext("Hello %s %s,\n\nWe are pleased to announce that your account is now fully created on\n%s.\nYou can now login on the panel.\n\n%s Administrators\n"),
 		$user->get_firstname, $user->get_lastname, $vhffs->get_config->get_host_name, $vhffs->get_config->get_host_name );
 	$user->send_mail_user( $subject, $content );
 

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2012-05-12 15:02:45 UTC (rev 2190)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2012-05-12 15:40:18 UTC (rev 2191)
@@ -134,13 +134,13 @@
 
 	my $user = Vhffs::User::create($vhffs, $username, $password, $admin,
 		$mail, $firstname, $lastname, $city, $zipcode,
-		$country, $address, $gpg_key);
+		$country, $address, $gpg_key, $language);
 
 Create in DB and return a fully functional user.
 
 =cut
 sub create {
-	my ( $vhffs, $username, $password, $admin, $mail, $firstname, $lastname, $city, $zipcode, $country, $address, $gpg_key ) = @_;
+	my ( $vhffs, $username, $password, $admin, $mail, $firstname, $lastname, $city, $zipcode, $country, $address, $gpg_key, $language ) = @_;
 	return undef unless check_username($username);
 
 	my $userconf = $vhffs->get_config->get_users;
@@ -180,11 +180,12 @@
 
 		# Insert base information
 		$admin = 0 unless (defined $admin);
-		$password = Vhffs::Functions::generate_random_password() if( not defined $password or $password eq '' );
+		$password = Vhffs::Functions::generate_random_password() unless defined $password and $password !~ /^\s+$/;
+		$language = $vhffs->get_config->get_default_language unless defined $language and grep { $_ eq $language } $vhffs->get_config->get_available_languages;
 		my $homedir = $vhffs->get_config->get_datadir.'/home/'.substr( $username, 0, 1 ).'/'.substr( $username, 1, 1 ).'/'.$username;
 
 		my $sth = $dbh->prepare('INSERT INTO vhffs_users (uid, gid, username, shell, passwd, homedir, admin, firstname, lastname, address, zipcode, city, country, mail, gpg_key, note, language, theme, lastloginpanel, object_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, NULL, NULL, ?)');
-		$sth->execute($uid, $gid, $username, $userconf->{'default_shell'}, password_encrypt($password), $homedir, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $vhffs->get_config->get_default_language, $parent->get_oid);
+		$sth->execute($uid, $gid, $username, $userconf->{'default_shell'}, password_encrypt($password), $homedir, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $language, $parent->get_oid);
 
 		my $group = Vhffs::Group::create($vhffs, $username, undef, $uid, $gid);
 		die('Error creating group') unless (defined $group);
@@ -202,8 +203,8 @@
 		undef $user;
 	}
 	else {
-		my $subject = sprintf("Welcome on %s", $vhffs->get_config->get_host_name );
-		my $content = sprintf("Hello %s %s, Welcome on %s\n\nHere are your login information :\nUser: %s\nPassword: %s\n\nYour account is NOT created yet, you cannot login on the panel now, you\nare going to receive another mail in a few minutes upon account creation.\n\n%s Administrators\n", $user->get_firstname, $user->get_lastname, $vhffs->get_config->get_host_name, $user->get_username, $password , $vhffs->get_config->get_host_name );
+		my $subject = sprintf( gettext('Welcome on %s'), $vhffs->get_config->get_host_name );
+		my $content = sprintf( gettext("Hello %s %s, Welcome on %s\n\nHere are your login information :\nUser: %s\nPassword: %s\n\nYour account is NOT created yet, you cannot login on the panel now, you\nare going to receive another mail in a few minutes upon account creation.\n\n%s Administrators\n"), $user->get_firstname, $user->get_lastname, $vhffs->get_config->get_host_name, $user->get_username, $password , $vhffs->get_config->get_host_name );
 		$user->send_mail_user( $subject, $content );
 	}
 

Modified: trunk/vhffs-tools/src/vhffs-useradd
===================================================================
--- trunk/vhffs-tools/src/vhffs-useradd	2012-05-12 15:02:45 UTC (rev 2190)
+++ trunk/vhffs-tools/src/vhffs-useradd	2012-05-12 15:40:18 UTC (rev 2191)
@@ -52,7 +52,7 @@
 print 'Address: ';
 chomp($address = <STDIN>);
 
-my $user = Vhffs::User::create( $vhffs, $username, $password, $access_level, $mail, $firstname, $lastname, $city, $zipcode, $country, $address, "");
+my $user = Vhffs::User::create( $vhffs, $username, $password, $access_level, $mail, $firstname, $lastname, $city, $zipcode, $country, $address, undef, undef);
 
 
 if(defined $user) {


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