wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.AuthUserRDB.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.AuthUserRDB.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/security/class.AuthUser.php");
20 require_once(BASE."wcmf/lib/security/class.UserManager.php");
21 require_once(BASE."wcmf/lib/util/class.InifileParser.php");
22 require_once(BASE."wcmf/3rdparty/adodb/adodb.inc.php");
23 
24 /**
25  * @class AuthUserRDB
26  * @ingroup Security
27  * @brief AuthUser that gets configuration from an database
28  * @deprecated Use AuthUser and UserRDB instead
29  *
30  * @author ingo herwig <ingo@wemove.com>
31  */
32 class AuthUserRDB extends AuthUser
33 {
34  /**
35  * @see AuthUser::getUserData()
36  *
37  * @note This class relies on the following database tables
38  * @verbatim
39  CREATE TABLE nm_user_role (
40  fk_user_id int(11) NOT NULL default '0',
41  fk_role_id int(11) NOT NULL default '0',
42  KEY fk_user_id (fk_user_id,fk_role_id)
43  ) TYPE=MyISAM;
44 
45  CREATE TABLE role (
46  id int(11) NOT NULL auto_increment,
47  name varchar(50) default NULL,
48  PRIMARY KEY (id)
49  ) TYPE=MyISAM;
50 
51  CREATE TABLE user (
52  id int(11) NOT NULL auto_increment,
53  name varchar(50) default NULL,
54  firstname varchar(50) default NULL,
55  login varchar(50) default NULL,
56  password varchar(50) default NULL,
57  config varchar(255) default NULL,
58  PRIMARY KEY (id)
59  ) TYPE=MyISAM;
60  @endverbatim
61  *
62  * @note Initialization data given in the constructor require the following keys:
63  * dbType, dbHostName, dbUserName, dbPassword, dbName
64  * if dbPrefix is given it will be appended to every table string, which is
65  * usefull if different cms operate on the same database
66  */
67  function getUserData($login, $password)
68  {
69  $userData = array();
70 
71  // connect to database
72  $conn = &ADONewConnection($this->_initParams['dbType']);
73  $connected = $conn->PConnect($this->_initParams['dbHostName'],$this->_initParams['dbUserName'],$this->_initParams['dbPassword'],$this->_initParams['dbName']);
74  if (!$connected)
75  WCMFException::throwEx($conn->ErrorMsg(), __FILE__, __LINE__);
76 
77  $conn->replaceQuote = "\'";
78  $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
79  define(ADODB_OUTP, "gError");
80 
81  // get database prefix if defined
82  $this->_dbPrefix = $params['dbPrefix'];
83 
84  // log sql if requested
85  $parser = &InifileParser::getInstance();
86  if (($logSQL = $parser->getValue('logSQL', 'cms')) === false)
87  $logSQL = 0;
88  $conn->LogSQL($logSQL);
89 
90  // query database
91  $sqlStr = "SELECT ".$dbPrefix."user.id, ".$dbPrefix."user.name, ".$dbPrefix."user.firstname, ".$dbPrefix."user.config, ".$dbPrefix."role.name as rolename
92  FROM ".$dbPrefix."user LEFT JOIN ".$dbPrefix."nm_user_role ON ".$dbPrefix."user.id=".$dbPrefix."nm_user_role.fk_user_id LEFT JOIN ".$dbPrefix."role
93  ON ".$dbPrefix."nm_user_role.fk_role_id=".$dbPrefix."role.id
94  WHERE ".$dbPrefix."user.login='".$login."' AND ".$dbPrefix."user.password='".$password."';";
95  $rs = &$conn->Execute($sqlStr);
96  $firstDone = false;
97  while ($rs && $row = $rs->FetchRow())
98  {
99  if (!$firstDone)
100  {
101  $userData['id'] = $row['id'];
102  $userData['name'] = $row['name'];
103  $userData['firstname'] = $row['firstname'];
104  $userData['config'] = $row['config'];
105  $userData['roles'] = array();
106  $firstDone = true;
107  }
108  array_push($userData['roles'], $row['rolename']);
109  }
110  $conn->Close();
111 
112  return $userData;
113  }
114 }
115 ?>
AuthUser provides a storage and methods for user data used for authentication/authorization purposes...
getUserData($login, $password)
throwEx($message, $file='', $line='')
AuthUser that gets configuration from an database.