/** * login in recovery mode * @return boolean wheter is possible to login in recovery mode */ public function recovery() { $model = UserGroupsUser::model()->findByAttributes(array('username' => $this->username)); if (!count($model)) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ((int) $model->status === UserGroupsUser::BANNED) { $this->errorCode = self::ERROR_USER_BANNED; } else { if ((int) $model->status === UserGroupsUser::ACTIVE) { $this->errorCode = self::ERROR_USER_ACTIVE; } else { if ((int) $model->status === UserGroupsUser::WAITING_APPROVAL) { $this->errorCode = self::ERROR_USER_APPROVAL; } else { if ($model->activation_code !== $this->password) { $this->errorCode = self::ERROR_ACTIVATION_CODE; } else { $this->errorCode = self::ERROR_NONE; $this->id = $model->id; $this->name = Yii::t('userGroupsModule.general', 'Recovery Mode'); $this->group = $model->group_id; $this->groupName = $model->relUserGroupsGroup->groupname; $this->level = $model->relUserGroupsGroup->level; $this->accessRules = $this->accessRulesComputation($model); $this->home = $model->home; $this->recovery = true; // load profile extension's data $this->profileLoad($model); // update the last login time $model->last_login = date('Y-m-d H:i:s'); $model->save(); } } } } } return !$this->errorCode; }
public function actionImportUsers() { set_time_limit(0); $count = 0; $users = BUser::model()->findAll(); foreach ($users as $user) { $group = BUserGroup::model()->find('USER_ID=' . $user->ID); if ($group && $group->GROUP_ID != 0) { $username = ''; $user->LOGIN = $this->sql_valid($user->LOGIN); $model = UserGroupsUser::model()->find("username='******'"); if ($model) { if ($user->EXTERNAL_AUTH_ID && $user->XML_ID) { $username = $user->LOGIN . '_' . $user->EXTERNAL_AUTH_ID; $username = substr($username, 0, 110); $model = new UserGroupsUser('import'); $model->username = $username; } elseif ($model->external_auth_id && $model->xml_id) { $model->username = $model->username . '_' . $model->xml_id; $model->update(); $model = new UserGroupsUser('import'); } } if (!$model) { $model = new UserGroupsUser('import'); } $group_id = 2; if ($group->GROUP_ID == 1) { $group_id = 5; } if ($group->GROUP_ID == 4) { $group_id = 3; } if ($user->LOGIN == 'admin') { $group_id = 1; } if ($user->EXTERNAL_AUTH_ID && $user->XML_ID) { $user->PASSWORD = ''; } $model->attributes = array('id' => $user->ID, 'group_id' => $group_id, 'username' => $username ? $username : $user->LOGIN, 'password' => $user->PASSWORD, 'email' => trim($user->EMAIL) ? trim($user->EMAIL) : null, 'name' => $user->NAME, 'second_name' => $user->SECOND_NAME, 'last_name' => $user->LAST_NAME, 'home' => '', 'status' => 4, 'creation_date' => $user->DATE_REGISTER, 'activation_code' => null, 'activation_time' => $user->CHECKWORD_TIME, 'last_login' => $user->LAST_LOGIN, 'params' => array_keys($model->ParamsFields), 'xml_id' => $user->XML_ID, 'external_auth_id' => $user->EXTERNAL_AUTH_ID, 'is_bitrix_pass' => 1); $model->id = $user->ID; if ($model->save()) { $count++; if (!$model->relProfile) { $profile = new Profile(); $profile->ug_id = $model->id; $profile->birthday = $user->PERSONAL_BIRTHDAY; $profile->site = $user->PERSONAL_WWW; $profile->save(); } $model->creation_date = $user->DATE_REGISTER; $model->status = 4; $model->update(); } else { echo "Пользователь " . $user->ID . "(" . $user->LOGIN . ")" . " не добавлен из-за : \n"; print_r($model->errors); } } } echo "Добавлено {$count} пользователей."; }
public function getEmail() { return UserGroupsUser::model()->findByPk((int) Yii::app()->user->id)->email; }
public function getUserModel() { if (!$this->_usermodel) { $this->_usermodel = UserGroupsUser::model()->findByPk((int) Yii::app()->user->id); } return $this->_usermodel; }
/** * Returns the data model based on the primary key given in the GET variable. * Optionally sets a scenario * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded * @param string the scenario to apply to the model */ public function loadModel($id, $scenario = false) { $model = UserGroupsUser::model()->findByPk((int) $id); if ($model === null || $model->relUserGroupsGroup->level > Yii::app()->user->level && !UserGroupsConfiguration::findRule('public_profiles')) { throw new CHttpException(404, Yii::t('userGroupsModule.general', 'The requested page does not exist.')); } if ($scenario) { $model->setScenario($scenario); } return $model; }
/** * deletes the item from the database * @param Array $formData */ private function itemDelete($formData) { // check if the user performing the action has the permission to do it if (!Yii::app()->user->pbac('admin')) { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'You don\'t have the permission to delete any user/group')); } else { // check if the user is trying to delete a valid id if (Yii::app()->request->isPostRequest && $formData['id'] !== 'new' && (int) $formData['id'] !== UserGroupsUser::ROOT) { // load the item to delete if ((int) $formData['what'] === UserGroupsAccess::GROUP) { $model = UserGroupsGroup::model()->findByPk((int) $formData['id']); } else { if ((int) $formData['what'] === UserGroupsAccess::USER) { $model = UserGroupsUser::model()->findByPk((int) $formData['id']); } } if ($model) { // check if your level is higher then the user/group you are about to delete if ($model->level < Yii::app()->user->level) { if ($model->delete() && UserGroupsAccess::model()->deleteAll('element = ' . $formData['what'] . ' AND element_id = ' . $formData['id'])) { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', '{what} deleted.', array('{what}' => ucfirst($formData['displayname'])))); } else { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'Impossible to delete the requested user/group. An Error Occurred')); } } else { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'You cannot delete a user/group with a higher level then yours.')); } } else { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'The requested user/group does not exist and cannot be deleted.')); } } else { Yii::app()->user->setFlash((int) $formData['what'] === UserGroupsAccess::USER ? 'user' : 'group', Yii::t('userGroupsModule.admin', 'Invalid Request.')); } } $this->redirect(Yii::app()->baseUrl . '/userGroups/admin'); }
public function actionPersonalDelete($id) { $model = $this->loadChangeModel($id); $currentUser = UserGroupsUser::model()->findByPk(Yii::app()->user->id); if ($currentUser && ($currentUser->id == $model->user->id || $currentUser->level > 1)) { $model->delete(); } else { throw new CHttpException(403, 'Доступ запрещен.'); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_POST['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('personal')); } }
/** * 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; }
public function actionDelete() { if (Yii::app()->request->isPostRequest && (isset($_POST['id']) || isset($_POST['DELETE_ALL']) && $_POST['DELETE_ALL'])) { if (!isset($_POST['DELETE_ALL'])) { $id = $_POST['id']; // we only allow deletion via POST request $model = $this->loadModel($id); if (isset($_POST['banuser']) && $_POST['banuser']) { $reason = "Забанен"; $period = 100000; $usermodel = UserGroupsUser::model()->findByPk($model->USER_ID); $usermodel->setScenario('ban'); // check if you are trying to ban a user with an higher level if ($usermodel->relUserGroupsGroup->level >= Yii::app()->user->level) { Yii::app()->user->setFlash('user', 'Вы не можете банить пользователей с уровнем выше или равным вашему.'); } else { $usermodel->ban = date('Y-m-d H:i:s', time() + $period * 86400); $usermodel->ban_reason = $reason; $usermodel->status = UserGroupsUser::BANNED; if ($usermodel->update()) { Yii::app()->user->setFlash('user', '{$usermodel->username}\\ акаунт забанен до {$usermodel->ban}.'); } else { Yii::app()->user->setFlash('user', 'Произошла ошибка попробуйте немного позднее'); } } } $model->delete(); } else { $holes = Holes::model()->findAll('id IN (' . $_POST['DELETE_ALL'] . ')'); $ok = 0; foreach ($holes as $model) { if ($model->delete()) { $ok++; } } if ($ok == count($holes)) { echo 'ok'; } } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect($_SERVER['HTTP_REFERER']); } } elseif (Yii::app()->user->groupName == 'root') { $model = Holes::model()->findByPk((int) $_GET['id']); if ($model) { $model->delete(); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
public function actionNotSentEmails() { ini_set('memory_limit', '1024M'); set_time_limit(0); $users = UserGroupsUser::model()->findAll(array('select' => 't.email', 'join' => 'INNER JOIN {{holes}} holes ON (t.id=holes.USER_ID)', 'condition' => 'holes.STATE="fresh"', 'group' => 't.email')); foreach ($users as $user) { echo $user->email . '<br />'; } }
<?php $canvote = 1; if (count($_POST)) { $data = $_POST; if (Yii::app()->user->id) { $poll_user = Yii::app()->user->id; } else { //autoreg $users = UserGroupsUser::model()->findAllByAttributes(array(), "email=:email", array(":email" => trim($data['email']))); if (count($users) == 0) { $umodel = new UserGroupsUser('autoregistration'); $umodel->username = trim($data['email']); $umodel->name = $data['first_name']; $umodel->email = trim($data['email']); $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; for ($i = 0; $i < 8; $i++) { $n = rand(0, count($alphabet) - 1); $pass[$i] = $alphabet[$n]; } $umodel->password = $pass; if ($umodel->save()) { $poll_user = $umodel->primaryKey; } } else { $poll_user = $users[0]->id; } } $vote = var_export($data, true); // file_put_contents(Yii::getPathOfAlias('webroot')."/upload/poll01.log",$a,FILE_APPEND); $poll = new Poll();
,<?php echo $hole->LONGITUDE; ?> &sensor=false"><br> </div> <?php } ?> <div class="info"> <div> <span class="date"><?php echo CHtml::encode(Y::dateFromTime($hole->DATE_CREATED)); ?> </span> <?php $userGroup = UserGroupsUser::model()->findByPk(Yii::app()->user->id); if (isset($userGroup->level) && $userGroup->level > 1) { ?> <div class="edit-container"> <?php if (Yii::app()->user->isModer && !$hole->PREMODERATED) { echo CHtml::link("Подтвердить", array('moderate', 'id' => $hole->ID)) . " "; } if ($hole->STATE == Holes::STATE_FRESH) { echo CHtml::link(Yii::t('holes_view', 'EDIT'), array('update', 'id' => $hole->ID)); } echo CHtml::link(Yii::t('holes_view', 'DELETE'), array('personalDelete', 'id' => $hole->ID), array('onclick' => 'return confirm("' . Yii::t('holes_view', 'DELETE_DEFECT_CONFIRM') . '");', 'class' => 'delete')); ?> </div> <?php }
public function loadUserModel($id) { $model = UserGroupsUser::model()->findByPk((int) $id); if ($model === null) { $this->error('NOT_FOUND'); } return $model; }
<br/> <?php //echo CHtml::link('Напечатать заявление на '.Y::declOfNum(count($gibdd->holes),Array('яму','ямы','ям')), Array('requestForm','id'=>$gibdd->id,'type'=>'gibdd','holes'=>implode(',',CHtml::listData($gibdd->holes,'ID','ID'))), Array('class'=>'show_form')); echo CHtml::link('Сохранить список ' . Y::declOfNum(count($gibdd->holes), array('яму', 'ямы', 'ям')), array('/profile/saveHoles2Selected', 'id' => $gibdd->id, 'holes' => implode(',', CHtml::listData($gibdd->holes, 'ID', 'ID'))), array('class' => 'save_selected')); ?> <br/><br/> <?php } ?> <br/><?php echo CHtml::link('Очистить список', '#', array('class' => 'clear_selected')); ?> <br/><br/> <?php } $sel = UserGroupsUser::model()->with(array('holes' => array('with' => array('request_gibdd' => array('with' => 'answers')))))->findByPk($user->id); if ($sel && $sel->selected_holes_lists) { ?> <h2>Сохраненные:</h2> <?php foreach ($sel->selected_holes_lists as $list) { ?> <?php echo Y::dateFromTimeShort($list->date_created); ?> <?php echo CHtml::link('удалить', array('/profile/delHolesSelectList', 'id' => $list->id), array('class' => 'save_selected')); ?> <br/> <?php echo CHtml::link('Заявление', array('requestForm', 'id' => $list->gibdd_id, 'type' => 'gibdd', 'holes' => implode(',', CHtml::listData($list->holes, 'ID', 'ID'))), array('class' => 'show_form'));