fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [6634] API / Rental: autocreate user for sso


From: Sigurd Nes
Subject: [Fmsystem-commits] [6634] API / Rental: autocreate user for sso
Date: Wed, 24 Nov 2010 21:41:51 +0000

Revision: 6634
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6634
Author:   sigurdne
Date:     2010-11-24 21:41:50 +0000 (Wed, 24 Nov 2010)
Log Message:
-----------
API / Rental: autocreate user for sso

Modified Paths:
--------------
    trunk/frontend/inc/class.bofrontend.inc.php
    trunk/frontend/inc/hook_config.inc.php
    trunk/frontend/setup/setup.inc.php
    trunk/frontend/templates/base/config.tpl
    trunk/login.php

Added Paths:
-----------
    trunk/frontend/inc/class.hook_helper.inc.php

Modified: trunk/frontend/inc/class.bofrontend.inc.php
===================================================================
--- trunk/frontend/inc/class.bofrontend.inc.php 2010-11-24 14:41:34 UTC (rev 
6633)
+++ trunk/frontend/inc/class.bofrontend.inc.php 2010-11-24 21:41:50 UTC (rev 
6634)
@@ -126,14 +126,14 @@
                 * @param string $lastname the user's last name
                 * @param string $password      the user's password
                 */
-               public static function create_delegate_account(string 
$username, string $firstname, string $lastname, string $password)
+               public static function create_delegate_account(string 
$username, string $firstname, string $lastname, string $password, $group_lid = 
'frontend_delegates')
                {
                        
                        // Create group account if needed
-                       if 
(!$GLOBALS['phpgw']->accounts->exists('frontend_delegates') ) // No group 
account exist
+                       if (!$GLOBALS['phpgw']->accounts->exists($group_lid) ) 
// No group account exist
                        {
                                $account                        = new 
phpgwapi_group();
-                               $account->lid           = 'frontend_delegates';
+                               $account->lid           = $group_lid;
                                $account->firstname = 'Frontend';
                                $account->lastname      = 'Delegates';
                                $frontend_delegates     = 
$GLOBALS['phpgw']->accounts->create($account, array(), array(), $modules);
@@ -154,7 +154,7 @@
                        }
                        else
                        {
-                               $frontend_delegates             = 
$GLOBALS['phpgw']->accounts->name2id('frontend_delegates');
+                               $frontend_delegates             = 
$GLOBALS['phpgw']->accounts->name2id($group_lid);
                        }
                        
                        if(isset($username) && isset($firstname) && 
isset($lastname) && isset($password))

Added: trunk/frontend/inc/class.hook_helper.inc.php
===================================================================
--- trunk/frontend/inc/class.hook_helper.inc.php                                
(rev 0)
+++ trunk/frontend/inc/class.hook_helper.inc.php        2010-11-24 21:41:50 UTC 
(rev 6634)
@@ -0,0 +1,70 @@
+<?php
+       /**
+        * rental - Hook helper
+        *
+        * @author Dave Hall <address@hidden>
+        * @author Sigurd Nes <address@hidden>
+        * @copyright Copyright (C) 2010 Free Software Foundation, Inc. 
http://www.fsf.org/
+        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
+        * @package rental
+        * @version $Id: class.hook_helper.inc.php 5822 2010-05-27 12:21:50Z 
sigurd $
+        */
+
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU General Public License as published by
+          the Free Software Foundation, either version 2 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU General Public License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
+
+       phpgw::import_class('frontend.bofrontend');
+       phpgw::import_class('frontend.bofellesdata');
+
+       /**
+        * Hook helper
+        *
+        * @package rental
+        */
+       class frontend_hook_helper
+       {
+               /**
+                * Create useraccount on login for SSO/ntlm
+                *
+                * @return void
+                */
+               public function auto_addaccount()
+               {
+                       $account_lid = $GLOBALS['hook_values']['account_lid'];
+
+                       if(!$GLOBALS['phpgw']->accounts->exists($account_lid))
+                       {
+                               $config = CreateObject('phpgwapi.config', 
'frontend');
+                               $config->read();
+                               $autocreate_user = 
isset($config->config_data['autocreate_user']) && 
$config->config_data['autocreate_user'] ? 
$config->config_data['autocreate_user'] : 0;
+
+                               if($autocreate_user)
+                               {
+                                       $fellesdata_user = 
frontend_bofellesdata::get_instance()->get_user($account_lid);
+                                       if($fellesdata_user)
+                                       {
+                                               // Read default assign-to-group 
from config
+                                               $default_group_id = 
isset($config->config_data['frontend_default_group']) && 
$config->config_data['frontend_default_group'] ? 
$config->config_data['frontend_default_group'] : 0;
+                                               $group_lid = 
$GLOBALS['phpgw']->accounts->name2id($default_group_id);
+                                               $group_lid = $group_lid ? 
$group_lid : 'frontend_delegates';
+
+                                               $password = 'PEre' . mt_rand() 
. '&';
+                                               $account_id = 
frontend_bofrontend::create_delegate_account($account_lid, 
$fellesdata_user['firstname'], $fellesdata_user['lastname'], $password, 
$group_lid);
+                                       }
+                               }
+                       }
+               }
+       }

Modified: trunk/frontend/inc/hook_config.inc.php
===================================================================
--- trunk/frontend/inc/hook_config.inc.php      2010-11-24 14:41:34 UTC (rev 
6633)
+++ trunk/frontend/inc/hook_config.inc.php      2010-11-24 21:41:50 UTC (rev 
6634)
@@ -106,6 +106,34 @@
        }
 
        /**
+       * Get HTML selectbox with user groups - which group to add autocreated 
users
+       *
+       * @param $config
+       * @return string options for selectbox
+       */
+       function frontend_default_group($config)
+       {
+               $groups = $GLOBALS['phpgw']->accounts->get_list('groups');
+               $group_assigned = isset($config['frontend_default_group']) ? 
$config['frontend_default_group'] : '';
+
+               $out = '<option value="">' . lang('none selected') . 
'</option>' . "\n";
+
+               foreach ( $groups as $group => $label)
+               {
+                       $selected = '';
+                       if ( $group_assigned == $group )
+                       {
+                               $selected = ' selected';
+                       }
+
+                       $out .=  <<<HTML
+                               <option 
value="{$group}"{$selected}>{$label}</option>
+HTML;
+               }
+               return $out;
+       }
+
+       /**
        * Get HTML listbox with categories that are candidates for the 
picture_building_cat
        *
        * @param $config

Modified: trunk/frontend/setup/setup.inc.php
===================================================================
--- trunk/frontend/setup/setup.inc.php  2010-11-24 14:41:34 UTC (rev 6633)
+++ trunk/frontend/setup/setup.inc.php  2010-11-24 21:41:50 UTC (rev 6634)
@@ -34,5 +34,6 @@
        $setup_info['frontend']['hooks'] = array
        (
                'menu'  => 'frontend.menu.get_menu',
+               'auto_addaccount'       => 
'frontend.hook_helper.auto_addaccount',
                'config'
        );

Modified: trunk/frontend/templates/base/config.tpl
===================================================================
--- trunk/frontend/templates/base/config.tpl    2010-11-24 14:41:34 UTC (rev 
6633)
+++ trunk/frontend/templates/base/config.tpl    2010-11-24 21:41:50 UTC (rev 
6634)
@@ -20,7 +20,24 @@
                         </table>
                        </td>
                </tr>
+               <tr class="row_on">
+                       <td>{lang_activate_autocreate_user}:</td>
+                       <td>
+                               <select name="newsettings[autocreate_user]">
+                                       <option value="" 
{selected_autocreate_user_}>NO</option>
+                                       <option value="1" 
{selected_autocreate_user_1}>YES</option>
+                               </select>
+                       </td>
+               </tr>
                <tr class="row_off">
+                       <td>{lang_frontend_default_group}:</td>
+                       <td>
+                        <select name="newsettings[frontend_default_group]">
+{hook_frontend_default_group}
+                        </select>
+                       </td>
+               </tr>
+               <tr class="row_on">
                        <td>{lang_ticket_default_group}:</td>
                        <td>
                         <select name="newsettings[tts_default_group]">
@@ -28,7 +45,7 @@
                         </select>
                        </td>
                </tr>
-               <tr class="row_on">
+               <tr class="row_off">
                        <td>{lang_ticket_default_category}:</td>
                        <td>
                                <select name="newsettings[tts_default_cat]">

Modified: trunk/login.php
===================================================================
--- trunk/login.php     2010-11-24 14:41:34 UTC (rev 6633)
+++ trunk/login.php     2010-11-24 21:41:50 UTC (rev 6634)
@@ -73,11 +73,19 @@
                $login  = $_SERVER['PHP_AUTH_USER'];
                $passwd = $_SERVER['PHP_AUTH_PW'];
        }
-       
+
        if ($GLOBALS['phpgw_info']['server']['auth_type'] == 'ntlm' && 
isset($_SERVER['REMOTE_USER']) && (!isset($_REQUEST['skip_remote']) || 
!$_REQUEST['skip_remote']))
        {
                $login  = $_SERVER['REMOTE_USER'];
                $passwd = '';
+
+               $GLOBALS['hook_values'] = array
+               (
+                       'account_lid'   => $login
+               );
+
+               
$GLOBALS['phpgw']->hooks->process('auto_addaccount',array('frontend'));
+
 //------------------Start login ntlm
 
                $GLOBALS['sessionid'] = 
$GLOBALS['phpgw']->session->create($login, $passwd);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]