WordPress.org

Plugin Directory

Changeset 351751


Ignore:
Timestamp:
02/26/11 12:14:05 (7 years ago)
Author:
GizzmoAsus
Message:

Updated the core soap_auth class to add additional comments and re-structure the class to aid readability. Updated the readme file to reflect change in the support page address

Location:
soap-authentication/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • soap-authentication/trunk/readme.txt

    r271800 r351751  
    11=== Plugin Name === 
    22Contributors: GizzmoAsus 
    3 Donate link: http://matthewkellett.co.uk/portfolio/soap-auth.php 
     3Donate link: http://matthewkellett.co.uk/portfolio/addons/wordpress/soap-auth.html 
    44Tags: soap, authentication, register 
    55Requires at least: 3.0 
     
    3939== Changelog == 
    4040 
     41= 1.1 = 
     42* Updated the documentation throughout the class to help modifications, 
     43* Updated code structure to improve readability 
     44* Updated links associated with the plugin to go to the correct destination 
     45 
    4146= 1.0 = 
    4247Latest Release - No recent changes 
  • soap-authentication/trunk/soap_auth.php

    r271807 r351751  
    44    Plugin URI: http://matthewkellett.co.uk/portfolio/soap-auth.php 
    55    Description: Used to externally authenticate WP users using a SOAP Service 
    6     Version: 1.0 
     6    Version: 1.1 
    77    Author: Matthew Kellett 
    88    Author URI: http://matthewkellett.co.uk 
     
    2525*/ 
    2626 
    27 function is_wpmu_enabled(){ 
     27/** 
     28 * is_wpmu_enabled() 
     29 * 
     30 * Checks to see if WPMU is installed and returns a boolean value based on the result 
     31 * 
     32 * @return boolean Returns true if WPMU is enabled, otherwise false 
     33 */ 
     34function is_wpmu_enabled() { 
    2835    # check if we can detect the version (not always available though) 
    2936    global $wmpu_version; 
     
    3946    return false; 
    4047} 
    41  
    4248 
    4349/** 
     
    4652 * A class to authenticate wordpress users using an external SOAP service 
    4753 * 
    48  * @author Matthew Kellett <email@matthewkellett.co.uk> 
    49  * 
     54 * @author Matthew Kellett 
     55 * @version 1.1 
     56 * @change Updated structure and added docblocks to all functions 
     57 * @todo Add the ability to use custom parameters in the soap call 
     58 * @todo Add additional messages to the options so they can be set via the settings page 
    5059 */ 
    5160class Soap_Auth { 
     61 
     62    /** 
     63     * Soap_Auth::getOptions() 
     64     * 
     65     * This function sets up all of the options for the soap auth class i.e. generates 
     66     * the options array, collects the current system roles for permission mappings and 
     67     * registers these options with the system 
     68     * 
     69     * @return void 
     70     */ 
    5271    function getOptions() { 
    5372        $options = get_option('soap_auth_options'); 
     
    86105    } 
    87106 
    88     function updateOptions(){ 
     107    /** 
     108     * Soap_Auth::updateOptions() 
     109     * 
     110     * This function will update the available options for the soap auth class. 
     111     * All parameters passes through from the $_POST array are cleansed before 
     112     * being assigned to the relevant options. Also adds the styles and javascript 
     113     * necessary for the admin interfaces to work correctly. 
     114     * 
     115     * @return void 
     116     */ 
     117    function updateOptions() { 
    89118        if(isset($_POST['save_soap_settings'])) { 
    90119            $options = Soap_Auth::getOptions(); 
     
    137166    } 
    138167 
     168    /** 
     169     * Soap_Auth::soap_auth_add_menu() 
     170     * 
     171     * Creates the default menu option once the plugin has been activated. If WPMU 
     172     * is enabled then this will be added to the main WPMU menu, otherwise it will 
     173     * add it to the main options menu 
     174     * 
     175     * @return void 
     176     */ 
    139177    function soap_auth_add_menu() { 
    140178        if (is_wpmu_enabled()) { 
    141             add_submenu_page('ms-admin.php',__('Soap Authentication', 'Soap_Auth'), __('Soap Authentication', 'Soap_Auth'), 'manage_options', basename(__FILE__), array('Soap_Auth', 'soap_auth_display_options')); 
     179            # add the menu to the main WPMU menu 
     180            add_submenu_page( 
     181                'ms-admin.php', 
     182                __('Soap Authentication', 'Soap_Auth'), 
     183                __('Soap Authentication', 'Soap_Auth'), 
     184                'manage_options', 
     185                basename(__FILE__), 
     186                array('Soap_Auth', 'soap_auth_display_options') 
     187            ); 
    142188        } else { 
    143             add_options_page(__('Soap Authentication', 'Soap_Auth'), __('Soap Authentication', 'Soap_Auth'), 'manage_options', basename(__FILE__), array('Soap_Auth', 'soap_auth_display_options')); 
    144         } 
    145     } 
    146  
     189            # add the menu to the main options section 
     190            add_options_page( 
     191                __('Soap Authentication', 'Soap_Auth'), 
     192                __('Soap Authentication', 'Soap_Auth'), 
     193                'manage_options', basename(__FILE__), 
     194                array('Soap_Auth', 'soap_auth_display_options') 
     195            ); 
     196        } 
     197    } 
     198 
     199    /** 
     200     * Soap_Auth::soap_auth_display_options() 
     201     * 
     202     * This function builds the main admin interface for the plugin. It basically 
     203     * builds a form and adds the options to it in the relevant sections. If WPMU 
     204     * is enabled then an extra role mapping is provided to allow the super admin role 
     205     * 
     206     * @return void 
     207     */ 
    147208    function soap_auth_display_options() { 
    148209        # initialise global objects 
     
    301362    } 
    302363 
    303  
    304     #actual meat of plugin - essentially, you're setting $username and $password to pass on to the system. 
    305     #You check from your external system and insert/update users into the WP system just before WP actually 
    306     #authenticates with its own database. 
     364    /** 
     365     * Soap_Auth::soap_auth_check_login() 
     366     * 
     367     * This is the main authentication function of the plugin. Given both the username and password it will 
     368     * make use of the options set to authenticate against an external soap service. If a user is authenticated 
     369     * and already exists in the system then their details will be updated, otherwise it will generate a new 
     370     * user and set up their permissions based on the mappings. 
     371     * 
     372     * @param string $username 
     373     * @param string $password 
     374     * @return void 
     375     */ 
    307376    function soap_auth_check_login($username, $password) { 
    308377        require_once(ABSPATH.'wp-includes/registration.php'); 
     
    310379        $options = Soap_Auth::getOptions(); 
    311380        $soap_url = ($options['soap_wsdl_path'] != "") ? $options['soap_wsdl_path'] : null; 
    312         #if on same host have to use resource id to make sure you don't lose the wp db connection 
     381        # if on same host have to use resource id to make sure you don't lose the wp db connection 
    313382 
    314383        if (!is_null($soap_url)) { 
    315             #do the password hash for comparing 
     384            #do the password hash for comparison 
    316385            switch($options['enc_method']) { 
    317386                case "SHA256 Hash" : 
     
    329398            } 
    330399 
     400            # carry out the soap call to authenticate the user 
    331401            try{ 
    332402                $method = $options['auth_function']; 
     
    384454                    $all_roles = $wp_roles->get_names(); 
    385455 
    386                     foreach ($all_roles as $name => $display){ 
     456                    foreach ($all_roles as $name => $display) { 
    387457                        // $options['role_'.$name] == $user_role 
    388458                        $role_match = false; 
     
    390460                            # multiple role maps so set them up 
    391461                            $mappings = explode(",",$options['role_'.$name]); 
    392                             foreach ($mappings as $map){ 
     462                            foreach ($mappings as $map) { 
    393463                                if ($map == $user_role) { 
    394464                                    $role_match = true; 
     
    427497                $error_type = "noauth"; 
    428498            } 
    429         }else{ 
     499        } else { 
    430500            global $error_msg; 
    431501            $error_msg = "The authentication settings could not be found, please contact an administrator to update these so you can log in"; 
     
    435505    } 
    436506 
    437     function object2array($object){ 
     507    /** 
     508     * Soap_Auth::object2array() 
     509     * 
     510     * Convenient (recursive) function to convert an object to an array 
     511     * 
     512     * @param mixed $object The object to convert to an array, typically a simpleXML Object in this instance 
     513     * @return mixed Returns either the array or the object if it can't be converted 
     514     */ 
     515    function object2array($object) { 
     516        # ensure we are dealing with an object before converting to an array 
    438517        if (is_array($object) || is_object($object)) { 
    439518            $array = array(); 
     
    446525    } 
    447526 
    448     //gives warning for login - where to get "source" login 
     527    /** 
     528     * Soap_Auth::soap_auth_warning() 
     529     * 
     530     * Prints out a the message to be displayed on the login screen, 
     531     * this needs to be set up in the WP options page 
     532     * 
     533     * @return void 
     534     */ 
    449535    function soap_auth_warning() { 
    450536        $opts = Soap_Auth::getOptions(); 
     
    452538    } 
    453539 
     540    /** 
     541     * Soap_Auth::soap_errors() 
     542     * 
     543     * A function for building the error messages that can be used throughout the 
     544     * system, typically on the login page though 
     545     * 
     546     * @return string Returns the error message from the soap authentication call 
     547     */ 
    454548    function soap_errors() { 
    455549        global $error; 
     
    482576    } 
    483577 
    484     //hopefully grays stuff out. 
     578    /** 
     579     * Soap_Auth::soap_warning() 
     580     * 
     581     * This function outputs a warning to the main user profile section to inform 
     582     * the users that changes to personal information will be overwritten if changed 
     583     * the next time they log in 
     584     * 
     585     * @return void 
     586     */ 
    485587    function soap_warning() { 
    486588        echo '<strong style="color:red;">Any changes made below WILL NOT be preserved when you login again. You have to change your personal information per instructions found in the <a href="../wp-login.php">login box</a>.</strong>'; 
    487589    } 
    488590 
    489     //disables the (useless) password reset option in WP when this plugin is enabled. 
     591    /** 
     592     * Soap_Auth::soap_show_password_fields() 
     593     * 
     594     * Disables the password reset option in WP when this plugin is enabled because 
     595     * this should be handled by the main user system and not the wordpress system 
     596     * 
     597     * @return 
     598     */ 
    490599    function soap_show_password_fields() { 
    491600        return 0; 
    492601    } 
    493602 
    494  
    495     /* 
    496      * Disable functions.  Idea taken from http auth plugin. 
     603    /** 
     604     * Soap_Auth::disable_function_register() 
     605     * 
     606     * This functions will disable the default registration for the system when 
     607     * the soap auth plugin is enabled 
     608     * 
     609     * @return void 
    497610     */ 
    498611    function disable_function_register() { 
    499612        $errors = new WP_Error(); 
    500         $errors->add('registerdisabled', __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.')); 
     613        $errors->add( 
     614            'registerdisabled', 
     615            __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.') 
     616        ); 
    501617        ?></form><br /><div id="login_error">User registration is not available from this site, so you can't create an account or retrieve your password from here. See the message above.</div> 
    502618                <p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p> 
     
    505621    } 
    506622 
     623    /** 
     624     * Soap_Auth::disable_function() 
     625     * 
     626     * The main error function to be used when a user tries to 
     627     * register or uses the forgotten password form 
     628     * 
     629     * @return void 
     630     */ 
    507631    function disable_function() { 
    508632        $errors = new WP_Error(); 
    509         $errors->add('registerdisabled', __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.')); 
     633        $errors->add( 
     634            'registerdisabled', 
     635            __('User registration is not available from this site, so you can\'t create an account or retrieve your password from here. See the message above.') 
     636        ); 
    510637        login_header(__('Log In'), '', $errors); 
    511638        ?> 
     
    516643} 
    517644 
     645/** 
     646 * Register the functions form the Soap_Auth class within the 
     647 * relevant sections of the system 
     648 */ 
    518649add_action('admin_menu', array('Soap_Auth', 'updateOptions')); 
    519650add_action('wp_authenticate', array('Soap_Auth', 'soap_auth_check_login'), 1, 2); 
Note: See TracChangeset for help on using the changeset viewer.