/** * initialize the singleton */ public static function init() { if (!self::$object) { self::$object = new self(); } return self::$object; }
/** * Authenticates a user. * @return boolean whether authentication succeeds. */ public function authenticate() { $model = UserGroupsUser::model()->findByAttributes(array('username' => $this->username)); if (!count($model)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if ($model->password !== md5($this->password . $model->getSalt())) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } //UGCron::run(); } $model->save(); } } } } } } return !$this->errorCode; }
/** * Authenticates a user. * @return boolean whether authentication succeeds. */ public function authenticate() { $model = UserGroupsUser::model()->findByAttributes(array('username' => $this->username)); //Тупая битриксовская проверка пароля. if ($model && $model->is_bitrix_pass) { if (strlen($model->password) > 32) { $salt = substr($model->password, 0, strlen($model->password) - 32); $db_password = substr($model->password, -32); } else { $salt = ""; $db_password = $model->password; } $user_password = md5($salt . $this->password); //echo $salt.'<br/>'.$user_password.'<br/>'.$db_password; //die(); } elseif ($model && !$model->is_bitrix_pass) { $user_password = md5($this->password . $model->getSalt()); $db_password = $model->password; } if (!count($model)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if (!$this->hash && $user_password !== $db_password || $this->hash && $model->password != $this->hash) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); if (Yii::app()->controller->module) { foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } } UGCron::run(); } $model->save(); } } } } } } return !$this->errorCode; }
/** * remove not installed cronjobs */ private function cronRemove() { // check user permissions if (Yii::app()->user->pbac('userGroups.admin.admin')) { // load the cronjobs UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } // load the cronjobs $crons = UserGroupsCron::model()->findAll(); foreach ($crons as $c) { if (UGCron::getStatus($c->name) === UGCron::NOT_INSTALLED) { $c->delete(); } } Yii::app()->user->setFlash('crons', Yii::t('userGroupsModule.admin', 'Cron Jobs successfully removed')); } else { Yii::app()->user->setFlash('crons', Yii::t('userGroupsModule.admin', 'You are not allowed to remove cron jobs')); } $this->redirect(Yii::app()->baseUrl . '/userGroups/admin'); }
<?php } ?> <div class="hidden-panel"> <?php if (Yii::app()->user->pbac('userGroups.admin.admin')) { $form = $this->beginWidget('CActiveForm', array('id' => 'user-groups-cron-form', 'enableAjaxValidation' => false)); } ?> <?php // load the cronjobs UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } ?> <?php $this->widget('zii.widgets.grid.CGridView', array('dataProvider' => $cronDataProvider, 'id' => 'configuration-list', 'enableSorting' => false, 'summaryText' => false, 'selectableRows' => 0, 'columns' => array('name', array('name' => 'lapse', 'value' => Yii::app()->user->pbac('userGroups.admin.admin') ? 'CHtml::textField("UserGroupsCron[$data->id]", $data->lapse, array("class" => "lapse"))' : '$data->lapse', 'type' => 'raw'), array('name' => 'last_occurrence', 'value' => 'substr($data->last_occurrence,0,strpos($data->last_occurrence," "))'), array('name' => 'status', 'value' => 'UGCron::getStatus($data->name, true, true)', 'type' => 'raw'), array('name' => 'description', 'value' => 'UGCron::getDescriptions($data->name, true);')))); ?> <?php if (Yii::app()->user->pbac('userGroups.admin.admin')) { ?> <div class="inline buttons"> <?php echo CHtml::submitButton(Yii::t('userGroupsModule.general', 'Save')); ?> </div> <?php $this->endWidget();
/** * Authenticates a user based on {@link username}. * This method is required by {@link IUserIdentity}. * @return boolean whether authentication succeeds. */ public function authenticate() { if ($this->service && $this->service->isAuthenticated) { $this->username = $this->service->serviceName . '#' . $this->service->id; $this->setState('name', $this->username); $this->setState('service', $this->service->serviceName); $this->errorCode = self::ERROR_NONE; $model = UserGroupsUser::model()->findByAttributes(array('xml_id' => $this->service->id, 'external_auth_id' => $this->service->getAttribute('external_auth_id') ? $this->service->getAttribute('external_auth_id') : $this->service->serviceName)); if (!$model) { $model = new UserGroupsUser(); $model->username = $this->username; $model->email = $this->service->getAttribute('email'); if (!$model->email && $this->service->serviceName == 'yandex') { $model->email = $this->service->getAttribute('name') . '@yandex.ru'; } $model->name = $this->service->getAttribute('name'); $model->last_name = $this->service->getAttribute('lastname'); $model->group_id = 2; $model->status = 4; $model->params = array_keys($model->ParamsFields); $model->xml_id = $this->service->id; $model->external_auth_id = $this->service->getAttribute('external_auth_id') ? $this->service->getAttribute('external_auth_id') : $this->service->serviceName; $model->save(); } if (!$model) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::WAITING_ACTIVATION) { $this->errorCode = self::ERROR_USER_INACTIVE; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::PASSWORD_CHANGE_REQUEST) { $this->errorCode = self::ERROR_PASSWORD_REQUESTED; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = $model->username; $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home ? $model->home : $model->relUserGroupsGroup->home; $this->recovery = false; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); // run the cronjobs if (UserGroupsConfiguration::findRule('server_executed_crons') === false) { UGCron::init(); UGCron::add(new UGCJGarbageCollection()); UGCron::add(new UGCJUnban()); foreach (Yii::app()->controller->module->crons as $c) { UGCron::add(new $c()); } UGCron::run(); } $model->save(); } } } } } } else { $this->errorCode = self::ERROR_NOT_AUTHENTICATED; } return !$this->errorCode; }