Thread: [Phpcms-plugins-cvs] admin4phpCMS/modules/user user.db,NONE,1.1 class.auth.php,NONE,1.1 layout.user.
Brought to you by:
mjahn
From: Martin J. <mj...@us...> - 2004-09-29 20:11:23
|
Update of /cvsroot/phpcms-plugins/admin4phpCMS/modules/user In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19438/modules/user Modified Files: layout.user.xml class.module_user.php Added Files: user.db class.auth.php Removed Files: Perm_XML.xml Auth_XML.xml Log Message: completed phpCMS-config-part began the statistic part Index: class.module_user.php =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/user/class.module_user.php,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- class.module_user.php 25 Aug 2004 21:16:46 -0000 1.8 +++ class.module_user.php 29 Sep 2004 20:10:43 -0000 1.9 @@ -30,6 +30,10 @@ /* * $Log$ +* Revision 1.9 2004/09/29 20:10:43 mjahn +* completed phpCMS-config-part +* began the statistic part +* * Revision 1.8 2004/08/25 21:16:46 mjahn * step 1 is taken * @@ -53,9 +57,15 @@ * */ /** -* include necessary files +* include the authentication-class **/ -include_once (PATH_TO_PEAR.'LiveUser/LiveUser.php'); +//include_once ('Auth.php'); +include_once (dirname (__FILE__).'/class.auth.php'); + +/** +* set the filename of the user-db +**/ +define ('PASSWD_FILE', dirname (__FILE__).'/user.db'); /** * Class for user- and permission-managment @@ -87,6 +97,7 @@ * @access private **/ var $_USER; + var $adminAction = ''; /** * Initialization of the module @@ -94,25 +105,9 @@ * The module registers its own events and connects his methods to some actions **/ function init () { - $liveuserConfig = array( - 'session' => array('name' => 'PHPSESSID','varname' => 'loginInfo'), - 'login' => array('username' => 'handle', 'password' => 'passwd'), - 'cookie' => array('name' => 'loginInfo', 'path' => '/', 'domain' => 'localhost', 'lifetime' => 60), - 'autoInit' => true, - 'authContainers' => array(0 => array('type' => 'XML', - 'file' => dirname(__FILE__).'/Auth_XML.xml', - 'loginTimeout' => 60*30, - 'expireTime' => 60*60*2, - 'idleTime' => 60*30, - 'allowDuplicateHandles' => 0, - 'passwordEncryptionMode' => 'MD5' - ) - ), - 'permContainer' => array('type' => 'XML_Simple', - 'file' => dirname(__FILE__).'/Perm_XML.xml' - ) - ); - $this->_USER = LiveUser::factory($liveuserConfig); + $this->_USER = new SaferAuth('File', PASSWD_FILE); + $this->_USER->setShowLogin (false); + // connect to actions $this->_registerAction ('doParseParam', 'parseParam'); $this->_registerAction ('doParseMenuMain', 'getMenuMain'); @@ -137,35 +132,61 @@ **/ function parseParam (&$actiondata) { + // start the user-managaer + $this->_USER->start (); + //echo ($this->_USER->getAuth() ? 'true' : 'false'); + // load our own extra template $actiondata1 = array ('filename'=>dirname (__FILE__).'/layout.user.xml'); $this->_callEvent ('LAYOUT_ADD_TEMPLATE', $actiondata1); - // check if the user submitted the login-form - $logout = false; - $username = ''; - $passwd = ''; - $password = ''; - if (isset ($actiondata['post']['logout'])) { - $logout = true; - unset ($_POST['logout']); - } elseif (isset ($actiondata['get']['logout'])) { - unset ($_GET['logout']); - $logout = true; - } - if (isset ($actiondata['post']['passwd'])) { - $passwd = $actiondata['post']['passwd']; - $logout = false; - } - $username = ''; - if (isset ($actiondata['post']['handle'])) { - $username = $actiondata['post']['handle']; - $logout = false; + // check for logout + if (isset ($actiondata ['post'] ['logout'])) { + if (!isset ($actiondata ['post'] ['submit-login'])) { + $this->_USER->logout (); + $this->_USER->start (); + } + } elseif (isset ($actiondata ['get'] ['logout'])) { + if (!isset ($actiondata ['post'] ['submit-login'])) { + $this->_USER->logout (); + $this->_USER->start (); + } } + + //check for admin-data + if (isset ($actiondata ['post'] ['submit-deluser'])) { - // start the user-managaer - $this->_USER->init($username, $password, $logout); + if (true || $this->_USER->getUsername () == 'Martin Jahn') { + + $this->_selectedUser = array (); + + if ($actiondata ['post'] ['submit-deluser'] == -1) { + // delete multiple user + $this->adminAction = 'delete-user'; + foreach ($actiondata ['post'] as $id=>$value) { + if (substr ($id, 0, 12) != 'select-user-') { + continue; + } + $this->_selectedUser [] = substr ($id, 12); + } + } else { + // delete one user + $this->adminAction = 'delete-user'; + $this->_selectedUser = array ($actiondata ['post'] ['submit-deluser']); + } + } + } + if (isset ($actiondata ['post'] ['submit-newuser'])) { + $this->_newUser = array ($actiondata ['post'] ['newuser-handle'] => $actiondata ['post'] ['newuser-password']); + $this->adminAction = 'new-user'; + } + + if (isset ($actiondata ['post'] ['submit-edituser'])) { + $this->_selectedUser = array ($actiondata ['post'] ['submit-edituser']); + $this->adminAction = 'edit-user'; + } + // check if we have to display something $this->display = (isset ($actiondata['request']['moduleid']) && $actiondata['request']['moduleid'] == 'user'); @@ -176,7 +197,7 @@ } // if the user is not yet logged in - if (!$this->_USER->isLoggedIn ()) { + if (!$this->_USER->getAuth ()) { $this->action = 'login'; } // react onto the action @@ -187,6 +208,9 @@ case 'admin': $this->_registerAction ('doProcess', 'processAdmin'); break; + case 'profile': + $this->_registerAction ('doProcess', 'processProfile'); + break; default: // $this->_registerAction ('doProcess', 'processLogin'); } @@ -209,10 +233,35 @@ } function processAdmin (&$actiondata) { + +// $this->_USER->setMode('sha'); + //check for the correct action we have to do + switch ($this->adminAction) { + case 'delete-user': + foreach ($this->_selectedUser as $id) { + $this->_USER->removeUser ($id); + } + break; + case 'save-user':break; + case 'new-user':; + foreach ($this->_newUser as $id=>$pass) { + $this->_USER->addUser ($id, $pass); + } + case 'edit-user': + //$this->_USER->chgUser ($this->_newUser ['login'], $this->_newUser ['password']); + break; + default:; + } + + // register the correct function $this->_registerAction ('doParseContent', 'getAdminContent'); return true; } + function processProfile (&$actiondata) { + $this->_registerAction ('doParseContent', 'getProfileContent'); + return true; + } /** * Get content for mainmenu @@ -223,7 +272,7 @@ $root = $actiondata['_root']; - if (!$this->_USER->isLoggedIn ()) { + if (!$this->_USER->getAuth ()) { $actiondata1 = array ('_type'=>'menu_main_entry', '_root'=>$root, 'name'=>'Anmeldung', 'module'=>'user', '_id'=>'usermenu', '_root'=>'mainmenu', 'extra'=>'class="active"'); $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata1); return true; @@ -244,7 +293,7 @@ * @param array $actiondata $actiondata['_root'] must provide the id of the parental element **/ function getMenuSub (&$actiondata) { - if (!$this->_USER->isLoggedIn ()) { + if (!$this->_USER->getAuth ()) { return true; } @@ -254,6 +303,12 @@ $root = $actiondata['_root']; + $actiondata1 = array ('_type'=>'menu_sub_entry', '_root'=>$root, 'name'=>'Benutzer-Profil', 'module'=>'user', '_id'=>'userprofile', 'action'=>'profile'); + if ($this->action == 'profile') { + $actiondata1 ['extra'] = 'id="current"'; + } + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata1); + $actiondata1 = array ('_type'=>'menu_sub_entry', '_root'=>$root, 'name'=>'Verwaltung', 'module'=>'user', '_id'=>'useroverview', 'action'=>'admin'); if ($this->action == 'admin') { $actiondata1 ['extra'] = 'id="current"'; @@ -271,11 +326,22 @@ function getLoginContent (&$actiondata) { $root = $actiondata['_root']; + + if (isset ($this->_USER) && $this->_USER->getStatus () != 0) { + $actiondata1 = array ('errortext'=>$this->_USER->getStatus ()); + $this->_callEvent ('ERROR_NOTICE', $actiondata1); + } $actiondata1 = array ('_id'=>'loginform', '_root'=>$root, '_type'=>'form', 'method'=>'post', 'action'=>'index.php'); $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata1); - $actiondata1 = array ('_id'=>'loginform-content', '_root'=>'loginform', '_type'=>'us_loginform', 'method'=>'post'); + $users =$this->_USER->listUsers (); + $list = ''; + foreach ($users as $id=>$user) { + $list .= '<option value="'.$user['username'].'">'.$user ['username'].'</option>'; + } + + $actiondata1 = array ('_id'=>'loginform-content', '_root'=>'loginform', '_type'=>'us_loginform', 'method'=>'post', 'userlist'=>$list); $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata1); if (isset ($_GET) && is_array ($_GET)) { @@ -296,31 +362,75 @@ * @param array $actiondata $actiondata['_root'] must provide the id of the parental element **/ function getStatusContent (&$actiondata) { - if ($this->_USER->isLoggedIn ()) { + if ($this->_USER->getAuth () == 1) { $root = $actiondata['_root']; - $actiondata = array ('_id'=>'1', '_root'=>$root, '_type'=>'paragraph', 'content'=>$this->_USER->getProperty ('handle').' (<a href="?logout=logout">abmelden</a>)'); - $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata); + $actiondata1 = array ('_id'=>'1', '_root'=>$root, '_type'=>'paragraph', 'content'=>$this->_USER->session['username'].' (<a href="?logout=logout">abmelden</a>)'); + $this->_callEvent('LAYOUT_ADD_ELEMENT', $actiondata1); } return true; } /** - * Get content for statusbar + * Get content for admin content * * @param array $actiondata $actiondata['_root'] must provide the id of the parental element **/ function getAdminContent (&$actiondata) { - $this->actiondata1 = array ('_root'=>$actiondata ['_root'], '_id'=>'us_list', '_type'=>'us_userlist'); + + $actiondata1 = array ('_root'=>$actiondata ['_root'], '_id'=>'container', '_type'=>'block', 'extra'=>'id="container"'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); - $this->actiondata1 = array ('_root'=>'us_list', '_id'=>'us_list_entry-1', '_type'=>'us_listentry', 'id'=>'1', 'username'=>'Martin Jahn'); + $actiondata1 = array ('_root'=>'container', '_id'=>'us_admin_form', '_type'=>'form'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); - $this->actiondata1 = array ('_root'=>'us_list', '_id'=>'us_list_entry-2', '_type'=>'us_listentry', 'id'=>'2', 'username'=>'demo'); + $actiondata1 = array ('_root'=>'us_admin_form', '_id'=>'us_form1', '_type'=>'form_input_hidden', 'value'=>'admin', 'name'=>'action'); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + + $actiondata1 = array ('_root'=>'us_admin_form', '_id'=>'us_form2', '_type'=>'form_input_hidden', 'value'=>'user', 'name'=>'moduleid'); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + + $actiondata1 = array ('_root'=>'us_admin_form', '_id'=>'us_list', '_type'=>'us_userlist'); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + + @$user =& $this->_USER->listUsers (); + + if (PEAR::isError ($user)) { + return true; + } + + foreach ($user as $id=>$user) { + + $actiondata1 = array ('_root'=>'us_list', '_id'=>'user-'.$id, '_type'=>'us_listentry', 'id'=>$id, 'username'=>$user ['username']); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + } + + $actiondata1 = array ('_root'=>'us_admin_form', '_id'=>'new-user', '_type'=>'us_newuser'); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + + return true; + } + + /** + * Get content for user profile + * + * @param array $actiondata $actiondata['_root'] must provide the id of the parental element + **/ + function getProfileContent (&$actiondata) { + $items = get_object_vars ($this->_USER); + + $actiondata1 = array ('_root'=>$actiondata ['_root'], '_id'=>'profile-list', '_type'=>'ulist'); $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + $num = count ($this->_USER); + foreach ($this->_USER as $id => $value) { + + $actiondata1 = array ('_root'=>'profile-list', '_id'=>'profile-list-'.$id, '_type'=>'list_entry', 'content'=>$id.' = '.$value); + $this->_callEvent ('LAYOUT_ADD_ELEMENT', $actiondata1); + + } + return true; } @@ -335,7 +445,7 @@ * @param array $actiondata **/ function getUserStatus (&$actiondata) { - $actiondata ['isLoggedIn'] = $this->_USER->isLoggedIn (); + $actiondata ['isLoggedIn'] = $this->_USER->getAuth (); return true; } @@ -361,21 +471,15 @@ function setUserData (&$actiondata) { return true; } - + /** - * + * Get a list of all available users + * + * @param array $actiondata **/ - function displayUserList ($list, $template) { - if (!is_array ($list)) { - return true; - } - - $num = count ($list); - for ($i = 0; $i < num; $i++ ) { - - } - } - + function getUserList (&$actiondata) { + return true; + } } --- NEW FILE: class.auth.php --- <?php /** * User- and permissionmanagment * * authentication class * * <b>License</b> * * 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * @author Martin Jahn <mj...@us...> * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @copyright Copyright (c) 2004, Martin Jahn * @version $Id: class.auth.php,v 1.1 2004/09/29 20:10:43 mjahn Exp $ * @package admin4phpCMS * @subpackage module_user **/ /* * $Log: class.auth.php,v $ * Revision 1.1 2004/09/29 20:10:43 mjahn * completed phpCMS-config-part * began the statistic part * */ /** * include necessary PEAR-packages **/ include_once ('Auth.php'); /** * @author Martin Jahn <mj...@us...> * @package admin4phpCMS */ class SaferAuth extends Auth { /** * Assign data from login form to internal values * * This function takes the values for username and password * from $HTTP_POST_VARS/$_POST and assigns them to internal variables. * If you wish to use another source apart from $HTTP_POST_VARS/$_POST, * you have to derive this function. * * @global $HTTP_POST_VARS, $_POST * @see Auth * @return void * @access private */ function assignData() { if (isset($this->post[$this->_postUsername]) && $this->post[$this->_postUsername] != '') { $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postUsername]) : $this->post[$this->_postUsername]); } if (isset($this->post[$this->_postPassword]) && $this->post[$this->_postPassword] != '') { $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postPassword]) : $this->post[$this->_postPassword] ); } } /** * Has the user been authenticated? * * @access public * @return bool True if the user is logged in, otherwise false. */ function getAuth() { if ( isset($this->session['registered']) ) { return true; } return false; } /** * Add user to the storage container * * @access public * @param string Username * @param string Password * @param mixed Additional parameters * @return mixed True on success, PEAR error object on error * and AUTH_METHOD_NOT_SUPPORTED otherwise. */ function addUser($username, $password, $additional = '') { $this->_loadStorage(); return $this->storage->addUser($username, $password, $additional); } /** * Change password for user in the storage container * * @access public * @param string Username * @param string The new password * @return mixed True on success, PEAR error object on error * and AUTH_METHOD_NOT_SUPPORTED otherwise. */ function changePassword($username, $password) { $this->_loadStorage(); return $this->storage->changePassword($username, $password); } } ?> --- Perm_XML.xml DELETED --- --- Auth_XML.xml DELETED --- Index: layout.user.xml =================================================================== RCS file: /cvsroot/phpcms-plugins/admin4phpCMS/modules/user/layout.user.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- layout.user.xml 25 Aug 2004 21:16:45 -0000 1.1 +++ layout.user.xml 29 Sep 2004 20:10:43 -0000 1.2 @@ -3,10 +3,16 @@ <layout:insert name="us_userlist"> <![CDATA[ - <h2>Benutzerübersicht</h2> - <ul id="userlist"> - <layout:replace name="username" /> - </ul> + <fieldset> + <legend>Benutzerübersicht</legend> + <ul id="userlist"> + <layout:replace name="content" /> + <li class="header"> + <span class="input"><img src="modules/filemanager/img/arrow.gif" width="16" height="16" alt="" class="input" /></span> + <span class="input"><button type="submit" name="submit-deluser" value="-1" title="ausgewählte Benutzereinträge entfernen">ausgewählte Benutzer entfernen</button></span> + </li> + </ul> + </fieldset> ]]> </layout:insert> @@ -14,8 +20,9 @@ <layout:insert name="us_listentry"> <![CDATA[ <li> - <input type="submit" name="deluser-<layout:replace name="id" />" value="D" /> - <input type="submit" name="edituser-<layout:replace name="id" />" value="E" /> + <span class="input"><input type="checkbox" name="select-user-<layout:replace name="id" />" value="1" title="Benutzereintrag auswählen" /></span> + <span class="input"><button type="submit" name="submit-deluser" value="<layout:replace name="username" />" title="Benutzereintrag entfernen"><img src="modules/filemanager/img/delete.gif" width="16" height="16" alt="del" /></button></span> + <span class="input"><button type="submit" name="submit-edituser" value="<layout:replace name="username" />" title="Benutzereintrag editieren" ><img src="modules/filemanager/img/edit.gif" width="16" height="16" alt="edit" /></button></span> <layout:replace name="username" /> </li> ]]> @@ -39,9 +46,9 @@ <![CDATA[ <fieldset> <legend>Neuen Benutzer anlegen</legend> - <label><input type="text" name="new-handle" value="Neues Login" />Loginname </label> - <label><input type="password" name="new-password" value="Neues Passwort" />Passwort </label> - <label><input type="checkbox" name="new-isActive" />Aktiviert </label> + <label><input type="text" name="newuser-handle" value="Neues Login" />Loginname </label> + <label><input type="password" name="newuser-password" value="Neues Passwort" />Passwort </label> + <button type="submit" name="submit-newuser" value="1">Neuen Benutzer anlegen</button> </fieldset> ]]> </layout:insert> @@ -51,13 +58,40 @@ <![CDATA[ <fieldset class="loginform"> <legend>Am System anmelden</legend> - <input type="hidden" name="method" value="<layout:replace name="method" default="post" />" /> + <script type="text/javascript"> + <![CDATA[ + window.onload = document.getElementById ("username").focus(); + ]]> + </script> <layout:replace name="content" /> - <label><input type="text" name="handle" />Benutzer </label> - <label><input type="password" name="passwd" value="" />Passwort </label> + <label><select name="username"><layout:replace name="userlist" /></select>Benutzer </label> + <label><input type="password" name="password" value="" />Passwort </label> <button type="submit" name="login-submit" value="1">Anmelden</button> </fieldset> ]]> </layout:insert> + <layout:insert name="us_loginform_safer"> + <![CDATA[ + <fieldset class="loginform"> + <legend>Am System anmelden</legend> + <script src="modules/user/js/HMAC.js" type="text/javacript"></script> + <script src="modules/user/js/HMAC_<layout:replace name="crypt" default="md5" />.js" type="text/javacript"></script> + <script type="text/javascript"> + <![CDATA[ + window.onload = document.getElementById ("username").focus(); + ]]> + </script> + <layout:replace name="content" /> +<!-- <label><input type="text" id="username" name="username" />Benutzer </label> --> + <label><input type="password" name="password" value="" />Passwort </label> + <input type="hidden" name="HMAC_use_js" id="HMAC_use_js" value="false" /> + <input type="hidden" name="HMAC_key" id="HMAC_key" value="<layout:replace name="hmac_key" default="" />" /> + <input type="hidden" name="HMAC_hash" id="HMAC_hash" /> + <button type="submit" name="login-submit" value="1">Anmelden</button> + </fieldset> + ]]> + </layout:insert> + + </layout> \ No newline at end of file --- NEW FILE: user.db --- Martin Jahn:{SHA}vC5jpRXo+O4Vao3czy09N0pHSFc= demo:{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE= |