package WebGUI::Operation::Account; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black Software. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use Digest::MD5 qw(md5_base64); use Exporter; use Net::LDAP; use strict; use URI; use WebGUI::DateTime; use WebGUI::ErrorHandler; use WebGUI::Form; use WebGUI::International; use WebGUI::Mail; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::Shortcut; use WebGUI::SQL; use WebGUI::URL; use WebGUI::Utility; our @ISA = qw(Exporter); our @EXPORT = qw(&www_viewMessageLog &www_viewProfile &www_editProfile &www_editProfileSave &www_createAccount &www_deactivateAccount &www_deactivateAccountConfirm &www_displayAccount &www_displayLogin &www_login &www_logout &www_recoverPassword &www_recoverPasswordFinish &www_createAccountSave &www_updateAccount); our %ldapStatusCode = ( 0=>'success (0)', 1=>'Operations Error (1)', 2=>'Protocol Error (2)', 3=>'Time Limit Exceeded (3)', 4=>'Size Limit Exceeded (4)', 5=>'Compare False (5)', 6=>'Compare True (6)', 7=>'Auth Method Not Supported (7)', 8=>'Strong Auth Required (8)', 9=>'Referral (10)', 11=>'Admin Limit Exceeded (11)', 12=>'Unavailable Critical Extension (12)', 13=>'Confidentiality Required (13)', 14=>'Sasl Bind In Progress (14)', 15=>'No Such Attribute (16)', 17=>'Undefined Attribute Type (17)', 18=>'Inappropriate Matching (18)', 19=>'Constraint Violation (19)', 20=>'Attribute Or Value Exists (20)', 21=>'Invalid Attribute Syntax (21)', 32=>'No Such Object (32)', 33=>'Alias Problem (33)', 34=>'Invalid DN Syntax (34)', 36=>'Alias Dereferencing Problem (36)', 48=>'Inappropriate Authentication (48)', 49=>'Invalid Credentials (49)', 50=>'Insufficient Access Rights (50)', 51=>'Busy (51)', 52=>'Unavailable (52)', 53=>'Unwilling To Perform (53)', 54=>'Loop Detect (54)', 64=>'Naming Violation (64)', 65=>'Object Class Violation (65)', 66=>'Not Allowed On Non Leaf (66)', 67=>'Not Allowed On RDN (67)', 68=>'Entry Already Exists (68)', 69=>'Object Class Mods Prohibited (69)', 71=>'Affects Multiple DSAs (71)', 80=>'other (80)'); #------------------------------------------------------------------- sub _accountOptions { my ($output); $output = '
"; } } #------------------------------------------------------------------- sub www_createAccount { my ($output, %language, @array); if ($session{user}{userId} != 1) { $output .= www_displayAccount(); } elsif ($session{setting}{anonymousRegistration} eq "no") { $output .= www_displayLogin(); } else { $output .= '
| '.WebGUI::International::get(50).' | '.WebGUI::Form::text("username",20,30).' |
| '.$session{setting}{ldapIdName}.' | '.WebGUI::Form::text("ldapId",20,100).' |
| '.$session{setting}{ldapPasswordName}.' | '.WebGUI::Form::password("ldapPassword",20,100).' |
| '.WebGUI::International::get(51).' | '.WebGUI::Form::password("identifier1",20,30).' |
| '.WebGUI::International::get(55).' | '.WebGUI::Form::password("identifier2",20,30).' |
| '.WebGUI::International::get(56).' | '.WebGUI::Form::text("email",20,255).' '.WebGUI::International::get(57).' |
| '.WebGUI::International::get(304).' | '.WebGUI::Form::selectList("language",\%language,\@array).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
'; } if (_hasBadPassword($session{form}{identifier1},$session{form}{identifier2})) { $error .= WebGUI::International::get(78); } if ($session{setting}{authMethod} eq "LDAP") { $uri = URI->new($session{setting}{ldapURL}); if ($uri->port < 1) { $port = 389; } else { $port = $uri->port; } %args = (port => $port); $ldap = Net::LDAP->new($uri->host, %args) or $error .= WebGUI::International::get(79); $ldap->bind; $search = $ldap->search (base => $uri->dn, filter => $session{setting}{ldapId}."=".$session{form}{ldapId}); if (defined $search->entry(0)) { $connectDN = "cn=".$search->entry(0)->get_value("cn"); $ldap->unbind; $ldap = Net::LDAP->new($uri->host, %args) or $error .= WebGUI::International::get(79); $auth = $ldap->bind(dn=>$connectDN, password=>$session{form}{ldapPassword}); if ($auth->code == 48 || $auth->code == 49) { $error .= WebGUI::International::get(68); WebGUI::ErrorHandler::warn("Invalid LDAP information for registration of LDAP ID: ".$session{form}{ldapId}); } elsif ($auth->code > 0) { $error .= 'LDAP error "'.$ldapStatusCode{$auth->code}.'" occured. '.WebGUI::International::get(69); WebGUI::ErrorHandler::warn("LDAP error: ".$ldapStatusCode{$auth->code}); } $ldap->unbind; } else { $error .= WebGUI::International::get(68); WebGUI::ErrorHandler::warn("Invalid LDAP information for registration of LDAP ID: ".$session{form}{ldapId}); } } if ($error eq "") { $encryptedPassword = Digest::MD5::md5_base64($session{form}{identifier1}); $uid = getNextId("userId"); WebGUI::SQL->write("insert into users (userId,username,identifier,email,authMethod,ldapURL,connectDN,language) values ($uid, ".quote($username).", ".quote($encryptedPassword).", ".quote($session{form}{email}).", ".quote($session{setting}{authMethod}).", ".quote($session{setting}{ldapURL}).", ".quote($connectDN).", ".quote($session{form}{language}).")"); ($registeredUserExpire) = WebGUI::SQL->quickArray("select expireAfter from groups where groupId=2"); WebGUI::SQL->write("insert into groupings values (2,$uid,".(time()+$registeredUserExpire).")"); _login($uid,$encryptedPassword); $output .= WebGUI::International::get(80).'
'; $output .= www_displayAccount(); } else { $output = "
'; $output .= '
'; } return $output; } #------------------------------------------------------------------- sub www_deactivateAccountConfirm { if ($session{user}{userId} != 1) { WebGUI::SQL->write("delete from users where userId=$session{user}{userId}"); WebGUI::SQL->write("delete from groupings where userId=$session{user}{userId}"); WebGUI::Session::end($session{var}{sessionId}); _login(1,"null"); } return www_displayLogin(); } #------------------------------------------------------------------- sub www_displayAccount { my ($output, %hash, @array); if ($session{user}{userId} != 1) { $output .= '| '.WebGUI::International::get(50).' | '.$session{user}{username}.' |
| '.WebGUI::International::get(50).' | '.WebGUI::Form::text("username",20,30,$session{user}{username}).' |
| '.WebGUI::International::get(51).' | '.WebGUI::Form::password("identifier1",20,30,"password").' |
| '.WebGUI::International::get(55).' | '.WebGUI::Form::password("identifier2",20,30,"password").' |
| '.WebGUI::International::get(56).' | '.WebGUI::Form::text("email",20,255,$session{user}{email}).' '.WebGUI::International::get(57).' |
| '.WebGUI::International::get(304).' | '.WebGUI::Form::selectList("language",\%hash,\@array).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
| '.WebGUI::International::get(50).' | '.WebGUI::Form::text("username",20,30).' |
| '.WebGUI::International::get(51).' | '.WebGUI::Form::password("identifier",20,30).' |
| '.WebGUI::Form::submit(WebGUI::International::get(52)).' |
| '.WebGUI::International::get(314).' | '.WebGUI::Form::text("firstName",20,50,$session{user}{firstName}).' |
| '.WebGUI::International::get(315).' | '.WebGUI::Form::text("middleName",20,50,$session{user}{middleName}).' |
| '.WebGUI::International::get(316).' | '.WebGUI::Form::text("lastName",20,50,$session{user}{lastName}).' |
| '.WebGUI::International::get(317).' | '.WebGUI::Form::text("icq",20,30,$session{user}{icq}).' |
| '.WebGUI::International::get(318).' | '.WebGUI::Form::text("aim",20,30,$session{user}{aim}).' |
| '.WebGUI::International::get(319).' | '.WebGUI::Form::text("msnIM",20,30,$session{user}{msnIM}).' |
| '.WebGUI::International::get(320).' | '.WebGUI::Form::text("yahooIM",20,30,$session{user}{yahooIM}).' |
| '.WebGUI::International::get(321).' | '.WebGUI::Form::text("cellPhone",20,30,$session{user}{cellPhone}).' |
| '.WebGUI::International::get(322).' | '.WebGUI::Form::text("pager",20,30,$session{user}{pager}).' |
| '.WebGUI::International::get(323).' | '.WebGUI::Form::text("homeAddress",20,128,$session{user}{homeAddress}).' |
| '.WebGUI::International::get(324).' | '.WebGUI::Form::text("homeCity",20,30,$session{user}{homeCity}).' |
| '.WebGUI::International::get(325).' | '.WebGUI::Form::text("homeState",20,30,$session{user}{homeState}).' |
| '.WebGUI::International::get(326).' | '.WebGUI::Form::text("homeZip",20,15,$session{user}{homeZip}).' |
| '.WebGUI::International::get(327).' | '.WebGUI::Form::text("homeCountry",20,30,$session{user}{homeCountry}).' |
| '.WebGUI::International::get(328).' | '.WebGUI::Form::text("homePhone",20,30,$session{user}{homePhone}).' |
| '.WebGUI::International::get(329).' | '.WebGUI::Form::text("workAddress",20,128,$session{user}{workAddress}).' |
| '.WebGUI::International::get(330).' | '.WebGUI::Form::text("workCity",20,30,$session{user}{workCity}).' |
| '.WebGUI::International::get(331).' | '.WebGUI::Form::text("workState",20,30,$session{user}{workState}).' |
| '.WebGUI::International::get(332).' | '.WebGUI::Form::text("workZip",20,15,$session{user}{workZip}).' |
| '.WebGUI::International::get(333).' | '.WebGUI::Form::text("workCountry",20,30,$session{user}{workCountry}).' |
| '.WebGUI::International::get(334).' | '.WebGUI::Form::text("workPhone",20,30,$session{user}{workPhone}).' |
| '.WebGUI::International::get(335).' | '.WebGUI::Form::selectList("gender",\%gender,\@array).' |
| '.WebGUI::International::get(336).' | '.WebGUI::Form::text("birthdate",20,30,$session{user}{birthdate}).' |
| '.WebGUI::International::get(337).' | '.WebGUI::Form::text("homepage",20,2048,$session{user}{homepage}).' |
| '.WebGUI::Form::submit(WebGUI::International::get(62)).' |
| '.WebGUI::International::get(56). ' | '.WebGUI::Form::text("email",20,255).' |
| '.WebGUI::Form::submit(WebGUI::International::get(72)).' |
'; } if ($session{form}{identifier1} ne "password") { if (_hasBadPassword($session{form}{identifier1},$session{form}{identifier2})) { $error .= WebGUI::International::get(78).'
'; } else { $encryptedPassword = Digest::MD5::md5_base64($session{form}{identifier1}); $passwordStatement = ', identifier='.quote($encryptedPassword); } } if ($error eq "") { $encryptedPassword = Digest::MD5::md5_base64($session{form}{identifier1}); WebGUI::SQL->write("update users set username=".quote($session{form}{username}).$passwordStatement.", email=".quote($session{form}{email}).", language=".quote($session{form}{language})." where userId=".$session{user}{userId}); if ($passwordStatement ne "") { _login($session{user}{userId},$encryptedPassword); } $output .= WebGUI::International::get(81).'
'; $output .= www_displayAccount(); } else { $output = $error; $output .= www_createAccount(); } } else { $output .= www_displayLogin(); } return $output; } #------------------------------------------------------------------- sub www_viewMessageLog { my (@data, $output, $sth, @row, $i, $dataRows, $prevNextBar); if (WebGUI::Privilege::isInGroup(2,$session{user}{userId})) { $output = '
| '.WebGUI::International::get(351).' | '.WebGUI::International::get(352).' |
| '.WebGUI::International::get(353).' |
| '.WebGUI::International::get(56).' | '.$user{email}.' |
| '.WebGUI::International::get(348).' | '.$user{firstName}.' '.$user{middleName}.' '.$user{lastName}.' |
| '.WebGUI::International::get(317).' | '.$user{icq}.' |
| '.WebGUI::International::get(318).' | '.$user{aim}.' |
| '.WebGUI::International::get(319).' | '.$user{msnIM}.' |
| '.WebGUI::International::get(320).' | '.$user{yahooIM}.' |
| '.WebGUI::International::get(321).' | '.$user{cellPhone}.' |
| '.WebGUI::International::get(322).' | '.$user{pager}.' |
| '.WebGUI::International::get(323).' | '.$user{homeAddress}.' '.$user{homeCity}.', '.$user{homeState}.' '.$user{homeZip}.' '.$user{homeCountry}.' |
| '.WebGUI::International::get(328).' | '.$user{homePhone}.' |
| '.WebGUI::International::get(329).' | '.$user{workAddress}.' '.$user{workCity}.', '.$user{workState}.' '.$user{workZip}.' '.$user{workCountry}.' |
| '.WebGUI::International::get(334).' | '.$user{workPhone}.' |
| '.WebGUI::International::get(335).' | '.$user{gender}.' |
| '.WebGUI::International::get(336).' | '.$user{birthdate}.' |
| '.WebGUI::International::get(337).' | '.$user{homepage}.' |