[vhffs-dev] [svn] commit: r227 - in /trunk/vhffs-panel: subscribe.pl subscribe_complete.pl templates/user/create.tmpl

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


Author: gradator
Date: Mon Oct 16 19:58:16 2006
New Revision: 227

Log:
remove intermediate script (subscribe_complete.pl), no need to fill again the form on error


Removed:
    trunk/vhffs-panel/subscribe_complete.pl
Modified:
    trunk/vhffs-panel/subscribe.pl
    trunk/vhffs-panel/templates/user/create.tmpl

Modified: trunk/vhffs-panel/subscribe.pl
==============================================================================
--- trunk/vhffs-panel/subscribe.pl (original)
+++ trunk/vhffs-panel/subscribe.pl Mon Oct 16 19:58:16 2006
@@ -29,53 +29,223 @@
 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 # POSSIBILITY OF SUCH DAMAGE.
 
-
-
-use strict;
+# subscribe.pl
+# Handle subscription for VHFFS
+# If the subscribe form has been submitted
+# we try to create the user, else display
+# the form. If there is an error we inform the
+# user and redisplay the form (already filled)
+#
+
+use POSIX qw(locale_h);
 use CGI;
 use locale;
+use Locale::gettext;
+use HTML::Template;
+
+use Vhffs::User;
 use Vhffs::Main;
+use Vhffs::Functions;
 use Vhffs::Constants;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Confirmation;
-use POSIX qw(locale_h);
-use HTML::Template;
-use Locale::gettext;
-
-my $vhffs 			= init Vhffs::Main;
-my $templatedir 	= $vhffs->get_config->get_templatedir;
-my $template;
-my $confirmation;
+
+#Get some basics informations with CGI
+my $cgi;
+my $uid;
+my $good_news;
+my $vhffs;
+my $templatedir;
+my $cid;
+my $realcode;
+my $code;
+
+$cgi = new CGI;
+
+#Initialize vars
+$good_news = "";
+
+#Init the Vhffs Main System
+$vhffs = init Vhffs::Main;
+$templatedir = $vhffs->get_config->get_templatedir;
 
 Vhffs::Panel::Main::check( $vhffs );
 Vhffs::Panel::Main::cook_lang( $vhffs );
 
+
+$submitted	= $cgi->param( "CREATE_SUBMIT" );
+$mail 		= $cgi->param( "MAIL" );
+$username 	= $cgi->param( "USERNAME" );
+$firstname 	= $cgi->param( "FIRSTNAME");
+$lastname 	= $cgi->param( "LASTNAME" );
+$city 		= $cgi->param("CITY");
+$zipcode 	= $cgi->param("ZIPCODE");
+$country 	= $cgi->param("COUNTRY");
+$address 	= $cgi->param("ADDRESS");
+$cid 		= $cgi->param("CID");
+$code 		= $cgi->param("CONFIRMATION");
+$realcode	= Vhffs::Panel::Confirmation::get_code( $vhffs , $cid );
+
+my $template;
+my $message;
+
 if( $vhffs->get_config->get_allow_subscribe == 0 )
 {
-	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl");
-	$template->param( MESSAGE => gettext("You cannot subscribe to VHFFS") );
+# Subscribe isn't allow, inform user
+        $template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl");
+        $template->param( MESSAGE => gettext("You cannot subscribe to VHFFS") );
+} elsif( defined $submitted ) {
+# don't check if form hasn't been submitted
+	@errors = ();
+	if( ( ! defined $cid ) || ( ! defined $code ) || ( $code ne $realcode ) )
+	{
+		push(@errors, {error => gettext("Codes do not match")});
+	}
+	if( ! defined $username )
+	{
+		push(@errors, {error => gettext("You must declare your username")});
+	}
+	if( ( length ( $username ) < 3 ) || ( length ( $username ) > 12 ) )
+	{
+		push(@errors, {error => gettext("Username must contain between 3 and 12 characters")});
+	}
+	if( ! defined $country )
+	{
+		push(@errors, {error => gettext("You must declare your country")});
+	}
+	if( ! defined $city )
+	{
+		push(@errors, {error => gettext("You must declare your city")});
+	}
+	if( ! defined $zipcode )
+	{
+		push(@errors, {error => gettext("You must declare your zipcode")});
+	}
+	if( ! defined $firstname )
+	{
+		push(@errors, {error => gettext("You must declare your firstname")});
+	}
+	if( ! defined $lastname )
+	{
+		push(@errors, {error => gettext("You must declare your lastname")});
+	}
+	if( ( ! defined $mail ) || ( length( $mail ) < 6 ) )
+	{
+		push(@errors, {error => gettext("You must declare your mail address")});
+	}
+	if( Vhffs::Functions::valid_mail( $mail ) == -1 )
+	{
+		push(@errors, {error => gettext("You must declare a valid mail address")});
+	}
+	if( ! ( $zipcode =~ /^[\d]+$/ ) )
+	{
+		push(@errors, {error => gettext("Your zipcode is not correct! Please enter a correct zipcode")});
+	}
+	if( ! ( $firstname =~ /^[\w\d\s\-]+$/ ) )
+	{
+                push(@errors, {error => gettext("Please enter a correct firstname")});
+	}
+	if( ! ( $lastname =~ /^[\w\d\s\-]+$/ ) )
+	{
+                push(@errors, {error => gettext("Please enter a correct firstname")});
+	}
+	if( ! ( $city =~ /^[^(\(\)\\\.\_\e\'\")]+$/ ) )
+	{
+                push(@errors, {error => gettext("Please enter a correct city")});
+	}
+	if( ! ( $country =~ /^[\w\d\s\-\s]+$/ ) )
+	{
+            push(@errors, {error => gettext("Please enter a correct country")});
+	}
+
+	if( ( scalar @errors )  == 0)
+	{
+	    my $retour;
+	    my $user = new Vhffs::User( $vhffs , $username , '401' );
+	    if( defined $user )
+	    {
+		$uid = $user->create;
+		
+		if( $uid < 0 )
+		{
+		    #If the API returns a negative value as uid, the user cannot be created !
+		    push( @errors, {error => gettext("Cannot create user, the username you entered already exists")});
+		}
+		else
+		{
+		    #Get user information
+		    $user->fetch;
+		    
+		    #We set informations user fill in the form
+		    $user->set_mail( $mail );
+		    $user->set_firstname( $firstname );
+		    $user->set_lastname( $lastname );
+		    $user->set_city( $city );
+		    $user->set_zipcode( $zipcode );
+		    $user->set_country( $country );
+		    $user->set_address( $address );
+		    $user->set_status( Vhffs::Constants::WAITING_FOR_CREATION );
+		    $user->set_password( Vhffs::Functions::generate_random_password );			
+		    
+		    #Commit all the changes for the current user
+		    if( ( $retour = $user->commit ) < 0 )
+		    {
+			push ( @errors, { error => gettext("Cannot apply changes to the user") } );
+		    }
+		    else
+		    {
+			$good_news = gettext("User Successfully created");
+			$good_news2 = gettext("Please wait while we are creating the account, it will take some minutes");
+			$template = new HTML::Template( filename => $templatedir."/user/create_complete.tmpl" );
+	    		$template->param( TEXT_BACK => gettext("Back to Login") );
+			$template->param( GOOD_NEWS => $good_news );
+			$template->param( GOOD_NEWS2 => $good_news2 );
+		    }
+		}
+		
+	    } else {
+		push ( @errors, { error => gettext("Cannot create user. Your username should contain at least 3 characters which are only lower case and digits.") } );
+	    }
+	}
+	if ( ( scalar @errors ) > 0 ) {
+	    $template = new HTML::Template( filename => $templatedir."/user/create.tmpl" );
+	    # There was an error, fill the template parameter
+	    $template->param( ERRORS => \@errors );
+	    $template->param( USERNAME_VALUE         => $username );
+	    $template->param( MAIL_VALUE             => $mail );
+	    $template->param( FIRSTNAME_VALUE        => $firstname );
+	    $template->param( LASTNAME_VALUE         => $lastname );
+	    $template->param( ZIPCODE_VALUE          => $zipcode );
+	    $template->param( CITY_VALUE             => $city );
+	    $template->param( COUNTRY_VALUE          => $country );
+	    $template->param( ADDRESS_VALUE          => $address );
+
+	}
+} else {
+    $template = new HTML::Template( filename => $templatedir."/user/create.tmpl" );
 }
-else
-{
-	$template 		= new HTML::Template( filename => $templatedir."/user/create.tmpl" );
-	$confirmation	=	Vhffs::Panel::Confirmation::create_code( $vhffs );
-	
-	$template->param( TITLE 			=> gettext("Subscription ") );
-	$template->param( TEXT_SUBSCRIBE 	=> gettext("Subscription") );
-	$template->param( TEXT_INFOS 		=> gettext("Please fill in all fields, a mail containing your password will be sent to you") );
-	$template->param( USERNAME_TEXT 	=> gettext("Username") );
-	$template->param( MAIL_TEXT 		=> gettext("mail") );
-	$template->param( FIRSTNAME_TEXT 	=> gettext("Firstname") );
-	$template->param( LASTNAME_TEXT 	=> gettext("Lastname") );
-	$template->param( ZIPCODE_TEXT 		=> gettext("Zipcode") );
-	$template->param( CITY_TEXT 		=> gettext("City") );
-	$template->param( COUNTRY_TEXT 		=> gettext("Country") );
-	$template->param( ADDRESS_TEXT 		=> gettext("Address") );
-	$template->param( SEND 				=> gettext("Subscribe") );
-	$template->param( BACK 				=> gettext("Back to Login") );
-	$template->param( CONFIRMATION_TEXT	=> gettext("Code confirmation") );
-	$template->param( REPEAT_CONFIRMATION_TEXT	=> gettext("Recopy the code") );
-	$template->param( CID				=> $confirmation->[0] );
+
+if( ( ! defined $submitted ) || ( ( defined @errors) && ( (scalar @errors) != 0 ) ) ) {
+    $confirmation  = Vhffs::Panel::Confirmation::create_code( $vhffs );
+
+# $template is defined in every cases
+
+    $template->param( TEXT_SUBSCRIBE        => gettext("Subscription") );
+    $template->param( TEXT_INFOS            => gettext("Please fill in all fields, a mail containing your password will be sent to you") );
+    $template->param( USERNAME_TEXT         => gettext("Username") );
+    $template->param( MAIL_TEXT             => gettext("mail") );
+    $template->param( FIRSTNAME_TEXT        => gettext("Firstname") );
+    $template->param( LASTNAME_TEXT         => gettext("Lastname") );
+    $template->param( ZIPCODE_TEXT          => gettext("Zipcode") );
+    $template->param( CITY_TEXT             => gettext("City") );
+    $template->param( COUNTRY_TEXT          => gettext("Country") );
+    $template->param( ADDRESS_TEXT          => gettext("Address") );
+    $template->param( SEND                  => gettext("Subscribe") );
+    $template->param( BACK                  => gettext("Back to Login") );
+    $template->param( CONFIRMATION_TEXT     => gettext("Code confirmation") );
+    $template->param( REPEAT_CONFIRMATION_TEXT      => gettext("Recopy the code") );
+    $template->param( CID                   => $confirmation->[0] );
+
 }
-
+$template->param( TITLE => gettext("Subscribe") );
 display_light Vhffs::Panel::Main($template);

Modified: trunk/vhffs-panel/templates/user/create.tmpl
==============================================================================
--- trunk/vhffs-panel/templates/user/create.tmpl (original)
+++ trunk/vhffs-panel/templates/user/create.tmpl Mon Oct 16 19:58:16 2006
@@ -18,71 +18,75 @@
 			<h1><tmpl_var name="TEXT_SUBSCRIBE"></h1>
 			
 			<div class="subscribe">
-			<form method="post" action="subscribe_complete.pl">
+			<form method="post" action="subscribe.pl">
+                        <tmpl_loop name="ERRORS">
+                                <p style="font-weight:bold;color:red;"><tmpl_var name="ERROR"></p>
+                        </tmpl_loop>
 			<h2><tmpl_var name="TEXT_INFOS"></h2>
+
 				<p>
 					<label for="USERNAME">
 						<TMPL_VAR NAME="USERNAME_TEXT">
 					</label>
-					<input type="text" name="USERNAME" id="USERNAME" maxlength="32"/>
+					<input type="text" name="USERNAME" id="USERNAME" maxlength="32" value="<TMPL_VAR NAME="USERNAME_VALUE">"/>
 				</p>
 				<p>
 					<label for="MAIL">
 						<TMPL_VAR NAME="MAIL_TEXT">
 					</label>
-					<input type="text" name="MAIL" id="MAIL" maxlength="32" />
+					<input type="text" name="MAIL" id="MAIL" maxlength="32" value="<TMPL_VAR NAME="MAIL_VALUE">"/>
 				</p>
 				<p>
 					<label for="FIRSTNAME">
 						<TMPL_VAR NAME="FIRSTNAME_TEXT">
 					</label>
-					<input type="text" name="FIRSTNAME" id="FIRSTNAME" maxlength="256" />
+					<input type="text" name="FIRSTNAME" id="FIRSTNAME" maxlength="256" value="<TMPL_VAR NAME="FIRSTNAME_VALUE">" />
 				</p>
 				<p>
 					<label for="LASTNAME">
 						<TMPL_VAR NAME="LASTNAME_TEXT">
 					</label>
-					<input type="text" name="LASTNAME" id="LASTNAME" maxlength="256"/>
+					<input type="text" name="LASTNAME" id="LASTNAME" maxlength="256" value="<TMPL_VAR NAME="LASTNAME_VALUE">"/>
 				</p>
 				<p>
 					<label for="ADDRESS">
 						<TMPL_VAR NAME="ADDRESS_TEXT">
 					</label>
-					<input type="text" name="ADDRESS" id="ADDRESS" maxlength="512"/>
+					<input type="text" name="ADDRESS" id="ADDRESS" maxlength="512" value="<TMPL_VAR NAME="ADDRESS_VALUE">"/>
 				</p>
 				<p>
 					<label for="CITY">
 						<TMPL_VAR NAME="CITY_TEXT">
 					</label>
-					<input type="text" name="CITY" id="CITY" maxlength="64"/>
+					<input type="text" name="CITY" id="CITY" maxlength="64" value="<TMPL_VAR NAME="CITY_VALUE">"/>
 				</p>
 				<p>
 					<label for="COUNTRY">
 						<TMPL_VAR NAME="COUNTRY_TEXT">
 					</label>
-					<input type="text" name="COUNTRY" id="COUNTRY" maxlength="32"/>
+					<input type="text" name="COUNTRY" id="COUNTRY" maxlength="32" value="<TMPL_VAR NAME="COUNTRY_VALUE">"/>
 				</p>
 				<p>
 					<label for="ZIPCODE">
 						<TMPL_VAR NAME="ZIPCODE_TEXT">
 					</label>
-					<input type="text" name="ZIPCODE" id="ZIPCODE" maxlength="16"/>
+					<input type="text" name="ZIPCODE" id="ZIPCODE" maxlength="16" value="<TMPL_VAR NAME="ZIPCODE_VALUE">"/>
 				</p>
 				<p>
-					<label for="ZIPCODE">
+					<label for="CONFIRMATION">
 						<TMPL_VAR NAME="CONFIRMATION_TEXT">
 					</label>
 						<img src="show_code.pl?cid=<TMPL_VAR NAME="CID">"/>
 				</p>
 				<p>
-					<label for="ZIPCODE">
+					<label for="CONFIRMATION">
 						<TMPL_VAR NAME="REPEAT_CONFIRMATION_TEXT">
 					</label>
-					<input type="text" name="CONFIRMATION"  maxlength="16"/>
+					<input type="text" name="CONFIRMATION"  id="CONFIRMATION" maxlength="16"/>
 				</p>
 				<p class="button">
 					<input type="hidden" name="CID" value="<TMPL_VAR NAME="CID">"/>
-					<input type="submit" value="<TMPL_VAR NAME="SEND">" />
+					<input type="submit" value="<TMPL_VAR NAME="SEND">" name="CREATE_SUBMIT"/>
 				</p>
 			
 			</form>




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