Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cApiAction
  • cApiActionCollection
  • cApiActionlog
  • cApiActionlogCollection
  • cApiArea
  • cApiAreaCollection
  • cApiArticle
  • cApiArticleCollection
  • cApiArticleLanguage
  • cApiArticleLanguageCollection
  • cApiArticleLanguageVersion
  • cApiArticleLanguageVersionCollection
  • cApiArticleSpecification
  • cApiArticleSpecificationCollection
  • cApiCategory
  • cApiCategoryArticle
  • cApiCategoryArticleCollection
  • cApiCategoryCollection
  • cApiCategoryLanguage
  • cApiCategoryLanguageCollection
  • cApiCategoryTree
  • cApiCategoryTreeCollection
  • cApiClient
  • cApiClientCollection
  • cApiClientLanguage
  • cApiClientLanguageCollection
  • cApiCommunication
  • cApiCommunicationCollection
  • cApiContainer
  • cApiContainerCollection
  • cApiContainerConfiguration
  • cApiContainerConfigurationCollection
  • cApiContent
  • cApiContentCollection
  • cApiContentVersion
  • cApiContentVersionCollection
  • cApiDbfs
  • cApiDbfsCollection
  • cApiFile
  • cApiFileCollection
  • cApiFileInformation
  • cApiFileInformationCollection
  • cApiFrameFile
  • cApiFrameFileCollection
  • cApiFrontendGroup
  • cApiFrontendGroupCollection
  • cApiFrontendGroupMember
  • cApiFrontendGroupMemberCollection
  • cApiFrontendPermission
  • cApiFrontendPermissionCollection
  • cApiFrontendUser
  • cApiFrontendUserCollection
  • cApiGroup
  • cApiGroupCollection
  • cApiGroupMember
  • cApiGroupMemberCollection
  • cApiGroupProperty
  • cApiGroupPropertyCollection
  • cApiInUse
  • cApiInUseCollection
  • cApiIso3166
  • cApiIso3166Collection
  • cApiIso6392
  • cApiIso6392Collection
  • cApiKeyword
  • cApiKeywordCollection
  • cApiLanguage
  • cApiLanguageCollection
  • cApiLayout
  • cApiLayoutCollection
  • cApiMailLog
  • cApiMailLogCollection
  • cApiMailLogSuccess
  • cApiMailLogSuccessCollection
  • cApiMetaTag
  • cApiMetaTagCollection
  • cApiMetaTagVersion
  • cApiMetaTagVersionCollection
  • cApiMetaType
  • cApiMetaTypeCollection
  • cApiModule
  • cApiModuleCollection
  • cApiNavMain
  • cApiNavMainCollection
  • cApiNavSub
  • cApiNavSubCollection
  • cApiOnlineUser
  • cApiOnlineUserCollection
  • cApiPathresolveCache
  • cApiPathresolveCacheCollection
  • cApiProperty
  • cApiPropertyCollection
  • cApiRight
  • cApiRightCollection
  • cApiSearchTracking
  • cApiSearchTrackingCollection
  • cApiStat
  • cApiStatCollection
  • cApiSystemProperty
  • cApiSystemPropertyCollection
  • cApiTemplate
  • cApiTemplateCollection
  • cApiTemplateConfiguration
  • cApiTemplateConfigurationCollection
  • cApiType
  • cApiTypeCollection
  • cApiUpload
  • cApiUploadCollection
  • cApiUploadMeta
  • cApiUploadMetaCollection
  • cApiUser
  • cApiUserCollection
  • cApiUserPasswordRequest
  • cApiUserPasswordRequestCollection
  • cApiUserProperty
  • cApiUserPropertyCollection
  • NoteCollection
  • NoteItem
  • TODOCollection
  • TODOItem
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the frontend user collection and item class.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       GenericDB_Model
  8:  * @author           Murat Purc <murat@purc.de>
  9:  * @copyright        four for business AG <www.4fb.de>
 10:  * @license          http://www.contenido.org/license/LIZENZ.txt
 11:  * @link             http://www.4fb.de
 12:  * @link             http://www.contenido.org
 13:  */
 14: 
 15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 16: 
 17: /**
 18:  * Frontend user collection
 19:  *
 20:  * @package Core
 21:  * @subpackage GenericDB_Model
 22:  */
 23: class cApiFrontendUserCollection extends ItemCollection {
 24: 
 25:     /**
 26:      * Constructor function
 27:      */
 28:     public function __construct() {
 29:         global $cfg;
 30:         parent::__construct($cfg['tab']['frontendusers'], 'idfrontenduser');
 31:         $this->_setItemClass('cApiFrontendUser');
 32: 
 33:         // set the join partners so that joins can be used via link() method
 34:         $this->_setJoinPartner('cApiClientCollection');
 35:     }
 36: 
 37:     /**
 38:      * Checks if a specific user already exists
 39:      *
 40:      * @param string $sUsername
 41:      *         specifies the username to search for
 42:      * @return bool
 43:      */
 44:     public function userExists($sUsername) {
 45:         global $client;
 46: 
 47:         $feUsers = new cApiFrontendUserCollection();
 48:         $feUsers->setWhere('idclient', $client);
 49:         $feUsers->setWhere('username', strtolower($sUsername));
 50:         $feUsers->query();
 51: 
 52:         return ($feUsers->next()) ? true : false;
 53:     }
 54: 
 55:     /**
 56:      * Creates a new user
 57:      *
 58:      * @param string $username
 59:      *         Specifies the username
 60:      * @param string $password [optional]
 61:      *         Specifies the password (optional)
 62:      * @return cApiFrontendUser
 63:      */
 64:     public function create($username, $password = '') {
 65:         global $client, $auth;
 66: 
 67:         // Check if the username already exists
 68:         $this->select("idclient = " . (int) $client . " AND username = '" . $this->escape($username) . "'");
 69: 
 70:         if ($this->next()) {
 71:             return $this->create($username . '_' . substr(md5(rand()), 0, 10), $password);
 72:         }
 73: 
 74:         $item = $this->createNewItem();
 75:         $item->set('idclient', $client);
 76:         $item->set('username', $username);
 77:         $item->set('salt', md5($username . rand(1000, 9999) . rand(1000, 9999) . rand(1000, 9999)));
 78:         $item->set('password', $password);
 79:         $item->set('created', date('Y-m-d H:i:s'), false);
 80:         $item->set('author', $auth->auth['uid']);
 81:         $item->set('active', 0);
 82: 
 83:         $item->store();
 84: 
 85:         // Put this user into the default groups
 86:         $feGroups = new cApiFrontendGroupCollection();
 87:         $feGroups->select("idclient = " . (int) $client . " AND defaultgroup = 1");
 88: 
 89:         $feGroupMembers = new cApiFrontendGroupMemberCollection();
 90: 
 91:         $iduser = $item->get('idfrontenduser');
 92: 
 93:         while (($feGroup = $feGroups->next()) !== false) {
 94:             $idgroup = $feGroup->get('idfrontendgroup');
 95:             $feGroupMembers->create($idgroup, $iduser);
 96:         }
 97: 
 98:         return $item;
 99:     }
100: 
101:     /**
102:      * Overridden delete method to remove user from groupmember table
103:      * before deleting user.
104:      *
105:      * @param int $itemId
106:      *         specifies the frontend user
107:      * @return bool
108:      */
109:     public function delete($itemId) {
110:         // delete group memberships
111:         $feGroupMembers = new cApiFrontendGroupMemberCollection();
112:         $feGroupMembers->select('idfrontenduser = ' . (int) $itemId);
113:         while (($item = $feGroupMembers->next()) !== false) {
114:             $feGroupMembers->delete($item->get('idfrontendgroupmember'));
115:         }
116: 
117:         // delete user
118:         return parent::delete($itemId);
119:     }
120: 
121: }
122: 
123: /**
124:  * Frontend user item
125:  *
126:  * @package Core
127:  * @subpackage GenericDB_Model
128:  */
129: class cApiFrontendUser extends Item {
130: 
131:     /**
132:      * Constructor function
133:      *
134:      * @param mixed $mId [optional]
135:      *         Specifies the ID of item to load
136:      */
137:     public function __construct($mId = false) {
138:         global $cfg;
139:         parent::__construct($cfg['tab']['frontendusers'], 'idfrontenduser');
140:         if ($mId !== false) {
141:             $this->loadByPrimaryKey($mId);
142:         }
143:     }
144: 
145:     /**
146:      * Overridden setField method to md5 the password.
147:      * Sets the value of a specific field.
148:      *
149:      * @param string $field
150:      *         Specifies the field to set
151:      * @param string $value
152:      *         Specifies the value to set
153:      * @param bool $safe [optional]
154:      *         Flag to use defined inFilter
155:      * @return bool
156:      */
157:     public function setField($field, $value, $safe = true) {
158:         if ($field == 'password') {
159:             return parent::setField($field, hash('sha256', md5($value) . $this->get('salt')), $safe);
160:         } else {
161:             return parent::setField($field, $value, $safe);
162:         }
163:     }
164: 
165:     /**
166:      * Sets the password to a raw value without md5 encoding.
167:      *
168:      * @param string $password
169:      *         Raw password
170:      * @return bool
171:      */
172:     public function setRawPassword($password) {
173:         return $this->setField('password', $password);
174:     }
175: 
176:     /**
177:      * Checks if the given password matches the password in the database
178:      *
179:      * @param string $password
180:      *         Password to check
181:      * @return bool
182:      *         True if the password is correct, false otherwise
183:      */
184:     public function checkPassword($password) {
185:         if ($this->isLoaded() === false) {
186:             return false;
187:         }
188: 
189:         $pass = $this->get('password');
190:         $salt = $this->get('salt');
191: 
192:         return hash('sha256', md5($password) . $salt) == $pass;
193:     }
194: 
195:     /**
196:      * Saves modified user entry
197:      *
198:      * @return bool
199:      */
200:     public function store() {
201:         global $auth;
202: 
203:         $this->set('modified', date('Y-m-d H:i:s'), false);
204:         $this->set('modifiedby', $auth->auth['uid']);
205:         return parent::store();
206:     }
207: 
208:     /**
209:      * Returns list of all groups belonging to current user
210:      *
211:      * @return array
212:      *         List of frontend group ids
213:      */
214:     public function getGroupsForUser() {
215:         $feGroupMembers = new cApiFrontendGroupMemberCollection();
216:         $feGroupMembers->setWhere('idfrontenduser', $this->get('idfrontenduser'));
217:         $feGroupMembers->query();
218: 
219:         $groups = array();
220:         while (($feGroupMember = $feGroupMembers->next()) !== false) {
221:             $groups[] = $feGroupMember->get('idfrontendgroup');
222:         }
223:         return $groups;
224:     }
225: 
226: }
227: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0