(file) Return to register.cgi CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / bin

  1 rizwank 1.1 #!/usr/bin/perl -wT
  2             #
  3             # TWiki Collaboration Platform, http://TWiki.org/
  4             #
  5             # Copyright (C) 1999-2004 Peter Thoeny, peter@thoeny.com
  6             #
  7             # For licensing info read license.txt file in the TWiki root.
  8             # This program is free software; you can redistribute it and/or
  9             # modify it under the terms of the GNU General Public License
 10             # as published by the Free Software Foundation; either version 2
 11             # of the License, or (at your option) any later version.
 12             #
 13             # This program is distributed in the hope that it will be useful,
 14             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 15             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16             # GNU General Public License for more details, published at 
 17             # http://www.gnu.org/copyleft/gpl.html
 18             
 19             BEGIN {
 20                 # Set default current working directory
 21                 if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~ /^(.+)\/[^\/]+$/ ) {
 22 rizwank 1.1         chdir $1;
 23                 }
 24                 # Set library paths in @INC at compile time
 25                 unshift @INC, '.';
 26                 require 'setlib.cfg';
 27             }
 28             
 29             # I18N: No locale settings necessary yet - only 7-bit ASCII due
 30             # to Apache limitations on userids.
 31             
 32             
 33             use CGI::Carp qw(fatalsToBrowser);
 34             use CGI;
 35             use TWiki;
 36             use TWiki::Net;
 37             use TWiki::Plugins;
 38             use TWiki::User;
 39             
 40             &main();
 41             
 42             sub main
 43 rizwank 1.1 {
 44                 my $query = new CGI;
 45             
 46                 # get all parameters from the form
 47                 my @paramNames = $query->param();
 48                 my @formDataName = ();
 49                 my @formDataValue = ();
 50                 my @formDataRequired = ();
 51                 my $name = "";
 52                 my $value = "";
 53                 my $emailAddress = "";
 54                 my $firstLastName = "";
 55                 my $wikiName = "";
 56                 my $remoteUser = "";
 57                 my $passwordA = "";
 58                 my $passwordB = "";
 59             
 60                 foreach( @paramNames ) {
 61                     if( /^(Twk)([0-9])(.*)/ ) {
 62                         $value = $query->param( "$1$2$3" );
 63                         $formDataRequired[@formDataRequired] = $2;
 64 rizwank 1.1             $name = $3;
 65             	    # TODO: I18N fix here ???
 66                         $name =~ s/([a-z0-9])([A-Z0-9])/$1 $2/go; # Space the names
 67                         $name =~ s/(AIM)(Screen)/$1 $2/go;  # Horrible hack to space AIMScreen
 68                         $formDataName[@formDataName] = $name;
 69                         $formDataValue[@formDataValue] = $value;
 70             
 71                         if( $name eq "Name" ) {
 72                             $firstLastName = $value;
 73                         } elsif( $name eq "Wiki Name" ) {
 74                             $wikiName = $value;
 75                         } elsif( $name eq "Login Name" ) {
 76                             $remoteUser = $value;
 77                         } elsif( $name eq "Email" ) {
 78                             $emailAddress = $value;
 79                         } elsif( $name eq "Password" ) {
 80                             $passwordA = $value;
 81                         } elsif( $name eq "Confirm" ) {
 82                             $passwordB = $value;
 83                         }
 84                     }
 85 rizwank 1.1     }
 86                 my $formLen = @formDataValue;
 87             
 88                 my $topicName = $query->param( 'TopicName' );
 89                 my $thePathInfo = $query->path_info(); 
 90                 my $theUrl = $query->url;
 91                 ( $topic, $webName ) = 
 92             	&TWiki::initialize( $thePathInfo, $wikiName, $topicName, $theUrl, $query );
 93             
 94                 my $text = "";
 95                 my $url = "";
 96             
 97                 # check if user entry already exists
 98                 if(  ( $wikiName ) 
 99                   && (  ( &TWiki::Store::topicExists( $webName,  $wikiName ) )
100                      || ( TWiki::User::UserPasswordExists( $wikiName ) ) 
101                      ) ) {
102                     # PTh 20 Jun 2000: changed to getOopsUrl
103                     $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregexist", $wikiName );
104                     TWiki::redirect( $query, $url );
105                     return;
106 rizwank 1.1     }
107             
108                 # check if required fields are filled in
109                 my $x;
110                 for( $x = 0; $x < $formLen; $x++ ) {
111                     if( ( $formDataRequired[$x] ) && ( ! $formDataValue[$x] ) ) {
112                         $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregrequ", );
113                         TWiki::redirect( $query, $url );
114                         return;
115                     }
116                 }
117             
118                 # check if wikiName is a WikiName
119                 if( ! &TWiki::isWikiName( $wikiName ) ) {
120                     $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregwiki" );
121                     TWiki::redirect( $query, $url );
122                     return;
123                 }
124             
125                 # a WikiName is safe, so untaint variable
126                 $wikiName =~ /(.*)/;
127 rizwank 1.1     $wikiName = $1;
128             
129                 # check if passwords are identical
130                 if ( $passwordA ne $passwordB ) {
131                     $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregpasswd" );
132                     TWiki::redirect( $query, $url );
133                     return;
134                 }
135             
136                 # check valid email address
137                 if( $emailAddress !~ $TWiki::regex{emailAddrRegex} ) {
138                     $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregemail" );
139                     TWiki::redirect( $query, $url );
140                     return;
141                 }
142             
143             
144                 # everything OK
145             
146                 # generate user entry and add to .htpasswd file
147                 unless( $remoteUser ) {
148 rizwank 1.1         if ( ! TWiki::User::AddUserPassword($wikiName, $passwordA ) ) {
149             	    $url = &TWiki::getOopsUrl( $webName, $topic, "oopsregerr" );
150                    	    TWiki::redirect( $query, $url );
151                         return;
152             	}
153                 }
154             
155                 # send email confirmation
156                 my $skin = $query->param( "skin" ) || TWiki::Prefs::getPreferencesValue( "SKIN" );
157                 $text = TWiki::Store::readTemplate( "registernotify", $skin );
158                 $text =~ s/%FIRSTLASTNAME%/$firstLastName/go;
159                 $text =~ s/%WIKINAME%/$wikiName/go;
160                 $text =~ s/%EMAILADDRESS%/$emailAddress/go;
161                 ( $before, $after) = split( /%FORMDATA%/, $text );
162                 for( $x = 0; $x < $formLen; $x++ ) {
163                     $name = $formDataName[$x];
164                     $value = $formDataValue[$x];
165                     if( ( $name eq "Password" ) && ( $TWiki::doHidePasswdInRegistration ) ) {
166                         $value = "*******";
167                     }
168                     if( $name ne "Confirm" ) {
169 rizwank 1.1             $before .= "   * $name\: $value\n";
170                     }
171                 }
172                 $text = "$before$after";
173                 $text = &TWiki::handleCommonTags( $text, $wikiName );
174                 $text =~ s/( ?) *<\/?(nop|noautolink)\/?>\n?/$1/gois;   # remove <nop> and <noautolink> tags
175             
176                 my $senderr = &TWiki::Net::sendEmail( $text );
177             
178                 # create user topic if it does not exist
179                 if( ! &TWiki::Store::topicExists( $TWiki::mainWebname, $wikiName ) ) {
180                     my $meta = "";
181                     my $row = "";
182                     ( $meta, $text ) = &TWiki::Store::readTemplateTopic( "NewUserTemplate" );
183                     $text = "%SPLIT%\n\t* %KEY%: %VALUE%%SPLIT%\n" unless $text;
184                     ( $before, $repeat, $after) = split( /%SPLIT%/, $text );
185                     for( $x = 0; $x < $formLen; $x++ ) {
186                         $name = $formDataName[$x];
187                         $value = $formDataValue[$x];
188                         $value =~ s/[\n\r]/ /go;
189                         if( ! (    ( $name eq "Wiki Name" )
190 rizwank 1.1                     || ( $name eq "Password" )
191                                 || ( $name eq "Confirm" ) ) ) {
192                             $row = $repeat;
193                             $row =~ s/%KEY%/$name/go;
194                             $row =~ s/%VALUE%/$value/go;
195                             $before .= $row;
196                         }
197                     }
198                     $text = "$before$after";
199             
200                    my $userName = $remoteUser || $wikiName;
201                    $text = TWiki::expandVariablesOnTopicCreation( $text, $userName, $wikiName, "$webName.$wikiName" );
202             
203                     $meta->put( "TOPICPARENT", ( "name" => $TWiki::wikiUsersTopicname ) );
204                     &TWiki::Store::saveTopic( $webName, $wikiName, $text, $meta, "", 1 );
205                 }
206             
207                 # Plugin callback to set cookies. Contrib by SvenDowideit
208                 &TWiki::Plugins::registrationHandler( $webName, $wikiName, $remoteUser );
209             
210                 # add user to TWikiUsers topic
211 rizwank 1.1     my $userTopic = TWiki::User::addUserToTWikiUsersTopic( $wikiName, $remoteUser );
212             
213                 # write log entry
214                 if( $TWiki::doLogRegistration ) {
215                     &TWiki::Store::writeLog( "register", "$webName.$wikiName", $emailAddress, $wikiName );
216                 }
217             
218                 if( $senderr ) {
219                     my $url = &TWiki::getOopsUrl( $webName, $wikiName, "oopssendmailerr", $senderr );
220                     TWiki::redirect( $query, $url );
221                 }
222             
223                 # and finally display thank you page
224                 $url = &TWiki::getOopsUrl( $webName, $wikiName, "oopsregthanks", $emailAddress );
225                 TWiki::redirect( $query, $url );
226             }
227             
228             
229             # EOF

Rizwan Kassim
Powered by
ViewCVS 0.9.2