[vhffs-dev] [534] User preferences now uses only one page ( no more prefs_save + redirection).

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


Revision: 534
Author:   beuss
Date:     2007-03-29 07:01:26 +0000 (Thu, 29 Mar 2007)

Log Message:
-----------
User preferences now uses only one page (no more prefs_save + redirection).
Login process refreshes theme and language based on user preferences
(avoid theme and language loss when cookies are deleted).

Modified Paths:
--------------
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Commons.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Main.pm
    branches/vhffs_4.1/vhffs-panel/auth.pl
    branches/vhffs_4.1/vhffs-panel/templates/main/auth.tmpl
    branches/vhffs_4.1/vhffs-panel/templates/main/panel.tmpl
    branches/vhffs_4.1/vhffs-panel/templates/user/prefs.tmpl
    branches/vhffs_4.1/vhffs-panel/themes/vhffs/main.css
    branches/vhffs_4.1/vhffs-panel/themes/vhffs-ng/main.css
    branches/vhffs_4.1/vhffs-panel/user/prefs.pl

Removed Paths:
-------------
    branches/vhffs_4.1/vhffs-panel/user/prefs_save.pl


Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Commons.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Commons.pm	2007-03-29 07:01:26 UTC (rev 534)
@@ -42,6 +42,7 @@
     my ($vhffs, $panel) = @_;
 
     my $hostname = $vhffs->get_config->get_host_name;
+    my $cgi = $panel->{cgi};
 
     my $templatedir = $panel->{templatedir};
     my $template = new HTML::Template( filename => $templatedir."/main/auth.tmpl" );
@@ -51,6 +52,7 @@
     $template->param( VHFFS_INFO => sprintf( "Run VHFFS %s (%s)" , Vhffs::Constants::VHFFS_VERSION , Vhffs::Constants::VHFFS_RELEASE_NAME ) );
     $template->param( TEXT_PLEASEIDENTIFY => gettext("Please enter your username and password") );
     $template->param( TEXT_USERNAME => gettext("Username") );
+    $template->param( VALUE_USERNAME => $cgi->param('username') );
     $template->param( TEXT_PASSWORD => gettext("Password") );
     $template->param( TEXT_LOGIN => gettext("Access to panel") );
     $template->param( TEXT_LOSTPASSWORD => gettext("I've lost my password") );

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Main.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Main.pm	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Main.pm	2007-03-29 07:01:26 UTC (rev 534)
@@ -226,6 +226,9 @@
 	my $config = $vhffs->get_config;
 	my $templatedir = $vhffs->get_config->get_templatedir;
 
+    # We need to create an object now in order
+    # to be able to call display if something
+    # fails
     my $this = {};
 	$this->{vhffs} = $vhffs;
 	$this->{templatedir} = $templatedir;
@@ -241,9 +244,6 @@
 
 
 	# fetch the cookie which contain the sessions ID and the session
-    # if sarge didn't use out of date package (CGI::Session 3.95 is
-    # FOUR years old!) we could simply use CGI::Session->load an see
-    # id the session is expired.
 	my $sid = $cgi->cookie(CGI::Session::name());
 	if( ! defined $sid ) {
 		$bad_news = gettext("No cookie found, please accept the cookie and then please login again !");
@@ -318,6 +318,12 @@
     return (@{$self->{errors}} > 0);
 }
 
+sub set_title
+{
+    my ($self, $title) = @_;
+    $self->{template}->param( TEXT_TITLE => $title );
+}
+
 sub add_error
 {
     my ($self, $error) = @_;
@@ -330,6 +336,12 @@
     push(@{$self->{infos}}, {msg => $info});
 }
 
+sub clear_infos
+{
+    my $self = shift;
+    $self->{infos} = [];
+}
+
 sub right_first
 {
 	my ( $class , $vhffs , $session , $user ) = @_;
@@ -634,13 +646,18 @@
 	my $maintemplate = $panel->{'template'};
 	$maintemplate->param( CENTRE => $content );
     if(@{$panel->{errors}} > 0) {
-        my $tmplerrors = new HTML::Template( filename => $panel->{templatedir}."/misc/errors.tmpl" );
+        my $tmplerrors = new HTML::Template( filename => $panel->{templatedir}.'/misc/errors.tmpl' );
         $tmplerrors->param( ERRORS => $panel->{errors} );
         $maintemplate->param( ERRORS => $tmplerrors->output );
     }
 
-	if( defined $panel->{'group'} )
-	{
+    if(@{$panel->{infos}} > 0) {
+        my $tmplinfos = new HTML::Template( filename => $panel->{templatedir}.'misc/infos.tmpl' );
+        $tmplinfos->param( INFOS => $panel->{infos} );
+        $maintemplate->param( INFOS => $tmplinfos->output );
+    }
+
+	if( defined $panel->{'group'} ) {
 		$maintemplate->param( GROUPNAME => sprintf( gettext( "Current group: %s" ) , $panel->{'group'}->get_groupname )  );
 	}
 
@@ -726,19 +743,30 @@
 
 =head2 redirect
 
-    $panel->redirect($page, $cookie);
+    $panel->redirect($page, $cookies);
 
 Issues a redirection header sending to $page
-(you can specify an additional cookie to be send).
+(you can specify additional cookies to be send).
 
 This function never returns.
 
 B<C<$page> should be an absolute path>
 
+B<C<$cookies>> can be a CGI::Cookie or a reference
+to a CGI::Cookie array.
+
 =cut
 sub redirect {
-    my ($self, $dest, $cookie) = @_;
-    print "Set-Cookie: $cookie\n";
+    my ($self, $dest, $cookies) = @_;
+    if(defined $cookies) {
+        if(ref($cookies)) {
+            foreach(@$cookies) {
+                print "Set-Cookie: $_\n";
+            }
+        } else {
+            print "Set-Cookie: $cookies\n";
+        }
+    }
     print CGI::redirect($dest);
     exit(0);
 }

Modified: branches/vhffs_4.1/vhffs-panel/auth.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/auth.pl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/auth.pl	2007-03-29 07:01:26 UTC (rev 534)
@@ -76,8 +76,14 @@
         $session->param("username", $user->get_username);
         $session->param("uid", $user->get_uid);
 
-        my $cookie = new CGI::Cookie(-name => $session->name, -value => $session->id);
-        $panel->redirect('/panel.pl', $cookie);
+        my $sessioncookie = new CGI::Cookie(-name => $session->name, -value => $session->id);
+
+        # Refresh cookies (avoid theme and language loss when user
+        # deletes cookies).
+        my $themecookie = new CGI::Cookie( -name=> 'theme', -value=>$user->get_theme, -expires=>'+10y' );
+        my $langcookie = new CGI::Cookie( -name=>'language', -value=>$user->get_lang, -expires=>'+10y' );
+
+        $panel->redirect('/panel.pl', [$sessioncookie, $themecookie, $langcookie]);
     }
 }
 

Modified: branches/vhffs_4.1/vhffs-panel/templates/main/auth.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/templates/main/auth.tmpl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/templates/main/auth.tmpl	2007-03-29 07:01:26 UTC (rev 534)
@@ -29,7 +29,7 @@
 					<label for="username">
 						<tmpl_var name="TEXT_USERNAME">
 					</label>
-					<input type="text" name="username" id="username" maxlength="32" />
+					<input type="text" name="username" id="username" maxlength="32" value="<tmpl_var name="VALUE_USERNAME">"/>
 				</p>
 				<p>
 					<label for="password">

Modified: branches/vhffs_4.1/vhffs-panel/templates/main/panel.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/templates/main/panel.tmpl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/templates/main/panel.tmpl	2007-03-29 07:01:26 UTC (rev 534)
@@ -21,6 +21,9 @@
 	<tmpl_var name="GROUPNAME">
 	</div>
 <div class="main" id="main">
+    <h1><tmpl_var name="TEXT_TITLE"></h1>
+    <tmpl_var name="errors">
+    <tmpl_var name="infos">
 	<tmpl_var name="CENTRE">
 </div>
 

Modified: branches/vhffs_4.1/vhffs-panel/templates/user/prefs.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/templates/user/prefs.tmpl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/templates/user/prefs.tmpl	2007-03-29 07:01:26 UTC (rev 534)
@@ -1,8 +1,5 @@
 
-			<form method="post" action="/user/prefs_save.pl">
-	
-				<h1><tmpl_var name="TEXT_TITLE"></h1>
-	
+			<form method="post" action="/user/prefs.pl">
 				<p>
 					<label><tmpl_var name="TEXT_USERNAME"> :</label>
 					<span class="formInput"><tmpl_var name="VALUE_USERNAME"></span>
@@ -71,7 +68,7 @@
 
 				
 				<p class="button" id="buttonModify">
-					<input  type="submit"  value="<tmpl_var name="TEXT_SEND">"/>
+					<input  type="submit"  value="<tmpl_var name="TEXT_SEND">" name="prefs_submit" id="prefs_submit"/>
 				</p>
 			</form>
 

Modified: branches/vhffs_4.1/vhffs-panel/themes/vhffs/main.css
===================================================================
--- branches/vhffs_4.1/vhffs-panel/themes/vhffs/main.css	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/themes/vhffs/main.css	2007-03-29 07:01:26 UTC (rev 534)
@@ -683,6 +683,13 @@
     font-weight: bold;
 }
 
+.info
+{
+    color:blue;
+    text-align: center;
+    width: 50%;
+    font-weight: bold;
+}
 
 .warning
 {

Modified: branches/vhffs_4.1/vhffs-panel/themes/vhffs-ng/main.css
===================================================================
--- branches/vhffs_4.1/vhffs-panel/themes/vhffs-ng/main.css	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/themes/vhffs-ng/main.css	2007-03-29 07:01:26 UTC (rev 534)
@@ -477,6 +477,13 @@
     font-weight:bold;
 }
 
+.info
+{
+    color:blue;
+    text-align: center;
+    width: 50%;
+    font-weight: bold;
+}
 
 .warning
 {

Modified: branches/vhffs_4.1/vhffs-panel/user/prefs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/user/prefs.pl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/user/prefs.pl	2007-03-29 07:01:26 UTC (rev 534)
@@ -46,35 +46,190 @@
 use Vhffs::Panel::User;
 
 my $panel = new Vhffs::Panel::Main();
-if(!$panel)  {
-        exit 0;
+my $cgi = $panel->{cgi};
+my $vhffs = $panel->{vhffs};
+my $session = $panel->{session};
+my $maintemplate = $panel->{template};
+my $user = $panel->{user};
+
+my $submitted = defined($cgi->param('prefs_submit'));
+
+if($submitted) {
+    my $mail = $cgi->param( "MAIL" );
+    my $firstname = $cgi->param( "FIRSTNAME" );
+    my $lastname = $cgi->param( "LASTNAME" );
+    my $city = $cgi->param( "CITY" );
+    my $zipcode = $cgi->param( "ZIPCODE" );
+    my $country = $cgi->param( "COUNTRY" );
+    my $address = $cgi->param( "ADDRESS" );
+    my $pass1 = $cgi->param("PASSWORD1");
+    my $pass2 = $cgi->param("PASSWORD2");
+
+    my $theme = $cgi->param( "THEME" );
+    my $lang = $cgi->param( "LANG" );
+
+    my $pwd_change = 0;
+    my $mail_change = 0;
+
+
+    # Checks data and perform requested modifications
+    $panel->{'themecookie'} = CGI->cookie( -name=>"theme", -value=>$theme, -expires=>'+10y' );
+    Vhffs::Panel::User::set_theme( $user, $theme );
+
+    $panel->{'langcookie'} = CGI->cookie( -name=>"language", -value=>$lang, -expires=>'+10y' );
+    Vhffs::Panel::User::set_lang( $user, $lang );
+
+
+# Commit all the changes for the current user
+if( ( ! defined $firstname ) || ( ! defined $lastname ) || ( ! defined $city ) || ( ! defined $mail ) || ( ! defined $zipcode ) || ( ! defined $country ) || ( ! defined $address ) ) {
+    $panel->add_error( gettext( "CGI Error!" ) );
+} else {
+    if( ! ( $zipcode =~ /^[\w\d\s\-]+$/ ) ) {
+        $panel->add_error( gettext( "Zipcode is not correct !" ) );
+    }
+    if( $pass1 ne $pass2 ) {
+        $panel->add_error( gettext( "Passwords don't match" ) );
+    }
+    if(! $panel->has_errors) {
+        $user->set_firstname(  $firstname );
+        $user->set_lastname(  $lastname );
+        $user->set_city(  $city );
+        $user->set_zipcode( $zipcode );
+        $user->set_country( $country );
+        $user->set_address( $address );
+
+        if( ( length( $pass1 ) > 1 ) && ( $pass1 eq $pass2 ) ) { 
+            $pwd_change = 1;
+            $user->set_password( $pass1 );
+            $panel->add_info( gettext('Password changed') );
+        }
+
+        my $prevmail = $user->get_mail();
+        if( $prevmail ne $mail ) {
+            $mail_change = 1;
+            $user->set_mail( $mail );
+            my $subject = gettext("Mailbox modified");
+            my $content = sprintf( gettext("Hello %s %s,\n\nYou changed your email, here are your new personal information :\n\nUser: %s\nMail: %s\n\nVHFFS administrators\n"), $user->get_firstname, $user->get_lastname, $user->get_username, $user->get_mail);
+            $user->send_mail_user( $subject, $content );
+            $panel->add_info( gettext('Email address changed') );
+        }
+
+        if( $user->commit < 0 ) {
+            $panel->clear_infos();
+            $panel->add_error( gettext("An error occured while updating the user account") );
+        }
+
+        my $mu; 
+        if( $vhffs->get_config->use_mailuser == 1 ) {
+            use Vhffs::Services::MailUser;
+            $mu = init Vhffs::Services::MailUser( $vhffs , $user );
+        }
+
+    # check if mu is not a negative integer
+        if( defined $mu  &&  $mu >= 0  &&  $mu->available > 0 )  {
+
+            my $mail_activate = $cgi->param( "mail_activate" );
+            my $nospam = $cgi->param( "mail_nospam" );
+            my $novirus = $cgi->param( "mail_novirus" );
+            $nospam = (( defined $nospam ) && ( $nospam eq "on" ));
+            $novirus = ( ( defined $novirus ) && ( $novirus eq "on" ) );
+    
+            if( ( defined $mail_activate ) && ( $mail_activate eq "on" ) ) {
+                my $usage = $cgi->param( "mail_usage" );
+                if( ! defined $usage ) {
+                    $panel->add_error( gettext("You must choose a method for your mail") );
+                } elsif( $usage == 1 ) {
+                  #In this case, we treat for popable accounts
+                    if( $mu->exists_box == 0 ) {
+                        # Box doesn't exists, need a password
+                         if( $pwd_change == 0 ) {
+                             $panel->add_error( gettext("Error ! You MUST provide a password in your account when you create your popable account") );
+                         } elsif( ($mu->addbox ($pass1 )) < 0 ) {
+                             $panel->add_error( gettext("An error occured while adding the box") );
+                         } elsif( $nospam && ( $mu->change_spam_status < 0 ) ) {
+                             $panel->add_error( gettext("An error occured while adding the box (anti-spam adding)") );
+                         } elsif( $novirus && ( $mu->change_virus_status < 0 ) ) {
+                             $panel->add_error( gettext("An error occured while adding the box (anti-virus adding)") );
+                         } else {
+                             $panel->add_info( gettext("Mailbox successfully added") );
+                         }
+                    } else {
+                        #Box already exists
+                        # The use changed his password, we must update password for mail
+                        if( $pwd_change ) {
+                            $mu->delbox;
+                            $mu->addbox( $pass1 );
+                        }
+
+                        # We change the spam status. if the spam status changed
+                        if( $vhffs->get_config->use_nospam == 1 ) {
+                            if( $nospam != $mu->use_nospam ) {
+                                if( $mu->change_spam_status == 1 ) {
+                                    $panel->add_info( gettext( "Change spam protection status for your account\n" ) );
+                                } else {
+                                    $panel->add_error( gettext( "Error for spam protection\n" ) );
+                                }
+                            }
+                        }
+
+                        # As spam, the virus status changes only if the user changed values
+                        if( $vhffs->get_config->use_novirus == 1 ) {
+                            if( $novirus != $mu->use_novirus ) {
+                                if( $mu->change_virus_status == 1 ) {
+                                    $panel->add_info( gettext( "Changed anti-virus status for your account\n" ) );
+                                } else {
+                                    $panel->add_error( gettext( "Error for virus protection\n" ) );
+                                }
+                            }
+                        }
+                    }
+                } elsif( $usage == 2 ) {
+                    #Here, we create the forward
+                    my $ad = $user->get_mail;
+                    if(  $mu->exists_forward == 0 ) {
+                        if( ! defined $ad ) {
+                            $panel->add_error( gettext("There is a problem with the address you filled in your profile, unable to add forwarding") );
+                        } elsif( $mu->addforward( $user->get_mail ) < 0) {
+                            $panel->add_error(  gettext("An error occured while adding the forwarding") );
+                        } else {
+                            $panel->add_info( gettext('Forward added') );
+                        }
+                    } elsif( $mail_change ==1 ) {
+                        $mu->delforward;
+                        if( $mu->addforward( $mail ) < 0 ) {
+                                $panel->add_error( gettext("An error occured while the forwarding") );
+                        } else {
+                            $panel->add_info( gettext('Forward updated') );
+                        }
+                    }
+                }
+            } elsif($mu->exists_box || $mu->exists_forward) {
+                $panel->add_info( gettext('Mail deleted') );
+                # User doesn't want mail anymore
+                $mu->delbox;
+                $mu->delforward;
+            }
+        }    
+    }
 }
+} # if($submitted)
 
-my $vhffs = $panel->{'vhffs'};
-my $session = $panel->{'session'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-
 my $mailuser;
 
-if( $vhffs->get_config->use_mailuser == 1 )
-{
-	$mailuser = 1;
+if( $vhffs->get_config->use_mailuser == 1 ) {
+    $mailuser = 1;
+} else {
+    $mailuser = 0;
 }
-else
-{
-	$mailuser = 0;
-}
 
 my $username = $user->get_username();
 my $usermail = $user->get_mail();
 
+$panel->set_title( gettext("User Preferences") );
+
 my $templatedir = $vhffs->get_config->get_templatedir;
-
 my $template = new HTML::Template( filename => $templatedir."/user/prefs.tmpl" );
 
-$template->param( TEXT_TITLE => gettext("User Preferences") );
-
 $template->param( TEXT_USERNAME => gettext("Username") );
 $template->param( TEXT_MAIL => gettext("mail") );
 $template->param( TEXT_FIRSTNAME => gettext("Firstname") );
@@ -143,14 +298,10 @@
 my @langs = Vhffs::Panel::Main::list_languages( $vhffs );
 my $curlang = Vhffs::Panel::User::get_lang( $user );
 my $langlist;
-foreach( @langs )
-{
-	if($curlang ne $_)
-	{
+foreach( @langs ) {
+	if($curlang ne $_) {
 		$langlist .= "<option value=\"".$_."\">".$_."</option>\n";
-	}
-	else
-	{
+	} else {
 		$langlist .= "<option value=\"".$_."\" selected=\"selected\">".$_."</option>\n";
 	}
 }

Deleted: branches/vhffs_4.1/vhffs-panel/user/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/user/prefs_save.pl	2007-03-28 13:11:45 UTC (rev 533)
+++ branches/vhffs_4.1/vhffs-panel/user/prefs_save.pl	2007-03-29 07:01:26 UTC (rev 534)
@@ -1,291 +0,0 @@
-#!/usr/bin/perl -w
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-
-use POSIX qw(locale_h);
-use HTML::Template;
-use locale;
-use Locale::gettext;
-use CGI;
-use CGI::Session;
-use strict;
-
-use lib "/usr/share/vhffs/api/";
-use Vhffs::User;
-use Vhffs::Main;
-use Vhffs::Panel::Main;
-use Vhffs::Panel::Menu;
-use Vhffs::Panel::User;
-
-my $panel = new Vhffs::Panel::Main();
-if(!$panel)  {
-        exit 0;
-}
-
-my $vhffs = $panel->{'vhffs'};
-my $session = $panel->{'session'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-my $cgi = $panel->{'cgi'};
-
-my $message;
-
-my $mail = $cgi->param( "MAIL" );
-my $firstname = $cgi->param( "FIRSTNAME" );
-my $lastname = $cgi->param( "LASTNAME" );
-my $city = $cgi->param( "CITY" );
-my $zipcode = $cgi->param( "ZIPCODE" );
-my $country = $cgi->param( "COUNTRY" );
-my $address = $cgi->param( "ADDRESS" );
-my $pass1 = $cgi->param("PASSWORD1");
-my $pass2 = $cgi->param("PASSWORD2");
-
-my $theme = $cgi->param( "THEME" );
-my $lang = $cgi->param( "LANG" ); 
-
-my $pwd_change = 0;
-my $mail_change = 0;
-my $templatedir = $vhffs->get_config->get_templatedir;
-
-# We set informations user fill in the form
-
-
-$panel->{'themecookie'} = CGI->cookie( -name=>"theme", -value=>$theme, -expires=>'+10y' );
-Vhffs::Panel::User::set_theme( $user, $theme );
-
-$panel->{'langcookie'} = CGI->cookie( -name=>"language", -value=>$lang, -expires=>'+10y' );
-Vhffs::Panel::User::set_lang( $user, $lang );
-
-
-# Commit all the changes for the current user
-if( ( ! defined $firstname ) || ( ! defined $lastname ) || ( ! defined $city ) || ( ! defined $mail ) || ( ! defined $zipcode ) || ( ! defined $country ) || ( ! defined $address ) )
-{
-	$message = gettext( "CGI Error!" );
-}
-elsif( ! ( $zipcode =~ /^[\w\d\s\-]+$/ ) )
-{
-	$message = gettext( "Zipcode is not correct !" );
-}
-elsif( $pass1 ne $pass2 )
-{
-	$message = gettext( "Passwords don't match" );
-}
-else
-{
-	$user->set_firstname(  $firstname );
-	$user->set_lastname(  $lastname );
-	$user->set_city(  $city );
-	$user->set_zipcode( $zipcode );
-	$user->set_country( $country );
-	$user->set_address( $address );
-
-	if( ( length( $pass1 ) > 1 ) && ( $pass1 eq $pass2 ) )
-	{ 
-		$pwd_change = 1;
-		$user->set_password( $pass1 );
-	}
-
-	my $prevmail = $user->get_mail();
-	if( $prevmail ne $mail )
-	{
-		$mail_change = 1;	
-		$user->set_mail( $mail );
-		my $subject = gettext("Mailbox modified");
-		my $content = sprintf( gettext("Hello %s %s,\n\nYou changed your email, here are your new personal information :\n\nUser: %s\nMail: %s\n\nVHFFS administrators\n"), $user->get_firstname, $user->get_lastname, $user->get_username, $user->get_mail);
-		$user->send_mail_user( $subject, $content );
-	}
-
-	if( $user->commit < 0 )
-	{
-		$message = gettext("An error occured while updating the user account");
-	}
-	else
-	{
-		$message = gettext("User Successfully modified") . "<br>";
-	}
-
-	my $mu;	
-	if( $vhffs->get_config->use_mailuser == 1 )
-	{
-		use Vhffs::Services::MailUser;
-		$mu = init Vhffs::Services::MailUser( $vhffs , $user );
-	}
-
-	# check if mu is not a negative integer
-	if( defined $mu  &&  $mu >= 0  &&  $mu->available > 0 )  {
-
-		my $mail_activate = $cgi->param( "mail_activate" );
-		my $nospam = $cgi->param( "mail_nospam" );
-		my $novirus = $cgi->param( "mail_novirus" );
-		if( ( defined $nospam ) && ( $nospam eq "on" ) )
-		{
-			$nospam = 1;
-		}
-		else
-		{
-			$nospam = 0;
-		}
-		if( ( defined $novirus ) && ( $novirus eq "on" ) )
-		{
-			$novirus = 1;
-		}
-		else
-		{
-			$novirus = 0;
-		}
-
-		if( ( defined $mail_activate ) && ( $mail_activate eq "on" ) )
-		{
-			my $usage = $cgi->param( "mail_usage" );
-			if( ! defined $usage )
-			{
-				$message = gettext("You must choose a method for your mail");	
-			}
-			elsif( $usage == 1 )
-			{
-
-				#In this case, we treat for popable accounts
-				if( $mu->exists_box == 0 )
-				{
-					if( $pwd_change == 0 )
-					{
-						$message = gettext("Error ! You MUST provide a password in your account when you create your popable account");
-					}
-					elsif( ($mu->addbox ($pass1 )) < 0 )
-					{
-						$message = gettext("An error occured while adding the box");
-					}
-					elsif( ( $nospam == 1 ) && ( $mu->change_spam_status < 0 ) )
-					{
-						$message = gettext("An error occured while adding the box (anti-spam adding)");
-					}
-					elsif( ( $novirus == 1 ) && ( $mu->change_virus_status < 0 ) )
-					{
-						$message = gettext("An error occured while adding the box (anti-virus adding)");
-					}
-					else
-					{
-						$message .= "<br/>";
-						$message .= gettext("Mailbox successfully added");
-					}
-				}
-				else
-				{
-					# The use changed his password, we must update password for mail
-					if( $pwd_change == 1 )
-					{
-						$mu->delbox;
-						$mu->addbox( $pass1 );
-					}
-
-					# We change the spam status. if the spam status changed
-					if( $vhffs->get_config->use_nospam == 1 )
-					{
-						if( $nospam != $mu->use_nospam )
-						{
-							if( $mu->change_spam_status == 1 )
-							{
-								$message .= gettext( "Change spam protection status for your account\n" );
-								$message .= "<br/>";
-							}
-							else
-							{
-								$message .= gettext( "Error for spam protection\n" );
-								$message .= "<br/>";
-							}
-						}
-					}
-
-					# As spam, the virus status changes only if the user changed values
-					if( $vhffs->get_config->use_novirus == 1 )
-					{
-						if( $novirus != $mu->use_novirus )
-						{
-							if( $mu->change_virus_status == 1 )
-							{
-								$message .= gettext( "Change anti-virus status for your account\n" );
-								$message .= "<br/>";
-							}
-							else
-							{
-								$message .= gettext( "Error for virus protection\n" );
-								$message .= "<br/>";
-							}
-						}
-					}
-				}
-			}
-			elsif( $usage == 2 ) 
-			{
-				#Here, we create the forward
-				my $ad = $user->get_mail;
-				if(  $mu->exists_forward == 0 )
-				{
-					if( ! defined $ad )
-					{
-						$message = "<br>" . gettext("There is a problem with the address you filled in your profile, unable to add forwarding");
-					}
-					else
-					{
-						if( $mu->addforward( $user->get_mail ) < 0)
-						{
-							$message = gettext("An error occured while adding the forwarding");
-						}
-					}
-				}
-				else
-				{
-					#Here, we update the forward
-					if( $mail_change ==1 )
-					{
-						$mu->delforward;
-						if( $mu->addforward( $mail ) < 0 )
-						{
-							$message .= "<br>" . gettext("An error occured while the forwarding");
-							
-						}
-					}
-				}
-			}
-		}
-		else
-		{
-			$mu->delbox;
-			$mu->delforward;
-		}
-	}
-	
-}
-my $template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
-$template->param( MESSAGE => $message );
-
-set_refresh_url Vhffs::Panel::Main($panel, "/user/prefs.pl", 0);
-display Vhffs::Panel::Main($panel, $template->output);


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