Changeset 144

Show
Ignore:
Timestamp:
12/27/07 00:53:51 (1 year ago)
Author:
pamela
Message:

updating pwwp trunk to RB-0.9

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-infocard

    • Property svn:externals changed from
      pwlib https://pamelaproject.com/svn/pw/pwcommon/trunk/pwlib
      legal https://pamelaproject.com/svn/pw/pwcommon/trunk/legal
      to
      pwlib https://pamelaproject.com/svn/pw/pwcommon/branches/RB-1.0/pwlib
      legal https://pamelaproject.com/svn/pw/pwcommon/branches/RB-1.0/legal
  • trunk/wp-infocard/pw-config.php

    r109 r144  
    77define ('PW_SHOW_BINARY', FALSE); 
    88define ('PW_PLUGINPATH', '/wp-content/plugins/wp-infocard'); 
    9 define ('PW_VERSION', 'b3'); 
    10 define ('PW_VERSION_DATE', '29Sep07'); 
     9define ('PW_VERSION', 'v0.9'); 
     10define ('PW_VERSION_DATE', '12/26/07'); 
     11define ('PW_DB_VERSION', 'DB v3'); 
    1112define ('PW_USECAPTCHAS', false ); 
    1213define ('PW_DEBUG_ON', get_settings('pw_debug_on')); 
     14define ('PW_DEBUG_LEVEL', '0'); 
    1315define ('PW_SELECTOR_TRIGGER', get_settings('pw_selector_trigger')); 
    1416define ('PW_CUSTOM_DATA', get_settings('pw_custom_data')); 
  • trunk/wp-infocard/site-messages/en-us/new-email.html

    r110 r144  
    1     <h2>Email Address Change</h2> 
    2         <p>Your email address has changed - please note that your login ID is based on your original email address, and will remain the same.  This will be important if you ever need to recover your regular password.</p> 
     1<h2>Email Validation Required</h2> 
     2 
     3      <p>You have changed the email address in your registered Information Card. You must validate the new email address before you can continue.</p> 
     4 
     5<p>This blog is currently sending you an email.  It contains a link back to this site.  Please click on that link, which will validate you by proving that your claim to control the stated email address is legitimate.</p> 
  • trunk/wp-infocard/site-messages/infocard-usermessage.php

    r112 r144  
    22<?php 
    33$messageType = $_REQUEST['mesg']; 
     4 
    45 
    56include_once( dirname(__FILE__) . '/../' . '/pw-config.php'); 
  • trunk/wp-infocard/wp-infocard.php

    r100 r144  
    33Plugin Name: PamelaWare Information Card Login 
    44Plugin URI: http://code.pamelaproject.com/wiki/PWwordpress 
    5 Description: This plugin adds functionality to register and login with "information cards", part of the Identity Metasystem web services framework.  Once it is activated, go to the "Options" menu and click on "Information Card Options" to see what to do next. 
    6 Version: b3 
     5Description: This plugin adds functionality to register and login with "information cards", part of the Identity Metasystem web services framework.  Once it is activated, go to the "Options" menu and click on "Information Cards" to see what to do next. 
     6Version: v0.9  
    77Author: K. Cameron, P. Dingle, and more 
    88Author URI: https://pamelaproject.com/svn/pw/pwcommon/legal/CONTRIBUTORS 
     
    4747// function to add information card link to wp-login.php  
    4848add_action( 'login_form', array( $wpInfocard, 'pw_loginform_link')); 
     49add_action( 'register_form', array( $wpInfocard, 'pw_registerform_link')); 
    4950 
    5051//if ( PW_USECAPTCHAS ) 
  • trunk/wp-infocard/wp/admin.pw.php

    r110 r144  
    1111include_once( dirname(__FILE__) . '/../pwlib/admin.pwlib.php'); 
    1212include_once( dirname(__FILE__) . '/processing.pw.php'); 
     13include_once( dirname(__FILE__) . '/utils.pw.php'); 
    1314//require_once( ABSPATH . WPINC . '/registration-functions.php'); 
    1415/* 
     
    6263 
    6364                $myTableAuditQuery = 
    64                                 "CREATE TABLE `$this->table_audit` ( 
     65                                "CREATE TABLE IF NOT EXISTS `$this->table_audit` ( 
    6566                                                `cardhash` text default '', 
    6667                                                `accountid` bigint(20) unsigned, 
     
    168169                foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 
    169170                { 
    170                         if ( $table == $this->table_identity
     171                        if ( $table == $this->table_options
    171172                        { 
    172173                                return true; 
     
    185186        { 
    186187                global $wpdb; 
     188                pw_admin::createInfocardAuditTable(); 
     189                pw_admin::createInfocardIdentityTable(); 
    187190 
    188191                $isAuditTableCreated = $this->_createAuditTable(); 
     
    198201                $this->createOption('pw_securesiteurl', $https_url); 
    199202 
     203                $this->createOption('pw_db_version', PW_DB_VERSION); 
    200204                $this->createOption('pw_debug_on', 0); 
    201205                $this->createOption('pw_enable_pass', 0); 
     
    236240        { 
    237241                global $current_user; 
    238                 if (strpos($_SERVER[SCRIPT_URI], "https")) 
    239                 { 
    240                         $css = PW_PLUGINURL . "/custom/infocard-frontpage.css"; 
    241                 } 
    242                 else 
    243                 { 
    244                         $css = PW_SECUREPLUGINURL . "/custom/infocard-frontpage.css"; 
    245                 } 
     242                $css = get_option('siteurl') . "/custom/infocard-frontpage.css"; 
    246243 
    247244                $chunk = ""; 
    248245                if( !$current_user->ID ) 
    249246                { 
    250                         $chunk = '<link rel="stylesheet" href="'.$css.'" type="text/css" />'; 
     247                        //$chunk = '<link rel="stylesheet" href="'.$css.'" type="text/css" />'; 
     248                        $chunk = ''; 
    251249                        // note I set the CSS styles inline because otherwise 
    252250                        // the user has to link infocard.css - not worth it 
    253251                        // for this one icon 
    254                        $chunk .='</li><li><a id="pw_frontpage_link" href="' 
     252                       $chunk .='<li><a id="pw_frontpage_link" href="' 
    255253                        . PW_SECUREPLUGINURL .'/' . PW_PLUGIN 
    256254                        . '/login/infocard-login.php" alt="' 
    257255                        . __('Information Card Login') 
    258                         . '"><img id="pw_frontpage_icon" src="' 
     256                        . '" style="border-bottom:none;"><img id="pw_frontpage_icon" src="' 
    259257                        . PW_IMGURL . '/' .PW_FP_ICON  
    260                         . '"/></a></li>'; 
     258                        . '" style="border:none; border-bottom: none; background: none;"/></a></div></li>'; 
    261259                } 
    262                 return $link . $chunk; 
     260               return $link . $chunk; 
    263261        } //end function pw_frontpage_link 
    264262 
     
    280278        } //end function pw_loginform_link 
    281279 
     280 
     281        function pw_registerform_link() 
     282        { 
     283//              if ( PW_USECAPTCHAS ) 
     284//                      display_cryptographp(); 
     285?> 
     286        <hr /> 
     287                <a href="<?php echo PW_SECUREPLUGINURL . '/' . PW_PLUGIN; ?>/login/infocard-login.php" alt="<?php pw_utils::screenPrint('Infocard Login'); ?>" style="border-bottom: none; color: #FFF"> 
     288                        <?php pw_utils::screenPrint('Register using an Information Card'); ?> 
     289                        <br/> 
     290                        <img src="<?php echo PW_IMGURL; ?>/infocard_60x42.png" style="padding:10px" /> 
     291                </a> 
     292                &nbsp; <a alt="<?php echo __('What is this?'); ?>" style="border-bottom: none; color: #fff"  href="http://pamelaproject.com/"> 
     293                        <?php echo __('(what is this?)'); ?> 
     294                </a> 
     295<?php 
     296        } //end function pw_registerform_link 
     297 
    282298        function pw_printUserCardStatus() 
    283299        { 
     
    292308?> 
    293309                        <p> 
    294                                 <img src="<?php echo PW_IMGURL; ?>/ic-logo/ic-logo-blue-icon.png"/> <?php pw_utils::screenPrint('Information Card ID: ' . $handle); ?> 
     310                                <img src="<?php echo PW_IMGURL; ?>/infocard_60x42.png"/>  
     311<?php  
     312                        pw_utils::screenPrint('An Information Card is associated with this account');  
     313                        //pw_utils::screenPrint('Information Card ID: ' . $handle);  
     314?> 
    295315                        </p> 
    296316 
     
    302322                                . "<label for='Information Card Info' style='display: inline'><img src=\"" 
    303323                                . PW_IMGURL 
    304                                 . '/ic-logo/ic-logo-disabled.png"' 
     324                                . '/infocard_60x42_disabled.png"' 
    305325                                . " style='vertical-align: middle'/> &nbsp;"; 
    306                                 pw_utils::screenPrint('No Information Card in use.'); 
     326                                pw_utils::screenPrint('No Information Card associated with this account.'); 
    307327                                echo "</label></p>"; 
    308328                } 
     
    319339        function getOption($attr_name) 
    320340        { 
    321                 return get_settings($attr_name); 
     341                return get_option($attr_name); 
    322342        } //end function getOption 
    323343 
    324         /* 
    325                 Function: createNewAccount 
    326                 Description: creates a new db record 
    327                 Input: account details 
    328                 Output: returns the user Id on success, FALSE on failure 
    329                 Side effect: none 
    330         */ 
    331         function createNewAccount( $datamap ) 
    332         { 
    333                 require_once( ABSPATH . WPINC . '/registration-functions.php'); 
    334  
    335                 $user_login = $datamap['user_login']->new_value; 
    336                 $user_firstname = $datamap['first_name']->new_value; 
    337                 $user_lastname = $datamap['last_name']->new_value; 
    338                 $user_email = $datamap['user_email']->new_value; 
    339                 $display_name = $datamap['display_name']->new_value; 
    340                 $user_nicename = $display_name; 
    341                 $user_pass = MD5($datamap['cardhash']->new_value); 
    342                 $user_url = $datamap['user_url']->new_value; 
    343  
    344                 InfocardUtils::printDebug("<br/>Action: createNewAccount<br>"); 
    345                 InfocardUtils::printDebug("<br/>Nice Name: $user_nicename<br>"); 
    346                 $userdata = compact('user_login', 'user_pass', 'user_email', 'user_nicename', 'user_url', 'display_name', 'user_firstname', 'user_lastname'); 
    347                 $user_ID = wp_insert_user($userdata); 
    348  
    349                 if ($user_ID)  
    350                 { 
    351                         InfocardUtils::printDebug("&nbsp;Inserted record # $user_ID<br>"); 
    352                         return $user_ID; 
    353                 } 
    354                 else 
    355                 { 
    356                         InfocardUtils::printDebug("&nbsp;Error - new user not created<br/>"); 
    357                         return FALSE; 
    358                 } 
    359         } // end function createNewAccount 
    360  
    361344        function createOption( $option_name, $option_value ) 
    362         { 
    363                 // this function needs to be inside the pw_infocard class for WP to call it.  This is just a  
    364                 // placeholder 
    365         } 
     345        {        
     346                // this is duplicated in the case of the wordpress plugin. 
     347                $options = get_option($option_name); 
     348                if ( !$options ) 
     349                        $options = $option_value; 
     350 
     351                update_option($option_name, $options); 
     352        } 
     353 
     354        function removeOption( $option_name ) 
     355        { 
     356                delete_option( $option_name ); 
     357 
     358        } 
     359         
    366360        function pwAdminScreen() 
    367361        { 
     
    369363                $opts = pw_admin::updateAdminOptions(); 
    370364                // write submitted changes if this page reload shows a submit 
     365                if (pw_utils::databaseUpToDate()) 
     366                { 
     367                        echo "<p>Plugin Version: ". PW_VERSION . " " . PW_VERSION_DATE  
     368                        . " (" . $opts['pw_db_version'] . ")</p>"; 
     369                } 
     370                else             
     371                { 
     372?> 
     373                <form  action="" method="post"> 
     374<?php 
     375                        echo "<div id='message' class='updated'>" . pw_admin::fixDatabase() . "</div>"; 
     376?> 
     377                        <input type="submit" name="infocard_admin_upgrade" id="infocard_admin_upgrade" value="Continue" /> 
     378                </form> 
     379<?php 
     380                        return; 
     381                } 
    371382 
    372383                pw_admin::printSystemCheck($opts['pw_securesiteurl']); 
     
    491502                return $option_val; 
    492503        } 
    493         function checkDatabaseStructure() 
    494         { 
    495                 // eventually this is where I will put my database upgrade code. 
     504                 
     505        function createInfocardAuditTable()  
     506        { 
     507                global $wpdb; 
     508                $audittable = PW_TABLE_PREFIX . "infocard_audit"; 
     509 
     510                $myTableAuditQuery = 
     511                        "CREATE TABLE IF NOT EXISTS `" . $audittable . "` ( 
     512                                `cardhash` text default '', 
     513                                `accountid` bigint(20) unsigned, 
     514                                `email` varchar(128) NOT NULL default '', 
     515                                `time` datetime NOT NULL default '0000-00-00 00:00:00', 
     516                                `IP` varchar(16) NOT NULL default '', 
     517                                `status` varchar(128) NOT NULL default '' 
     518                        ) ENGINE = MYISAM"; 
     519 
     520                // Check if table is already there 
     521                foreach ($wpdb->get_col("SHOW TABLES", 0) as $table ) 
     522                { 
     523                        if ($table == $audittable) 
     524                        { 
     525                                return false; 
     526                        } 
     527                } 
     528 
     529                // Ok, let's proceed 
     530                if ( $wpdb->query( $myTableAuditQuery ) === false ) 
     531                { 
     532                        return false; 
     533                } 
     534 
     535                // Just to be sure, we check that tables were actually created 
     536                foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 
     537                { 
     538                        if ( $table == $audittable ) 
     539                        { 
     540                                return true; 
     541                        } 
     542                } 
     543                return false; 
     544        } //end function createInfocardAuditTable 
     545 
     546        function createInfocardIdentityTable() 
     547        { 
     548                global $wpdb; 
     549                $identitytable = PW_TABLE_PREFIX . "infocard_identities"; 
     550 
     551                $myTableIdentityQuery = 
     552                        "CREATE TABLE `" . $identitytable . "` ( 
     553                                `cardhash` text default '', 
     554                                `accountid` bigint(20) unsigned, 
     555                                `cardhandle` varchar(128) NOT NULL default '', 
     556                                `startdate` varchar(128) NOT NULL default '', 
     557                                `lastused` varchar(128) NOT NULL default '' 
     558                        ) ENGINE = MYISAM"; 
     559 
     560                // Check if table is already there 
     561                foreach ($wpdb->get_col("SHOW TABLES", 0) as $table ) 
     562                { 
     563                        if ($table == $identitytable) 
     564                        { 
     565                                return false; 
     566                        } 
     567                } 
     568 
     569                // Ok, let's proceed 
     570                if ( $wpdb->query( $myTableIdentityQuery ) === false ) 
     571                { 
     572                        return false; 
     573                } 
     574 
     575                // Just to be sure, we check that tables were actually created 
     576                foreach ( $wpdb->get_col("SHOW TABLES", 0) as $table ) 
     577                { 
     578                        if ( $table == $identitytable ) 
     579                        { 
     580                                return true; 
     581                        } 
     582                } 
     583                return false; 
     584        } // end function createInfocardIdentityTable 
     585 
     586        /* 
     587                Function:       fixDatabase 
     588                Description:    updates/alters database depending on detection 
     589                                of database version 
     590                Input:          none 
     591                Output:         status string 
     592                Side-Effect:    may alter database structure 
     593        */ 
     594        function fixDatabase() 
     595        { 
     596                include_once('db_upgrade.pw.php'); 
     597                $output = "<h4>Upgrading PamelaWare to " . PW_VERSION . "</h4>"; 
     598                if (pw_admin::getOption('pw_db_version'))        
     599                        return $output . "oops sorry, up to date</p>"; 
     600 
     601                if (pw_admin::getOption('pw_infocard_key')) 
     602                { 
     603                        global $wpdb; 
     604                        // we are at least DBv2, maybe DBv3 
     605                        $query = "describe wp_infocard_identities"; 
     606                        $identity_info = $wpdb->get_results( $query, OBJECT );   
     607 
     608                        $cardhash_present = FALSE; 
     609                        foreach (array_values($identity_info) as $x) 
     610                                if ($x->Field == 'cardhash') 
     611                                        $cardhash_present = TRUE; 
     612                                 
     613                        if ($cardhash_present) 
     614                        { 
     615                                // DB is already v3, just fix options 
     616                                $output .= "<p>Version DBv3 detected</p>"; 
     617                                pw_admin::setOption('pw_db_version', 'DB v3'); 
     618                        } 
     619                        else 
     620                        { 
     621                                // DB is v2,  must upgrade 
     622                                $output .= "<p>Version DBv2 detected</p>"; 
     623                                $output .= pw_db_upgrade::upgradeDBv2ToDBv3(); 
     624                        } 
     625 
     626                        return $output . "</p>";                 
     627                } 
     628 
     629                if (pw_admin::getOption('infocard_key')) 
     630                { 
     631                        $output .= "<p>Version DBv1 detected</p>"; 
     632                        $output .= pw_db_upgrade::upgradeDBv1ToDBv3(); 
     633                        return $output . "</p>"; 
     634                } 
     635                return $output . "ERROR:  non-standard database state!"; 
    496636        } 
    497637} // end class pw_admin 
  • trunk/wp-infocard/wp/clickback.pw.php

    r106 r144  
    4242                } 
    4343 
    44         pw_utils::printDebug("Clickback: Challenge Created. <br/>" 
    45                         . "Clickback: salted data is " . (($data)?$data:"empty") . "<br/>" 
    46                         . "Clickback: length is " . PW_CLICKBACK_LENGTH  
    47                         . "<br/>Clickback: salt is $clickback_salt <br/>"); 
     44        pw_utils::printDebug("Clickback: Challenge Created (" . PW_CLICKBACK_LENGTH . " characters)<br/>"); 
     45        pw_utils::printDebug("<ul><li>salted data is " . (($data)?$data:"empty") . "</li>" 
     46                        . "<li>Clickback: salt is $clickback_salt </li>", 2); 
    4847 
    4948                $data = MD5($clickback_salt . $data); 
     
    5150                $chopped = substr($data, 0, PW_CLICKBACK_LENGTH); 
    5251 
    53         pw_utils::printDebug("Clickback: Hash of the salted challenge data: $data<br/>" 
    54                         . "Clickback: Chopped challenge data: $chopped <br/>"); 
     52        pw_utils::printDebug("<li>Hash of the salted challenge data: $data</li>" 
     53                        . "<li>Chopped challenge data: $chopped</li></ul>", 2); 
    5554 
    5655                return ($chopped); 
     
    108107        // Output:              none 
    109108        // Side Effects: sends an email 
    110         function sendAccountValidation( $clickbackID, $user_email )  
     109        function sendAccountValidation( $clickbackID, $user_email, $function='registration' )  
    111110        { 
    112                 global $mosConfig_live_site; 
     111                switch ($function) 
     112                { 
     113                        case "registration": 
     114                                $message  = sprintf('Please complete your registration at %s by opening the link below.', pw_utils::getTitle()) . "\r\n\r\n"; 
     115                                $email_title  = 'New Information Card Registration'; 
     116                        break; 
     117 
     118                        case "emailvalidation": 
     119                                $email_title  = 'Information Card Email Validation'; 
     120                                $message  = sprintf('Someone has recently attempted to change their email address at %s (%s) to be this email address.  If you are the person who has triggered this change, please click on the link below to confirm. If you have received this email in error, please disregard.', pw_utils::getTitle(), pw_utils::getSuccessUrl()) . "\r\n\r\n"; 
     121                        break; 
     122                        case "cardvalidation": 
     123                                $email_title  = 'New Information Card Validation'; 
     124                                $message  = sprintf('Someone has recently attempted to change the information card associated with the account at this email address at %s (%s).  If you are the person who has triggered this change, please click on the link below to confirm. If you have received this email in error, please disregard.', pw_utils::getTitle(), pw_utils::getSuccessUrl()) . "\r\n\r\n"; 
     125                        break; 
     126 
     127 
     128                        default: 
     129                                pw_utils::printDebug('Error: invalid function passed to sendAccountValidation!<br/>'); 
     130 
     131                } 
    113132                $clickbackUrl = PW_SECUREPLUGINURL . "/" . PW_PLUGIN . "/login/infocard-clickback.php?clickbackID=" . $clickbackID; 
    114133 
    115                 $message  = sprintf('Please complete your registration at %s by opening the link below.', pw_utils::getTitle()) . "\r\n\r\n"; 
    116                 $message .= $clickbackUrl."\r\n\r\nThanks\r\n"; 
     134                $message .= $clickbackUrl."\r\n\r\nThank You.\r\n"; 
    117135                // sendEmail: to-address, subject, body 
    118                 pw_utils::sendEmail($user_email, 'New InfoCard Registration', $message); 
     136                pw_utils::sendEmail($user_email, $email_title, $message); 
    119137 
    120138                pw_utils::printDebug( "<br/><br/>Account Validation is required.<br/>" 
  • trunk/wp-infocard/wp/login/infocard-clickback.php

    r98 r144  
    2121        </title> 
    2222        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    23         <link rel="stylesheet" href="<?php pw_utils::printCSSlink(); ?>" type="text/css" /> 
     23        <link rel="stylesheet" href="<?php pw_utils::printCSSlink('ssl'); ?>" type="text/css" /> 
    2424        <script type="text/javascript" src="<?php echo pw_utils::printJqueryLocation(); ?>"></script> 
    2525        <script> 
     
    101101        </div> 
    102102        <div id="pw_login_footer"> 
    103                 <a id="pw_pamelaproject_logo" href="http://pamelaproject.com" alt="Powered by PamelaWare"><img src='<?php pw_utils::displayPamelaProjectLogo(); ?>' /></a> 
     103                <a id="pw_pamelaproject_logo" href="https://pamelaproject.com" alt="Powered by PamelaWare"><img src='<?php pw_utils::displayPamelaProjectLogo('ssl'); ?>' /></a> 
    104104        </div> 
    105105  </div> 
  • trunk/wp-infocard/wp/login/infocard-login.php

    r109 r144  
    3232</head> 
    3333<body> 
     34<?php 
     35        if ( !($_SERVER['HTTPS']) || !(strtolower($_SERVER['HTTPS']) == 'on')) 
     36        { 
     37                pw_utils::errorPageRedirect('NOHTTPS'); 
     38        } 
     39 
     40?> 
    3441  <div id="pw_login_main"> 
    3542        <div id="pw_login_header"> 
  • trunk/wp-infocard/wp/processing.pw.php

    r108 r144  
    2626                pw_utils::printDebug("&nbsp;Login ID: ".$datamap['user_login']->new_value."<br />"); 
    2727                pw_utils::printDebug("&nbsp;Account ID: ".$datamap['ID']->new_value."<br />"); 
    28                 pw_utils::printDebug("&nbsp;Status: ".$status." <br/>"); 
     28                pw_utils::printDebug("&nbsp;User Status: ".$status." <br/>"); 
    2929 
    3030                pw_utils::printDebug("&nbsp;Errors: ");  
     
    3434                        pw_utils::printDebug(" none<br />"); 
    3535 
    36                 pw_utils::printDebug("&nbsp;Trusted Source:"); 
    37                 if ($blessed) 
    38                         pw_utils::printDebug("Yes<br/>"); 
    39                 else 
    40                         pw_utils::printDebug("No<br/>"); 
     36                pw_utils::printDebug("&nbsp; Issuer Trust: ".$blessed."<br />"); 
    4137 
    4238                pw_utils::printDebug("&nbsp;Account Validation: "); 
    43                 if ($validated
    44                         pw_utils::printDebug("Sent<br/>"); 
     39                if ($validated === 'validate'
     40                        pw_utils::printDebug("Required<br/>"); 
    4541                else 
    4642                        pw_utils::printDebug("Not needed<br/>"); 
     
    5147        } // end function showProcessingSummary 
    5248 
     49        /* 
     50                Function:       getDBv1CardHash 
     51                Description:    Before we started storing card hash, we stored 
     52                                the PPID and an MD5 hash of the base64-decoded 
     53                                modulus. 
     54                                This means that when we upgraded the database 
     55                                from v1 to v3, we had to make a hash out of 
     56                                the ppid and the md5 hash, not the ppid and the 
     57                                modulus. 
     58                Input:          none 
     59                Output:         SHA256 card hash with ppid  
     60                                        & md5(base64_decode(modulus)) 
     61        */ 
     62        function getDBv1CardHash() 
     63        { 
     64                global $claimslist; 
     65 
     66                $mod = md5(base64_decode($claimslist['signerkeymodulus']->token_value)); 
     67                pw_utils::printDebug('<br/>Checking DBv1 card hash<br/>', 1); 
     68                pw_utils::printDebug('--Modulus:  ' . $mod . '<br/>', 1); 
     69                 
     70                $cardhash = pw_processing::calculateCardHash( 
     71                        $claimslist['privatepersonalidentifier']->token_value, 
     72                        $mod 
     73                ); 
     74                pw_utils::printDebug('--CardHash:  ' . $cardhash . '<br/>', 1); 
     75                return $cardhash; 
     76        } //end function getDBv1CardHash 
     77         
    5378} // end class pw_processing 
    5479?> 
  • trunk/wp-infocard/wp/userdata.pw.php

    r110 r144  
    2222class pw_userdata extends pwlib_userdata 
    2323{ 
    24         // Function:  evaluateIncomingRequest 
    25         // Description: decides what kind of user is connecting. 
    26         // Input: email, modulus, ppid from incoming request 
    27         // Output: An array of user information. With the 
    28         //                      following indices: 
    29         //                      array['status'] - contains 1 of these statuses: 
    30         //                      1. valid-user - supplied email address exists 
    31         //                      and belongs to same user as supplied modulus/ppid 
    32         //                      2. new-user - email address & modulus/ppid are new 
    33         //                      3. new-card - email address exists but modulus is new 
    34         //                      4. new-email - modulus/ppid exists but email is new 
    35         //                      5. an error code 
    36         // 
    37         //              array['id'] - contains the user id number (or 0 if the status  
    38         //              is anything other than valid-user) 
    39         // Side-effects: none 
    40         function evaluateIncomingRequest() 
    41         { 
    42                 global $wpdb, $claimslist, $datamap; 
    43                 $incominguser['id'] = 0; 
    44                 $incominguser['status'] = 'UNKNOWNERROR'; 
    45                 $identity_user_id = 0; 
    46  
    47                 $cardhash = pw_processing::getCardHash(); 
    48                 pw_utils::printDebug( '<br/>Evaluating Incoming Request:<br/>'); 
    49  
    50                 if (!is_email($claimslist['emailaddress']->token_value)) 
    51                 { 
    52                         $incominguser['status'] = "INVALIDEMAIL"; 
    53                         return $incominguser; 
    54                 } 
    55                  
    56                 $query = "SELECT * FROM `" . PW_TABLE_PREFIX  
    57                         . "infocard_identities` WHERE cardhash = '" 
    58                         . $cardhash . "'"; 
    59                 $identity_info = $wpdb->get_results( $query, OBJECT ); 
    60  
    61                 switch (count($identity_info)) 
    62                 { 
    63                         case 1: 
    64                                 // could be valid-user, or new-email 
    65                                 $identity_user_id = $identity_info[0]->accountid; 
    66                                 $datamap['cardhash']->add_db_value($identity_info[0]->cardhash); 
    67                         break; 
    68  
    69                         case 0: 
    70                                 // could be new-card or new-user 
    71                                 $identity_user_id = 0; 
    72                         break; 
    73  
    74                         default: 
    75                                 $incominguser['status'] = "CARDNOTUNIQUE"; 
    76                                 return $incominguser; 
    77                 } 
    78  
    79                 pw_utils::printDebug('&nbsp;&nbsp;Card belongs to account #: ' . $identity_user_id . "<br/>" );  
    80  
    81                 $query = "SELECT * from " . PW_TABLE_PREFIX . "users " 
    82                         . "WHERE user_email LIKE '" 
    83                         . $claimslist['emailaddress']->token_value . "'"; 
    84  
    85                 $user_info = $wpdb->get_results( $query, ARRAY_A ); 
    86  
    87                 switch (count($user_info)) 
    88                 { 
    89                         case 1: 
    90                                 $mail_user_id = $user_info[0][ID]; 
    91                                 pw_utils::printDebug('&nbsp;&nbsp;User belongs to account #: ' . $mail_user_id . "<br/>" ); 
    92                                 if ($identity_user_id == 0) 
    93                                 { 
    94                                         $incominguser['id'] = $mail_user_id; 
    95                                         $incominguser['status'] = 'new-card'; 
    96                                 } 
    97                                 elseif ($identity_user_id != $mail_user_id) 
    98                                 { 
    99                                         $incominguser['status'] = "CLAIMSMISMATCHED"; 
    100                                         return $incominguser; 
    101                                 } 
    102                                 if ($identity_user_id == $mail_user_id) 
    103                                 { 
    104                                         $incominguser['id'] = $mail_user_id; 
    105                                         $incominguser['status'] = 'valid-user'; 
    106  
    107                                 } 
    108                                 foreach (array_keys($datamap) as $key) 
    109                                 { 
    110                                         if (array_key_exists($datamap[$key]->mappingattribute, $user_info[0])) 
    111                                         { 
    112                                                 pw_utils::printDebug('Existing Value: found '.$datamap[$key]->mappingattribute.' in user_info[0]<br/>'); 
    113                                                 $datamap[$key]->add_db_value($user_info[0][$datamap[$key]->mappingattribute]); 
    114                                         } 
    115                                 } 
    116  
    117                                 // special case for first, last name 
    118                                 $first = get_usermeta($mail_user_id, 'first_name'); 
    119                                 if ($first) 
    120                                 { 
    121                                         pw_utils::printDebug('Existing Value: found '.$datamap['first_name']->mappingattribute.' in usermeta ( '.$first.' )<br/>'); 
    122                                         $datamap['first_name']->add_db_value( $first ); 
    123                                 } 
    124  
    125                                 $last = get_usermeta($mail_user_id, 'last_name'); 
    126                                 if ($last) 
    127                                 { 
    128                                         pw_utils::printDebug('Existing Value: found '.$datamap['last_name']->mappingattribute.' in usermeta ( '.$last.' )<br/>'); 
    129                                         $datamap['last_name']->add_db_value( $last ); 
    130                                 } 
    131  
    132                                 if ( PW_CUSTOM_DATA ) 
    133                                         pw_customdata::evaluateIncomingCustomData( $mail_user_id ); 
    134                         break; 
    135  
    136                         case 0: 
    137                                 $mail_user_id = 0; 
    138                                 if ($identity_user_id == 0) 
    139                                 { 
    140                                         // no user entry or identity entry 
    141                                         $incominguser['status'] = 'new-user'; 
    142                                 } 
    143                                 else 
    144                                 { 
    145                                         //identity entry but no mail entry 
    146                                         $incominguser['id'] = $identity_user_id; 
    147                                         $incominguser['status'] = 'new-email'; 
    148                                 } 
    149                         break; 
    150  
    151                         default: 
    152                                 // More than one record returned for an email address 
    153                                 $incominguser['status'] = "EMAILNOTUNIQUE"; 
    154                                 return $incominguser; 
    155                 } 
    156  
    157                 pw_utils::printDebug( "&nbsp;&nbsp;Email address belongs toaccount #: $mail_user_id <br/>" ); 
    158                 pw_utils::printDebug( "&nbsp;&nbsp;Status: " . $incominguser['status'] . "<br/><br/>" ); 
    159  
    160                 return $incominguser; 
    161         } // end function evaluateIncomingRequest 
    16224 
    16325        function mapTokenData() 
    16426        { 
    16527                global $claimslist, $datamap; 
    166                 pw_utils::printDebug('<br/>Mapped Token Data:<br/>'); 
     28                pw_utils::printDebug('<br/>Mapped Token Data:<br/>', 1); 
    16729                foreach(array_keys($datamap) as $key) 
    16830                { 
    16931                        $datamap[$key]->new_value = eval($datamap[$key]->mappingfunction); 
    170                         //pw_utils::printDebug('&nbsp;Mapping Function: '.$datamap[$key]->mappingfunction.'<br/>'); 
    171                         pw_utils::printDebug('&nbsp;' . $datamap[$key]->handle.'&nbsp;Value: '.$datamap[$key]->new_value.'<br/>'); 
    172                 } 
    173                 pw_utils::printDebug('<br />'); 
     32                        pw_utils::printDebug('&nbsp;Mapping Function: '.$datamap[$key]->mappingfunction.'<br/>',2); 
     33                        pw_utils::printDebug('&nbsp;' . $datamap[$key]->handle.'&nbsp;Value: '.$datamap[$key]->new_value.'<br/>', 1); 
     34                } 
     35                pw_utils::printDebug('<br />', 1); 
    17436        } // end