Exemple #1
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     if (LoginForm::getLoggingWithField() === 'username') {
         $user = User::model()->findByAttributes(array('username' => $this->username));
     } else {
         if (LoginForm::getLoggingWithField() === 'email') {
             $user = User::model()->findByAttributes(array('email' => $this->username));
         } else {
             if (LoginForm::getLoggingWithField() === 'usernameOrEmail') {
                 $user = User::model()->find("`username`=? OR `email`=?", array($this->username, $this->username));
             }
         }
     }
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$user->validatePassword($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->isActive === User::IS_NOT_ACTIVE) {
                 $this->errorCode = self::ERROR_ACCOUNT_IS_INACTIVE;
             } else {
                 if (MArea::isBackend() && $user->accessType !== User::ADMINISTRATOR) {
                     $this->errorCode = self::ERROR_IS_NOT_ADMINISTRATOR;
                     Yii::app()->controller->var->userAccessType = $user->getAttributeView('accessType');
                 } else {
                     $this->_id = $user->id;
                     $this->errorCode = self::ERROR_NONE;
                     // do not store password or other sensitive data in the persistent storage
                     // when (config/main.php) allowAutoLogin is true, because
                     // all these data will be stored in cookie = it is readable
                     $this->setState('email', $user->email);
                     $this->setState('interface', $user->interface);
                     $this->setState('language', $user->language);
                     $this->setState('screenName', $user->screenName);
                     // init rbac
                     $this->authorize($user);
                 }
             }
         }
     }
     return $this->errorCode == self::ERROR_NONE;
 }
Exemple #2
0
 /**
  * Load params from Yii::app()->params into class properties.
  */
 public static function load()
 {
     // initialize core default parameters
     self::$coreDefaultData = array('adminEmailAddress' => '*****@*****.**', 'adminEmailName' => 'Web3CMS Staff', 'availableInterfaces' => array('ui-lightness' => 'UI Lightness', 'ui-darkness' => 'UI Darkness', 'smoothness' => 'Smoothness', 'start' => 'Start', 'redmond' => 'Redmond', 'sunny' => 'Sunny', 'overcast' => 'Overcast', 'le-frog' => 'Le frog', 'flick' => 'Flick', 'pepper-grinder' => 'Pepper grinder', 'eggplant' => 'Eggplant', 'dark-hive' => 'Dark hive', 'cupertino' => 'Cupertino', 'south-street' => 'South street', 'blitzer' => 'Blitzer', 'humanity' => 'Humanity', 'hot-sneaks' => 'Hot sneaks', 'excite-bike' => 'Excite bike', 'vader' => 'Vader', 'dot-luv' => 'Dot luv', 'mint-choc' => 'Mint choc', 'black-tie' => 'Black tie', 'trontastic' => 'Trontastic', 'swanky-purse' => 'Swanky purse'), 'availableLanguages' => array('en' => 'English', 'ru' => 'Russian'), 'copyrightBy' => 'My Company', 'headerTitle' => MArea::isBackend() ? 'Web3CMS Administrator Area' : 'My Web3CMS', 'htmlDoctype' => 'transitional', 'interface' => 'start', 'language' => 'en', 'mainMenuFullWidth' => true, 'metaDescription' => 'Web3CMS - Web 2.0 Content Management System based on Yii Framework.', 'metaKeywords' => array('web3cms', 'yii'), 'pageLabel' => 'Home', 'pageTitleFormula' => '{pageLabel} - {siteTitle}', 'pathToFiles' => dirname(Yii::app()->basePath) . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR, 'registerJqueryUI' => true, 'siteTitle' => MArea::isBackend() ? 'Web3CMS Administrator' : 'Web3CMS', 'systemLanguage' => 'en', 'tablePrefix' => 'w3_', 'urlToFiles' => Yii::app()->request->baseUrl . '/files/', 'userLoginWithField' => 'username');
     // initialize core parameters allowed values
     self::$coreDataAllowedValue = array('htmlDoctype' => array('strict', 'transitional'), 'modelAttributes' => array('User' => array('email2' => false)), 'userLoginWithField' => array('_any_', 'email', 'username'));
     // set data from params.php
     $data = Yii::app()->params;
     $parameters = array('systemLanguage', 'adminEmailAddress', 'adminEmailName', 'availableInterfaces', 'availableLanguages', 'language', 'copyrightBy', 'headerTitle', 'htmlDoctype', 'interface', 'mainMenuFullWidth', 'metaDescription', 'metaKeywords', 'modelAttributes', 'pageTitleFormula', 'pathToFiles', 'registerJqueryUI', 'siteTitle', 'tablePrefix', 'urlToFiles', 'userLoginWithField');
     // our universal setters
     foreach ($parameters as $parameter) {
         $setter = 'set' . ucfirst($parameter);
         if (isset($data[$parameter])) {
             call_user_func(array('self', $setter), $data[$parameter]);
         } else {
             call_user_func(array('self', $setter), self::_default);
             Yii::log(W3::t('system', 'Missing parameter in file params.php: {parameter}.', array('{parameter}' => $parameter)), 'error', 'w3');
         }
     }
     // class is loaded
     self::$isLoaded = true;
 }