示例#1
0
 /**
  * user registration
  */
 public function actionRegister()
 {
     $model = new UserGroupsUser('registration');
     // set the profile extension array
     $profiles = array();
     $profile_list = Yii::app()->controller->module->profile;
     foreach ($profile_list as $p) {
         // create an instance of the profile extension
         $p_instance = new $p('registration');
         // check if the profile extension is supporting registration
         $views = $p_instance->profileViews();
         if (isset($views[UserGroupsUser::REGISTRATION])) {
             $profiles[] = array('view' => $views[UserGroupsUser::REGISTRATION], 'model' => $p_instance);
         }
     }
     if (isset($_POST['UserGroupsUser'])) {
         $model->attributes = $_POST['UserGroupsUser'];
         // set validation for additional fields
         foreach ($profiles as &$p) {
             if (isset($_POST[get_class($p['model'])])) {
                 $p['model']->attributes = $_POST[get_class($p['model'])];
             }
             if (!$p['model']->validate()) {
                 $error = true;
             }
         }
         if ($model->validate() && !isset($error)) {
             if ($model->save()) {
                 // save the related profile extensions
                 foreach ($profiles as $p) {
                     $p['model']->ug_id = $model->id;
                     $p['model']->save();
                 }
                 $this->redirect(Yii::app()->baseUrl . '/userGroups');
             }
         }
     }
     $this->render('register', array('model' => $model, 'profiles' => $profiles));
 }
示例#2
0
 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} пользователей.";
 }
示例#3
0
 public function actionAutoRegister()
 {
     $newUser = $_POST['CommunityForm'];
     $umod = new UserGroupsUser();
     $users = $umod->findAllByAttributes(array(), "email=:email", array(":email" => $newUser['email']));
     if (count($users) == 0) {
         $model = new UserGroupsUser('autoregistration');
         $model->username = $newUser['email'];
         $model->name = $newUser['firstName'];
         $model->last_name = $newUser['lastName'];
         $model->email = $newUser['email'];
         $model->password = $this->randomPassword();
         if ($model->save()) {
             echo $model->primaryKey;
         }
     } else {
         echo $users[0]->id;
     }
 }
示例#4
0
 public function actionAdd()
 {
     $this->pageTitle = Yii::t('titles', 'HOLES_ADD');
     $this->layout = '//layouts/header_blank';
     $model = new Holes();
     $model->USER_ID = Yii::app()->user->id;
     if (isset($_POST['Holes'])) {
         $model->attributes = $_POST['Holes'];
         if ($model->USER_ID === 0 || $model->USER_ID === null) {
             $users = UserGroupsUser::model()->findAllByAttributes(array(), "email=:email", array(":email" => $_POST['Holes']['EMAIL']));
             if (count($users) == 0) {
                 $umodel = new UserGroupsUser('autoregistration');
                 $umodel->username = $_POST['Holes']['EMAIL'];
                 $umodel->name = $_POST['Holes']['FIRST_NAME'];
                 $umodel->last_name = $_POST['Holes']['LAST_NAME'];
                 $umodel->email = $_POST['Holes']['EMAIL'];
                 $umodel->password = $this->randomPassword();
                 if ($umodel->save()) {
                     $model->USER_ID = $umodel->primaryKey;
                 }
             } else {
                 $model->USER_ID = $users[0]->id;
             }
         }
         $model->DATE_CREATED = strtotime($_POST['Holes']['DATE_CREATED']);
         if (!$model->DATE_CREATED) {
             $model->DATE_CREATED = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
         }
         if ($model->DATE_CREATED < time() - 7 * 86400) {
             $model->addError("DATE_CREATED", Yii::t('template', 'DATE_CANT_BE_PAST', array('{attribute}' => $model->getAttributeLabel('DATE_CREATED'))));
         }
         $model->PREMODERATED = Yii::app()->user->level > 50 ? 1 : 0;
         $model->ROAD_TYPE = $_POST['Holes']['ROAD_TYPE'];
         $tran = $model->dbConnection->beginTransaction();
         if ($model->validate(null, false)) {
             if ($model->save() && $model->savePictures()) {
                 $tran->commit();
                 if ($model->PREMODERATED && $model->ROAD_TYPE == 'highway') {
                     $this->sendMailToUkrautodor($model);
                 }
                 $this->redirect(array('view', 'id' => $model->ID));
             }
         }
     } else {
         //выставляем центр на карте по координатам IP юзера
         $request = new CHttpRequest();
         $geoIp = new EGeoIP();
         $geoIp->locate($request->userHostAddress);
         //echo ($request->userHostAddress);
         if ($geoIp->latitude) {
             $model->LATITUDE = $geoIp->latitude;
         } else {
             $model->LATITUDE = Yii::app()->params['latitude'];
         }
         if ($geoIp->longitude) {
             $model->LONGITUDE = $geoIp->longitude;
         } else {
             $model->LONGITUDE = Yii::app()->params['longitude'];
         }
         $model->DATE_CREATED = time();
     }
     $this->render('holeform', array('model' => $model));
 }
示例#5
0
 /**
  * create the root user
  */
 private function createRootUser()
 {
     $user_model = new UserGroupsUser('installation');
     $user_model->id = UserGroupsUser::ROOT;
     $user_model->username = $_POST['UserGroupsInstallation']['root_user'];
     $user_model->password = $_POST['UserGroupsInstallation']['root_password'];
     $user_model->email = $_POST['UserGroupsInstallation']['root_email'];
     $user_model->group_id = UserGroupsUser::ROOT;
     $user_model->status = UserGroupsUser::ACTIVE;
     $user_model->question = $_POST['UserGroupsInstallation']['root_question'];
     $user_model->answer = $_POST['UserGroupsInstallation']['root_answer'];
     $user_model->home = '/userGroups/admin/documentation';
     $user_model->save();
     if ((int) $user_model->id !== UserGroupsUser::ROOT) {
         throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Error during installation. Couldn\'t create root user with id {id}', array('{id}' => UserGroupsUser::ROOT)));
         Yii::app()->end();
     }
 }
 /**
  * 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;
 }
示例#7
0
     $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();
 $test = $poll->findAllByAttributes(array(), "u_id=:u_id", array(":u_id" => $poll_user));
 if (count($test)) {
     $canvote = 0;
 } else {
     $poll->poll = "poll01";
     $poll->u_id = $poll_user;