Changeset 160056
- Timestamp:
- 10/02/2009 10:40:47 PM (16 years ago)
- Location:
- shibboleth/trunk
- Files:
-
- 3 edited
-
options-admin.php (modified) (1 diff)
-
options-user.php (modified) (7 diffs)
-
shibboleth.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shibboleth/trunk/options-admin.php
r159838 r160056 148 148 </p> 149 149 150 <table class="form-table optiontable editform" cellspacing="2" cellpadding="5" width="100%">150 <table class="form-table optiontable editform" cellspacing="2" cellpadding="5"> 151 151 <tr valign="top"> 152 152 <th scope="row"><label for="username"><?php _e('Username') ?></label</th> 153 <td><input type="text" id="username" name="headers[username]" value="<?php echo $shib_headers['username'] ?>" /></td> 153 <td><input type="text" id="username" name="headers[username][name]" value="<?php echo 154 $shib_headers['username']['name'] ?>" /></td> 155 <td width="60%"></td> 154 156 </tr> 155 157 <tr valign="top"> 156 158 <th scope="row"><label for="first_name"><?php _e('First name') ?></label</th> 157 <td><input type="text" id="first_name" name="headers[first_name]" value="<?php echo $shib_headers['first_name'] ?>" /></td> 159 <td><input type="text" id="first_name" name="headers[first_name][name]" value="<?php echo 160 $shib_headers['first_name']['name'] ?>" /></td> 161 <td><input type="checkbox" id="first_name_managed" name="headers[first_name][managed]" <?php 162 checked($shib_headers['first_name']['managed']) ?> /> <?php _e('Managed', 'shibboleth') ?></td> 158 163 </tr> 159 164 <tr valign="top"> 160 165 <th scope="row"><label for="last_name"><?php _e('Last name') ?></label</th> 161 <td><input type="text" id="last_name" name="headers[last_name]" value="<?php echo $shib_headers['last_name'] ?>" /></td> 166 <td><input type="text" id="last_name" name="headers[last_name][name]" value="<?php echo 167 $shib_headers['last_name']['name'] ?>" /></td> 168 <td><input type="checkbox" id="last_name_managed" name="headers[last_name][managed]" <?php 169 checked($shib_headers['last_name']['managed']) ?> /> <?php _e('Managed', 'shibboleth') ?></td> 162 170 </tr> 163 171 <tr valign="top"> 164 172 <th scope="row"><label for="nickname"><?php _e('Nickname') ?></label</th> 165 <td><input type="text" id="nickname" name="headers[nickname]" value="<?php echo $shib_headers['nickname'] ?>" /></td> 166 </tr> 167 <tr valign="top"> 168 <th scope="row"><label for="display_name"><?php _e('Display name') ?></label</th> 169 <td><input type="text" id="display_name" name="headers[display_name]" value="<?php echo $shib_headers['display_name'] ?>" /></td> 170 </tr> 171 <tr valign="top"> 172 <th scope="row"><label for="email"><?php _e('Email Address') ?></label</th> 173 <td><input type="text" id="email" name="headers[email]" value="<?php echo $shib_headers['email'] ?>" /></td> 174 </tr> 175 <tr valign="top"> 176 <th scope="row"><label for="update_users"><?php _e('Update User Data', 'shibboleth') ?></label</th> 177 <td> 178 <input type="checkbox" id="update_users" name="update_users" <?php echo shibboleth_get_option('shibboleth_update_users') ? ' checked="checked"' : '' ?> /> 179 <label for="update_users"><?php _e('Use Shibboleth data to update user profile data each time the user logs in.', 'shibboleth'); ?></label> 180 181 <p><?php _e('This will prevent users from being able to manually update these' 182 . ' fields. Note that Shibboleth data is always used to populate the user' 183 . ' profile during account creation.', 'shibboleth'); ?></p> 184 185 </td> 173 <td><input type="text" id="nickname" name="headers[nickname][name]" value="<?php echo 174 $shib_headers['nickname']['name'] ?>" /></td> 175 <td><input type="checkbox" id="nickname_managed" name="headers[nickname][managed]" <?php 176 checked($shib_headers['nickname']['managed']) ?> /> <?php _e('Managed', 'shibboleth') ?></td> 177 </tr> 178 <tr valign="top"> 179 <th scope="row"><label for="_display_name"><?php _e('Display name', 'shibboleth') ?></label</th> 180 <td><input type="text" id="_display_name" name="headers[display_name][name]" value="<?php echo 181 $shib_headers['display_name']['name'] ?>" /></td> 182 <td><input type="checkbox" id="display_name_managed" name="headers[display_name][managed]" <?php 183 checked($shib_headers['display_name']['managed']) ?> /> <?php _e('Managed', 'shibboleth') ?></td> 184 </tr> 185 <tr valign="top"> 186 <th scope="row"><label for="email"><?php _e('Email Address', 'shibboleth') ?></label</th> 187 <td><input type="text" id="email" name="headers[email][name]" value="<?php echo 188 $shib_headers['email']['name'] ?>" /></td> 189 <td><input type="checkbox" id="email_managed" name="headers[email][managed]" <?php 190 checked($shib_headers['email']['managed']) ?> /> <?php _e('Managed', 'shibboleth') ?></td> 186 191 </tr> 187 192 </table> 193 194 <p><?php _e('<em>Managed</em> profile fields are updated each time the user logs in using the current' 195 . ' data provided by Shibboleth. Additionally, users will be prevented from manually updating these' 196 . ' fields from within WordPress. Note that Shibboleth data is always used to populate the user' 197 . ' profile during initial account creation.', 'shibboleth'); ?></p> 188 198 189 199 <br class="clear" /> -
shibboleth/trunk/options-user.php
r159838 r160056 5 5 add_action('personal_options_update', 'shibboleth_personal_options_update'); 6 6 add_action('show_user_profile', 'shibboleth_show_user_profile'); 7 add_action(' edit_user_profile', 'shibboleth_edit_user_profile');7 add_action('admin_footer-user-edit.php', 'shibboleth_admin_footer_edit_user'); 8 8 9 9 … … 17 17 add_filter('show_password_fields', create_function('$v', 'return false;')); 18 18 19 if (shibboleth_get_option('shibboleth_update_users')) { 20 echo ' 21 <script type="text/javascript"> 22 jQuery(function() { 23 jQuery("#first_name,#last_name,#nickname,#display_name,#email").attr("disabled", true); 24 jQuery("h3:contains(\'Name\')").after("<div class=\"updated fade\"><p>' 25 . __('These fields cannot be changed from WordPress.', 'shibboleth') . '<p></div>"); 26 jQuery("form#your-profile").submit(function() { 27 jQuery("#first_name,#last_name,#nickname,#display_name,#email").attr("disabled", false); 28 }); 19 add_action('admin_footer-profile.php', 'shibboleth_admin_footer_profile'); 20 } 21 } 22 23 function shibboleth_admin_footer_profile() { 24 $managed_fields = shibboleth_get_managed_user_fields(); 25 26 if ( !empty($managed_fields) ) { 27 $selectors = join(',', array_map(create_function('$a', 'return "#$a";'), $managed_fields)); 28 29 echo ' 30 <script type="text/javascript"> 31 jQuery(function() { 32 jQuery("' . $selectors . '").attr("disabled", true); 33 jQuery("#first_name").parents(".form-table").before("<div class=\"updated fade\"><p>' 34 . __('Some profile fields cannot be changed from WordPress.', 'shibboleth') . '</p></div>"); 35 jQuery("form#your-profile").submit(function() { 36 jQuery("' . $selectors . '").attr("disabled", false); 29 37 }); 30 </script>';31 }38 }); 39 </script>'; 32 40 } 33 41 } … … 38 46 * Shibboleth managed attributes. 39 47 */ 40 function shibboleth_ edit_user_profile() {48 function shibboleth_admin_footer_edit_user() { 41 49 global $user_id; 42 50 … … 44 52 $shibboleth_fields = array(); 45 53 46 if (shibboleth_get_option('shibboleth_update_users')) { 47 $shibboleth_fields = array_merge($shibboleth_fields, 48 array('user_login', 'first_name', 'last_name', 'nickname', 'display_name', 'email')); 49 } 54 $shibboleth_fields = array_merge($shibboleth_fields, shibboleth_get_managed_user_fields()); 50 55 51 56 if (shibboleth_get_option('shibboleth_update_roles')) { … … 64 69 jQuery(function() { 65 70 jQuery("' . implode(',', $selectors) . '").before("<span style=\"color: #F00; font-weight: bold;\">*</span> "); 66 jQuery(" h3:contains(\'Name\')")67 . after("<div class=\"updated fade\"><p><span style=\"color: #F00; font-weight: bold;\">*</span> '68 . __('Starred fields are managed by Shibboleth and should not be changed from WordPress.', 'shibboleth') . '</p></div>");71 jQuery("#first_name").parents(".form-table") 72 .before("<div class=\"updated fade\"><p><span style=\"color: #F00; font-weight: bold;\">*</span> ' 73 . __('Starred fields are managed by Shibboleth and should not be changed from WordPress.', 'shibboleth') . '</p></div>"); 69 74 }); 70 75 </script>'; … … 79 84 function shibboleth_show_user_profile() { 80 85 $user = wp_get_current_user(); 81 if (get_usermeta($user->ID, 'shibboleth_account')) {82 if (shibboleth_get_option('shibboleth_password_change_url')) {86 $password_change_url = shibboleth_get_option('shibboleth_password_change_url'); 87 if (get_usermeta($user->ID, 'shibboleth_account') && !empty($password_change_url) ) { 83 88 ?> 84 89 <table class="form-table"> 85 90 <tr> 86 <th> Change Password</th>87 <td><a href="<?php echo shibboleth_get_option('shibboleth_password_change_url');88 ?>" target="_blank"><?php_e('Change your password', 'shibboleth'); ?></a></td>91 <th><?php _e('Change Password') ?></th> 92 <td><a href="<?php echo esc_url($password_change_url); ?>" target="_blank"><?php 93 _e('Change your password', 'shibboleth'); ?></a></td> 89 94 </tr> 90 95 </table> 91 96 <?php 92 }93 97 } 94 98 } … … 96 100 97 101 /** 98 * Ensure profile data isn't updated by the user. This only applies to 99 * accounts that were provisioned through Shibboleth, and only if the option 100 * to manage user attributes exclusively from Shibboleth is enabled. 102 * Ensure profile data isn't updated by the user. This only applies to accounts that were 103 * provisioned through Shibboleth, and only for those user fields marked as 'managed'. 101 104 */ 102 105 function shibboleth_personal_options_update() { 103 106 $user = wp_get_current_user(); 104 107 105 if (get_usermeta($user->ID, 'shibboleth_account') && shibboleth_get_option('shibboleth_update_users')) { 106 add_filter('pre_user_first_name', 107 create_function('$n', 'return $GLOBALS["current_user"]->first_name;')); 108 if ( get_usermeta($user->ID, 'shibboleth_account') ) { 109 $managed = shibboleth_get_managed_user_fields(); 108 110 109 add_filter('pre_user_last_name', 110 create_function('$n', 'return $GLOBALS["current_user"]->last_name;')); 111 if ( in_array('first_name', $managed) ) { 112 add_filter('pre_user_first_name', create_function('$n', 'return $GLOBALS["current_user"]->first_name;')); 113 } 111 114 112 add_filter('pre_user_nickname', 113 create_function('$n', 'return $GLOBALS["current_user"]->nickname;')); 115 if ( in_array('last_name', $managed) ) { 116 add_filter('pre_user_last_name', create_function('$n', 'return $GLOBALS["current_user"]->last_name;')); 117 } 114 118 115 add_filter('pre_user_display_name', 116 create_function('$n', 'return $GLOBALS["current_user"]->display_name;')); 119 if ( in_array('nickname', $managed) ) { 120 add_filter('pre_user_nickname', create_function('$n', 'return $GLOBALS["current_user"]->nickname;')); 121 } 117 122 118 add_filter('pre_user_email', 119 create_function('$e', 'return $GLOBALS["current_user"]->user_email;')); 123 if ( in_array('display_name', $managed) ) { 124 add_filter('pre_user_display_name', create_function('$n', 'return $GLOBALS["current_user"]->display_name;')); 125 } 126 127 if ( in_array('email', $managed) ) { 128 add_filter('pre_user_email', create_function('$e', 'return $GLOBALS["current_user"]->user_email;')); 129 } 120 130 } 121 131 } -
shibboleth/trunk/shibboleth.php
r160015 r160056 34 34 35 35 $headers = array( 36 'username' => 'eppn',37 'first_name' => 'givenName',38 'last_name' => 'sn',39 'nickname' => 'eppn',40 'display_name' => 'displayName',41 'email' => 'mail',36 'username' => array( 'name' => 'eppn', 'managed' => false), 37 'first_name' => array( 'name' => 'givenName', 'managed' => true), 38 'last_name' => array( 'name' => 'sn', 'managed' => true), 39 'nickname' => array( 'name' => 'eppn', 'managed' => true), 40 'display_name' => array( 'name' => 'displayName', 'managed' => true), 41 'email' => array( 'name' => 'mail', 'managed' => true), 42 42 ); 43 43 shibboleth_add_option('shibboleth_headers', $headers); … … 52 52 'value' => 'faculty', 53 53 ), 54 // TODO: this could likely do strange things if WordPress has an actual role named 'default' 54 55 'default' => 'subscriber', 55 56 ); 56 57 shibboleth_add_option('shibboleth_roles', $roles); 57 58 58 shibboleth_add_option('shibboleth_update_users', true);59 59 shibboleth_add_option('shibboleth_update_roles', true); 60 60 61 61 shibboleth_insert_htaccess(); 62 63 shibboleth_migrate_old_data(); 62 64 63 65 shibboleth_update_option('shibboleth_plugin_revision', SHIBBOLETH_PLUGIN_REVISION); … … 76 78 register_deactivation_hook('shibboleth/shibboleth.php', 'shibboleth_deactivate_plugin'); 77 79 80 81 /** 82 * Migrate old data to newer formats. 83 */ 84 function shibboleth_migrate_old_data() { 85 86 // new header format, allowing each header to be marked as 'managed' individually 87 $managed = shibboleth_get_option('shibboleth_update_users'); 88 $headers = shibboleth_get_option('shibboleth_headers'); 89 $updated = false; 90 91 foreach ($headers as $key => $value) { 92 if ( is_string($value) ) { 93 $headers[$key] = array( 94 'name' => $value, 95 'managed' => $managed, 96 ); 97 $updated = true; 98 } 99 } 100 101 if ( $updated ) { 102 shibboleth_update_option('shibboleth_headers', $headers); 103 } 104 shibboleth_remove_option('shibboleth_update_users'); 105 106 } 78 107 79 108 /** … … 241 270 } 242 271 243 $username = $_SERVER[$shib_headers['username'] ];272 $username = $_SERVER[$shib_headers['username']['name']]; 244 273 $user = new WP_User($username); 245 274 … … 266 295 // update user data 267 296 update_usermeta($user->ID, 'shibboleth_account', true); 268 if ( shibboleth_get_option('shibboleth_update_users') )shibboleth_update_user_data($user->ID);297 shibboleth_update_user_data($user->ID); 269 298 if ( shibboleth_get_option('shibboleth_update_roles') ) $user->set_role($user_role); 270 299 … … 289 318 290 319 // always update user data and role on account creation 291 shibboleth_update_user_data($user->ID );320 shibboleth_update_user_data($user->ID, true); 292 321 $user_role = shibboleth_get_user_role(); 293 322 $user->set_role($user_role); … … 333 362 334 363 /** 335 * Update the user data for the specified user based on the current Shibboleth headers. 364 * Get the user fields that are managed by Shibboleth. 365 * 366 * @return Array user fields managed by Shibboleth 367 */ 368 function shibboleth_get_managed_user_fields() { 369 $headers = shibboleth_get_option('shibboleth_headers'); 370 $managed = array(); 371 372 foreach ($headers as $name => $value) { 373 if ( $value['managed'] ) { 374 $managed[] = $name; 375 } 376 } 377 378 return $managed; 379 } 380 381 382 /** 383 * Update the user data for the specified user based on the current Shibboleth headers. Unless 384 * the 'force_update' parameter is true, only the user fields marked as 'managed' fields will be 385 * updated. 336 386 * 337 387 * @param int $user_id ID of the user to update 388 * @param boolean $force_update force update of user data, regardless of 'managed' flag on fields 338 389 * @uses apply_filters() Calls 'shibboleth_user_*' before setting user attributes, 339 * where '*' is one of: login, nicename, first_name, last_name, nickname,340 * display_name, email341 */ 342 function shibboleth_update_user_data($user_id ) {390 * where '*' is one of: login, nicename, first_name, last_name, 391 * nickname, display_name, email 392 */ 393 function shibboleth_update_user_data($user_id, $force_update = false) { 343 394 require_once( ABSPATH . WPINC . '/registration.php' ); 344 395 345 396 $shib_headers = shibboleth_get_option('shibboleth_headers'); 397 398 $user_fields = array( 399 'user_login' => 'username', 400 'user_nicename' => 'username', 401 'first_name' => 'first_name', 402 'last_name' => 'last_name', 403 'nickname' => 'nickname', 404 'display_name' => 'display_name', 405 'user_email' => 'email' 406 ); 346 407 347 408 $user_data = array( 348 409 'ID' => $user_id, 349 'user_login' => apply_filters('shibboleth_user_login', $_SERVER[$shib_headers['username']]),350 'user_nicename' => apply_filters('shibboleth_user_nicename', $_SERVER[$shib_headers['username']]),351 'first_name' => apply_filters('shibboleth_user_first_name', $_SERVER[$shib_headers['first_name']]),352 'last_name' => apply_filters('shibboleth_user_last_name', $_SERVER[$shib_headers['last_name']]),353 'nickname' => apply_filters('shibboleth_user_nickname', $_SERVER[$shib_headers['nickname']]),354 'display_name' => apply_filters('shibboleth_user_display_name', $_SERVER[$shib_headers['display_name']]),355 'user_email' => apply_filters('shibboleth_user_email', $_SERVER[$shib_headers['email']]),356 410 ); 411 412 foreach ($user_fields as $field => $header) { 413 if ( $force_update || $shib_headers[$header]['managed'] ) { 414 $filter = 'shibboleth_' . ( strpos($field, 'user_') === 0 ? '' : 'user_' ) . $field; 415 $user_data[$field] = apply_filters($filter, $_SERVER[$shib_headers[$header]['name']]); 416 } 417 } 357 418 358 419 wp_update_user($user_data);
Note: See TracChangeset
for help on using the changeset viewer.