Project

General

Profile

« Previous | Next » 

Revision 4746

Added by walbridge almost 16 years ago

DRY out login request code

View differences:

register-dataset.cgi
137 137
    $debug_enabled = $FORM::debug;
138 138
}
139 139

  
140
my $username = $config->{'username'};
141
my $password = $config->{'password'};
140
# skin owner credentials
141
my $adminUsername = $config->{'username'};
142
my $adminPassword = $config->{'password'};
142 143

  
143 144
# contains sender, recipient, admin, mailhost
144 145
my $email = $skinProperties->splitToTree(qr/\./, 'email');
......
374 375

  
375 376
if (! $error) {
376 377
    # Login to metacat
377
    my ($dname, $userPass) = getCredentials();
378
    my $response = $metacat->login($dname, $userPass);
378
    my ($username, $password) = getCredentials();
379
    my $response = $metacat->login($username, $password);
379 380
    my $errorMessage = "";
380 381

  
381 382
    # Parameters have been validated and Create the XML document
......
400 401

  
401 402
    if ($config->{'adminIsDocOwner'} eq 'true') {
402 403
        debug("adminIsDocOwner is set.");
403
        $response = $metacat->login($username, $password);
404
        $response = $metacat->login($adminUsername, $adminPassword);
404 405
        if (! $response) {
405 406
            push(@errorMessages, $metacat->getMessage());
406 407
            push(@errorMessages, "Failed during login for admin.\n");
......
1307 1308
    my $entityObjects = shift;
1308 1309
    my %entityObjects = %$entityObjects;
1309 1310
    my $userAccess = allowElement(getUsername(), 'all');
1310
    my $skinAccess = allowElement($username, 'all');
1311
    my $skinAccess = allowElement($adminUsername, 'all');
1311 1312
    my $accessList = "";
1312 1313

  
1313 1314
    # form name => EML permission; roles akin to Apache model
......
1801 1802
    my $access = "";
1802 1803

  
1803 1804
    $access .= "<access authSystem=\"knb\" order=\"denyFirst\">\n";
1804
    $access .= allowElement($username, 'all');
1805
    $access .= allowElement($adminUsername, 'all');
1805 1806

  
1806 1807
    if($moderators eq '') {
1807 1808
        $access .= allowElement(getUsername(), 'all');
......
1866 1867
    my $element;
1867 1868
    my $tempfile;
1868 1869

  
1869
    my $session = CGI::Session->load();
1870
    if (!$session->is_empty) {
1871
        my $username = $session->param("username");
1872
        my $password = $session->param("password");
1873
        $metacat->login($username, $password);
1874
    }
1875
   
1870
    my ($username, $password) = getCredentials();
1871
    $metacat->login($username, $password);
1876 1872
 
1877 1873
    $httpMessage = $metacat->read($docid);
1878 1874
    $doc = $httpMessage->content();
......
2579 2575
        }
2580 2576

  
2581 2577
        if ($principal eq 'public' && $permission ne 'read') { $accessError = 1; }
2582
        if ($principal eq $username && $permission ne 'all') { $accessError = 2; }
2583
        if ($principal ne 'public' && $principal ne $username && $permission ne 'all') { $accessError = 3; }
2578
        if ($principal eq $adminUsername && $permission ne 'all') { $accessError = 2; }
2579
        if ($principal ne 'public' && $principal ne $adminUsername && $permission ne 'all') { $accessError = 3; }
2584 2580
        # TODO: FIXME for 1.9.1
2585 2581
        # The ESA skin has a separate concept of 'moderator', which is defined by a property
2586 2582
        # within the configuration. This should be updated to check the user against the groups.
......
2597 2593
        #   $accessError = 3;
2598 2594
        # }
2599 2595
        if ($accessError == 3) {
2600
            my $session = CGI::Session->load();
2601
            if (!$session->is_empty) {
2602
                my $username = $session->param("username");
2603
                my $password = $session->param("password");
2604
                if ($principal eq $username) {
2605
                    $accessError = 0;
2606
                }
2596
            my ($username, $password) = getCredentials();
2597
            if ($principal eq $username) {
2598
                $accessError = 0;
2607 2599
            }
2608 2600
        }
2609 2601
    }
......
2688 2680
    my $docid = $FORM::docid;
2689 2681
    
2690 2682
    # Login to metacat
2691
    my $userDN = $FORM::username;
2692
    my $userOrg = $FORM::organization;
2693
    my $userPass = $FORM::password;
2694
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
2695
    
2696 2683
    my $errorMessage = "";
2697
    my $response = $metacat->login($dname, $userPass);
2684
    my ($username, $password) = getCredentials();
2685
    my $response = $metacat->login($username, $password);
2698 2686

  
2699 2687
    if (! $response) {
2700 2688
    # Could not login
......
2802 2790
        my $password = $FORM::password;
2803 2791

  
2804 2792
        my $metacat = Metacat->new($metacatUrl);
2805
        my $returnVal = $metacat->login($username,$password);
2793
        my $returnVal = $metacat->login($username, $password);
2806 2794
        debug("Login was $returnVal for login attempt to $metacatUrl, with $username");
2807 2795
        if ($returnVal > 0) {
2808 2796
            # valid username and passwd
......
2931 2919
    }
2932 2920

  
2933 2921
    if ($returnValue eq 1) {
2934
        $modUsername = $session->param("username");
2935
        $modPassword = $session->param("password");
2922
        ($modUsername, $modPassword) = getCredentials();
2936 2923
    }
2937 2924

  
2938 2925
    return $returnValue;
......
2975 2962

  
2976 2963
    my $moderator = $session->param("moderator");
2977 2964

  
2978
    $$templateVars{'reviewdocid'} = getReviewHistoryHTML($session->param("username"),  $session->param("password"));
2965
    $$templateVars{'reviewdocid'} = getReviewHistoryHTML();
2979 2966
    $$templateVars{'docid'} = $FORM::docid;
2980 2967
    if ($moderator eq 'true') {
2981 2968
        $$templateVars{'isModerator'} = "true";
......
2984 2971
}
2985 2972

  
2986 2973
sub getReviewHistoryHTML {
2987
    my $username = shift;
2988
    my $password = shift;
2989

  
2990 2974
    my $metacat = Metacat->new($metacatUrl);
2975
    my ($username, $password) = getCredentials();
2991 2976
    $metacat->login($username, $password);
2992 2977
    my $parser = XML::LibXML->new();
2993 2978
    my $docid = $FORM::docid;

Also available in: Unified diff