(file) Return to User.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / twiki / lib / TWiki

  1 rizwank 1.1 # Module of TWiki Collaboration Platform, http://TWiki.org/
  2             #
  3             # Copyright (C) 1999-2004 Peter Thoeny, peter@thoeny.com
  4             #
  5             # For licensing info read license.txt file in the TWiki root.
  6             # This program is free software; you can redistribute it and/or
  7             # modify it under the terms of the GNU General Public License
  8             # as published by the Free Software Foundation; either version 2
  9             # of the License, or (at your option) any later version.
 10             #
 11             # This program is distributed in the hope that it will be useful,
 12             # but WITHOUT ANY WARRANTY; without even the implied warranty of
 13             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14             # GNU General Public License for more details, published at 
 15             # http://www.gnu.org/copyleft/gpl.html
 16             #
 17             # Notes:
 18             # - Latest version at http://twiki.org/
 19             # - Installation instructions in $dataDir/Main/TWikiDocumentation.txt
 20             # - Customize variables in TWiki.cfg when installing TWiki.
 21             # - Optionally change TWiki.pm for custom extensions of rendering rules.
 22 rizwank 1.1 # - Upgrading TWiki is easy as long as you do not customize TWiki.pm.
 23             # - Check web server error logs for errors, i.e. % tail /var/log/httpd/error_log
 24             #
 25             
 26             =begin twiki
 27             
 28             ---+ TWiki::User Package
 29             
 30             This module hosts the user authentication implementation
 31             
 32             =cut
 33             
 34             package TWiki::User;
 35             
 36             #use File::Copy;
 37             #use Time::Local;
 38             
 39             #if( $TWiki::OS eq "WINDOWS" ) {
 40             #    require MIME::Base64;
 41             #    import MIME::Base64 qw( encode_base64 );
 42             #    require Digest::SHA1;
 43 rizwank 1.1 #    import Digest::SHA1 qw( sha1 );
 44             #}
 45             
 46             
 47             use strict;
 48             
 49             # 'Use locale' for internationalisation of Perl sorting in getTopicNames
 50             # and other routines - main locale settings are done in TWiki::setupLocale
 51             BEGIN {
 52                 # Do a dynamic 'use locale' for this module
 53                 if( $TWiki::useLocale ) {
 54                     require locale;
 55             	import locale ();
 56                 }
 57             }
 58             
 59             # FIXME: Move elsewhere?
 60             # template variable hash: (built from %TMPL:DEF{"key"}% ... %TMPL:END%)
 61             use vars qw( %templateVars $UserImpl ); # init in TWiki.pm so okay for modPerl
 62             
 63             $UserImpl = "";
 64 rizwank 1.1 
 65             # ===========================
 66             =pod
 67             
 68             ---+++ initialize ()
 69             | Description: | loads the selected User Implementation |
 70             
 71             =cut
 72             sub initialize
 73             {
 74                 %templateVars = ();
 75             	if ( # (-e $TWiki::htpasswdFilename ) && #<<< maybe
 76             		( $TWiki::htpasswdFormatFamily eq "htpasswd" ) ) {
 77             	    $UserImpl = "TWiki::User::HtPasswdUser";
 78             #	} elseif ($TWiki::htpasswdFormatFamily eq "something?") {
 79             #	    $UserImpl = "TWiki::User::SomethingUser";
 80             	} else {
 81             	    $UserImpl = "TWiki::User::NoPasswdUser";
 82             	}
 83             	eval "use ".$UserImpl;
 84             }
 85 rizwank 1.1 
 86             # ===========================
 87             =pod
 88             
 89             ---++ sub _getUserHandler (  $web, $topic, $attachment  )
 90             
 91             Not yet documented.
 92             
 93             =cut
 94             
 95             sub _getUserHandler
 96             {
 97                my( $web, $topic, $attachment ) = @_;
 98             
 99                $attachment = "" if( ! $attachment );
100             
101                my $handlerName = $UserImpl;
102             
103                my $handler = $handlerName->new( );
104                return $handler;
105             }
106 rizwank 1.1 
107             #========================= 
108             =pod
109             
110             ---++ UserPasswordExists( $user ) ==> $passwordExists
111             | Description: | checks to see if there is a $user in the password system |
112             | Parameter: =$user= | the username we are looking for  |
113             | Return: =$passwordExists= | "1" if true, "" if not |
114             | TODO: | what if the login name is not the same as the twikiname?? (I think we don't have TWikiName to username mapping fully worked out|
115             
116             =cut
117             
118             sub UserPasswordExists
119             {
120                 my ( $user ) = @_;
121             
122                 my $handler = _getUserHandler();
123             
124                 return $handler->UserPasswordExists($user);
125             }
126              
127 rizwank 1.1 #========================= 
128             =pod
129             
130             ---++ UpdateUserPassword( $user, $oldUserPassword, $newUserPassword ) ==> $success
131             | Description: | used to change the user's password |
132             | Parameter: =$user= | the username we are replacing  |
133             | Parameter: =$oldUserPassword= | unencrypted password |
134             | Parameter: =$newUserPassword= | unencrypted password |
135             | Return: =$success= | "1" if success |
136             | TODO: | need to improve the error mechanism so TWikiAdmins know what failed |
137             | Notes: | always return failure if the $user is AnonymousContributor |
138             | | this is to stop hyjacking of DeletedUser's content |
139             
140             =cut
141             
142             sub UpdateUserPassword
143             {
144                 my ( $user, $oldUserPassword, $newUserPassword ) = @_;
145             
146             	if ( $user =~ /AnonymousContributor/ ) {
147             		return;
148 rizwank 1.1 	}
149             
150                 my $handler = _getUserHandler();
151                 return $handler->UpdateUserPassword($user, $oldUserPassword, $newUserPassword);
152             }
153             
154             #========================= 
155             =pod
156             
157             ---++ AddUserPassword( $user, $newUserPassword ) ==> $success
158             | Description: | creates a new user & password entry |
159             | Parameter: =$user= | the username we are replacing  |
160             | Parameter: =$newUserPassword= | unencrypted password |
161             | Return: =$success= | "1" if success |
162             | TODO: | need to improve the error mechanism so TWikiAdmins know what failed |
163             | Notes: | always return failure if the $user is AnonymousContributor |
164             | | this is to stop hyjacking of DeletedUser's content |
165             
166             =cut
167             
168             sub AddUserPassword
169 rizwank 1.1 {
170                 my ( $user, $newUserPassword ) = @_;
171             
172             	if ( $user =~ /AnonymousContributor/ ) {
173             		return;
174             	}
175             
176                 my $handler = _getUserHandler();
177                 return $handler->AddUserPassword($user, $newUserPassword);
178             }
179             
180             #========================= 
181             =pod
182             
183             ---++ RemoveUser( $user ) ==> $success
184             | Description: | used to remove the user from the password system |
185             | Parameter: =$user= | the username we are replacing  |
186             | Return: =$success= | "1" if success |
187             | TODO: | need to improve the error mechanism so TWikiAdmins know what failed |
188             
189             =cut
190 rizwank 1.1 
191             sub RemoveUser
192             {
193                 my ( $user ) = @_;
194             
195                 my $handler = _getUserHandler();
196                 return $handler->RemoveUser($user);
197             }
198             
199             # =========================
200             =pod
201             
202             ---++ CheckUserPasswd( $user, $password ) ==> $success
203             | Description: | used to check the user's password |
204             | Parameter: =$user= | the username we are replacing  |
205             | Parameter: =$password= | unencrypted password |
206             | Return: =$success= | "1" if success |
207             | TODO: | need to improve the error mechanism so TWikiAdmins know what failed |
208             
209             =cut
210             
211 rizwank 1.1 sub CheckUserPasswd
212             {
213                 my ( $user, $password ) = @_;
214             
215                 my $handler = _getUserHandler();
216                 return $handler->CheckUserPasswd($user, $password);
217             }
218              
219             # =========================
220             =pod
221             
222             ---++ addUserToTWikiUsersTopic( $wikiName, $remoteUser ) ==> $topicName
223             | Description: | create the User's TWikiTopic |
224             | Parameter: =$wikiName= | the user's TWikiName |
225             | Parameter: =$remoteUser= | the remote username (is this used in the password file at any time?) |
226             | Return: =$topicName= | the name of the TWikiTopic created |
227             | TODO: | does this really belong here? |
228             
229             =cut
230             
231             sub addUserToTWikiUsersTopic
232 rizwank 1.1 {
233                 my ( $wikiName, $remoteUser ) = @_;
234                 my $today = &TWiki::formatTime(time(), "\$day \$mon \$year", "gmtime");
235                 my $topicName = $TWiki::wikiUsersTopicname;
236                 my( $meta, $text )  = &TWiki::Store::readTopic( $TWiki::mainWebname, $topicName );
237                 my $result = "";
238                 my $status = "0";
239                 my $line = "";
240                 my $name = "";
241                 my $isList = "";
242                 # add name alphabetically to list
243                 foreach( split( /\n/, $text) ) {
244                     $line = $_;
245             	# TODO: I18N fix here once basic auth problem with 8-bit user names is
246             	# solved
247                     $isList = ( $line =~ /^\t\*\s[A-Z][a-zA-Z0-9]*\s\-/go );
248                     if( ( $status == "0" ) && ( $isList ) ) {
249                         $status = "1";
250                     }
251                     if( $status == "1" ) {
252                         if( $isList ) {
253 rizwank 1.1                 $name = $line;
254                             $name =~ s/(\t\*\s)([A-Z][a-zA-Z0-9]*)\s\-.*/$2/go;            
255                             if( $wikiName eq $name ) {
256                                 # name is already there, do nothing
257                                 return $topicName;
258                             } elsif( $wikiName lt $name ) {
259                                 # found alphabetical position
260                                 if( $remoteUser ) {
261                                     $result .= "\t* $wikiName - $remoteUser - $today\n";
262                                 } else {
263                                     $result .= "\t* $wikiName - $today\n";
264                                 }
265                                 $status = "2";
266                             }
267                         } else {
268                             # is last entry
269                             if( $remoteUser ) {
270                                 $result .= "\t* $wikiName - $remoteUser - $today\n";
271                             } else {
272                                 $result .= "\t* $wikiName - $today\n";
273                             }
274 rizwank 1.1                 $status = "2";
275                         }
276                     }
277             
278                     $result .= "$line\n";
279                 }
280                 &TWiki::Store::saveTopic( $TWiki::mainWebname, $topicName, $result, $meta, "", 1 );
281                 return $topicName;
282             }
283             
284             
285             
286             1;
287             
288             # EOF

Rizwan Kassim
Powered by
ViewCVS 0.9.2