Project

General

Profile

« Previous | Next » 

Revision 8221

Added by Jing Tao over 11 years ago

Add a method to lookup users'account for the people who forgot their user name.

View differences:

src/perl/ldapweb.cgi
304 304
              'resetpass'         => \&handleResetPassword,
305 305
              'initresetpass'     => \&handleInitialResetPassword,
306 306
              'emailverification' => \&handleEmailVerification,
307
              'lookupname' => \&handleLookupName,
307 308
             );
308 309

  
309 310
# call the appropriate routine based on the stage
......
333 334
    $template->process( $templates->{'footer'}, $templateVars );
334 335
}
335 336

  
337

  
338

  
336 339
#
340
# Handle the user's request to look up account names with a specified email address.
341
# This relates to "Forget your user name"
342
#
343
sub handleLookupName {
344

  
345
    print "Content-type: text/html\n\n";
346
   
347
    my $allParams = {'mail' => $query->param('mail')};
348
    my @requiredParams = ('mail');
349
    if (! paramsAreValid(@requiredParams)) {
350
        my $errorMessage = "Required information is missing. " .
351
            "Please fill in all required fields and resubmit the form.";
352
        fullTemplate(['lookupname'], { stage => "lookupname",
353
                                     allParams => $allParams,
354
                                     errorMessage => $errorMessage });
355
        exit();
356
    }
357
    my $mail = $query->param('mail');
358
    
359
    #search accounts with the specified emails 
360
    $searchBase = $authBase; 
361
    my $filter = "(mail=" . $mail . ")";
362
    my @attrs = [ 'uid', 'o', 'ou', 'cn', 'mail', 'telephoneNumber', 'title' ];
363
    my $notHtmlFormat = 1;
364
    my $found = findExistingAccounts($ldapurl, $searchBase, $filter, \@attrs, $notHtmlFormat);
365
    my $accountInfo;
366
    if($found) {
367
        $accountInfo = $found;
368
    } else {
369
        my $link = $contextUrl. '/cgi-bin/ldapweb.cgi?cfg=' . $skinName;
370
        $accountInfo = "There are no KNB accounts associated with the email " . $mail . ".\n" .
371
                       "You may create a new one by the following link: \n" . $link
372
    }
373
    
374
    
375
    
376
    my $mailhost = $properties->getProperty('email.mailhost');
377
    my $sender;
378
    $sender = $skinProperties->getProperty("email.sender") or $sender = $properties->getProperty('email.sender');
379
    debug("the sender is " . $sender);
380
    my $recipient = $query->param('mail');
381
    # Send the email message to them
382
    my $smtp = Net::SMTP->new($mailhost) or do {  
383
                                                  fullTemplate( ['lookupNameFailed'], {errorMessage => "Our mail server currently is experiencing some difficulties. Please contact " . 
384
                                                  $skinProperties->getProperty("email.recipient") . "." });  
385
                                                  exit(0);
386
                                               };
387
    $smtp->mail($sender);
388
    $smtp->to($recipient);
389

  
390
    my $message = <<"     ENDOFMESSAGE";
391
    To: $recipient
392
    From: $sender
393
    Subject: KNB Account
394
        
395
    Somebody (hopefully you) looked up the KNB accounts associated with the email address.  
396
    Here is the accounts information:
397
    
398
    $accountInfo
399

  
400
    Thanks,
401
        The KNB Development Team
402
    
403
     ENDOFMESSAGE
404
     $message =~ s/^[ \t\r\f]+//gm;
405
    
406
     $smtp->data($message);
407
     $smtp->quit;
408
     fullTemplate( ['lookupNameSuccess'] );
409
    
410
}
411

  
412

  
413
#
337 414
# create the initial registration form 
338 415
#
339 416
sub handleInitRegister {
......
344 421
  exit();
345 422
}
346 423

  
424

  
425

  
347 426
#
348 427
# process input from the register stage, which occurs when
349 428
# a user submits form data to create a new account
......
827 906
    my $base = shift;
828 907
    my $filter = shift;
829 908
    my $attref = shift;
909
    my $notHtmlFormat = shift;
830 910
    my $ldap;
831 911
    my $mesg;
832 912

  
......
851 931
                # a fix to ignore 'ou=Account' properties which are not usable accounts within Metacat.
852 932
                # this could be done directly with filters on the LDAP connection, instead.
853 933
                #if ($entry->dn !~ /ou=Account/) {
854
                    $foundAccounts .= "<p>\n<b><u>Account:</u> ";
934
                    if($notHtmlFormat) {
935
                        $foundAccounts .= "\nAccount: ";
936
                    } else {
937
                        $foundAccounts .= "<p>\n<b><u>Account:</u> ";
938
                    }
855 939
                    $foundAccounts .= $entry->dn();
856
                    $foundAccounts .= "</b><br />\n";
940
                    if($notHtmlFormat) {
941
                        $foundAccounts .= "\n";
942
                    } else {
943
                        $foundAccounts .= "</b><br />\n";
944
                    }
857 945
                    foreach my $attribute ($entry->attributes()) {
858 946
                        my $value = $entry->get_value($attribute);
859 947
                        $foundAccounts .= "$attribute: ";
860 948
                        $foundAccounts .= $value;
861
                        $foundAccounts .= "<br />\n";
949
                         if($notHtmlFormat) {
950
                            $foundAccounts .= "\n";
951
                        } else {
952
                            $foundAccounts .= "<br />\n";
953
                        }
862 954
                    }
863
                    $foundAccounts .= "</p>\n";
955
                    if($notHtmlFormat) {
956
                        $foundAccounts .= "\n";
957
                    } else {
958
                        $foundAccounts .= "</p>\n";
959
                    }
960
                    
864 961
                #}
865 962
			}
866 963
        }

Also available in: Unified diff