/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $transaction = Yii::app()->db->beginTransaction(); try { $model = new User(); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->password = crypt(Sysparam::model()->findByPk(AppConstants::RESET_PASSWORD_DEFAULT)->value); if ($model->save()) { $authAssign = new AuthAssignment(); $authAssign->itemname = $model->role; $authAssign->userid = $model->nick; $authAssign->save(); $fsu = new FileSystemUtil(); $fsu->createUserTmpFoderIfNotExists($model->nick); $this->audit->logAudit(Yii::app()->user->id, new DateTime(), AppConstants::AUDIT_OBJECT_USER, AppConstants::AUDIT_OPERATION_NEW, $model->nick); $this->render('/site/successfullOperation', array('header' => 'Usuario creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de usuarios', 'returnUrl' => Yii::app()->createUrl('user/admin'), 'viewUrl' => Yii::app()->createUrl("user/view", array("id" => $model->nick)))); $transaction->commit(); return; } else { $transaction->rollback(); } } $this->render('create', array('model' => $model)); } catch (Exception $exc) { Yii::log($exc->getMessage(), DBLog::LOG_LEVEL_ERROR); $transaction->rollback(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new EmployeeTransaction(); $info = new EmployeeInfo(); $user = new User(); $photo = new EmployeePhotos(); $address = new EmployeeAddress(); $lang = new LanguagesKnown(); $auth_assign = new AuthAssignment(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($info, $model, $user)); if (!empty($_POST['EmployeeTransaction']) || !empty($_POST['EmployeeInfo'])) { $model->attributes = $_POST['EmployeeTransaction']; $info->attributes = $_POST['EmployeeInfo']; $user->attributes = $_POST['User']; $doa = $info->employee_joining_date; $dateofadmission = date("Y-m-d", strtotime($doa)); $info->employee_joining_date = $dateofadmission; /** fix the attendece id card length */ $cardid_length = strlen((string) $info->employee_attendance_card_id); $cardid = $info->employee_attendance_card_id; $digit = 0; $diff = 10 - $cardid_length; for ($i = 1; $i <= $diff; $i++) { $cardid = $digit . $cardid; } $info->employee_attendance_card_id = $cardid; $info->employee_private_email = strtolower($user->user_organization_email_id); $info->employee_created_by = Yii::app()->user->id; $info->employee_creation_date = new CDbExpression('NOW()'); $user->user_organization_email_id = $info->employee_private_email; $user->user_password = md5($info->employee_private_email . $info->employee_private_email); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); //$user->user_organization_id = Yii::app()->user->getState('org_id'); $user->user_type = "employee"; if ($info->save(false)) { $user->save(false); $address->save(false); $lang->save(false); $photo->employee_photos_path = "no-images"; $photo->save(false); } $model->employee_transaction_employee_id = $info->employee_id; $model->employee_transaction_user_id = $user->user_id; $model->employee_transaction_emp_photos_id = $photo->employee_photos_id; $model->employee_transaction_emp_address_id = $address->employee_address_id; $model->employee_transaction_languages_known_id = $lang->languages_known_id; $model->employee_transaction_organization_id = Yii::app()->user->getState('org_id'); $model->employee_status = 0; $model->save(false); // not false because it hasn't been validated $auth_assign->itemname = 'Employee'; $auth_assign->userid = $user->user_id; $auth_assign->save(); $this->redirect(array('update', 'id' => $model->employee_transaction_id)); } else { $this->render('create', array('model' => $model, 'info' => $info, 'user' => $user)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Registration(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Registration'])) { $model->attributes = $_POST['Registration']; if ($model->save()) { $user = new User(); $auth_assign = new AuthAssignment(); $user->user_organization_email_id = $model->email; $my_string = $this->rand_string(7); $user->user_password = md5($my_string . $my_string); $user->user_type = 'admin'; $user->user_created_by = 1; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = 1; if ($user->save()) { $auth_assign->itemname = 'SuperAdmin'; $auth_assign->userid = $user->user_id; $auth_assign->save(false); $request_url = 'http://www.rudrasoftech.com/register-script.php?first_name=' . $model->first_name . '&last_name=' . $model->last_name . '&email=' . $model->email . '&country_code=' . $model->country_code . '&mobile=' . $model->mobile . '&pass='******'site/createOrg')); } } $this->render('create', array('model' => $model)); }
public function authenticate($uloginModel = null, $role = 'Customer') { $criteria = new CDbCriteria(); $criteria->condition = 'identity=:identity AND network=:network'; $criteria->params = array(':identity' => $uloginModel->identity, ':network' => $uloginModel->network); $user = User::model()->find($criteria); if (null == $user) { $criteria = new CDbCriteria(); $criteria->condition = 'email=:email'; $criteria->params = array(':email' => $uloginModel->email); $user = User::model()->find($criteria); if (null == $user) { $user = new User(); } $user->scenario = 'social_network'; $user->identity = $uloginModel->identity; $user->network = $uloginModel->network; $user->email = $uloginModel->email; $user->full_name = $uloginModel->full_name; $user->status = 1; $user->save(); $AuthAssignment = new AuthAssignment(); $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $user->id); $AuthAssignment->save(); } $this->id = $user->id; $this->name = $user->full_name; $this->isAuthenticated = true; return true; }
public static function updateUserRole($user_id, $role) { $assignment = AuthAssignment::model()->findByAttributes(array('userid' => $user_id)); if (!$assignment) { $assignment = new AuthAssignment(); $assignment->userid = $user_id; } $assignment->itemname = $role; $assignment->save(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new StudentTransaction(); $info = new StudentInfo(); $user = new User(); $photo = new StudentPhotos(); $address = new StudentAddress(); $lang = new LanguagesKnown(); $auth_assign = new AuthAssignment(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($info, $model, $user)); if (!empty($_POST['StudentTransaction']) || !empty($_POST['StudentInfo'])) { //print_r($_POST['StudentTransaction']); exit; $model->attributes = $_POST['StudentTransaction']; $info->attributes = $_POST['StudentInfo']; $user->attributes = $_POST['User']; $info->student_created_by = Yii::app()->user->id; $info->student_creation_date = new CDbExpression('NOW()'); $info->student_email_id_1 = strtolower($user->user_organization_email_id); $info->student_adm_date = date('Y-m-d', strtotime($_POST['StudentInfo']['student_adm_date'])); $user->user_organization_email_id = strtolower($info->student_email_id_1); $user->user_password = md5($info->student_email_id_1 . $info->student_email_id_1); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = Yii::app()->user->getState('org_id'); $user->user_type = "student"; if ($info->save(false)) { $user->save(false); $address->save(false); $lang->save(false); $photo->student_photos_path = "no-images"; $photo->save(); } if (empty($model->student_transaction_batch_id)) { $model->student_transaction_batch_id = 0; } $model->student_transaction_languages_known_id = $lang->languages_known_id; $model->student_transaction_student_id = $info->student_id; $model->student_transaction_user_id = $user->user_id; $model->student_transaction_student_address_id = $address->student_address_id; $model->student_transaction_student_photos_id = $photo->student_photos_id; $model->student_transaction_organization_id = Yii::app()->user->getState('org_id'); $model->save(); $auth_assign->itemname = 'Student'; $auth_assign->userid = $user->user_id; $auth_assign->save(); StudentInfo::model()->updateByPk($model->student_transaction_student_id, array('student_info_transaction_id' => $model->student_transaction_id)); $this->redirect(array('admin')); } else { $this->render('create', array('model' => $model, 'info' => $info, 'user' => $user)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new AuthAssignment(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AuthAssignment'])) { $model->attributes = $_POST['AuthAssignment']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); if (isset($_GET['role']) && $_GET['role'] == 'Customer') { $role = 'Customer'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') { $role = 'Author'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') { $role = 'Manager'; } else { $role = 'Customer'; } if (isset($_POST['ajax']) && $_POST['ajax'] === 'simple-registration-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; if ($model->validate()) { $soucePassword = $this->generate_password(8); $model->password = UserModule::encrypting($soucePassword); $model->superuser = 0; $model->status = 1; $model->username = $model->email; if ($model->save()) { $AuthAssignment = new AuthAssignment(); $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id); $AuthAssignment->save(); $login_url = '<a href="' . $this->createAbsoluteUrl('/user/login') . '">' . Yii::app()->name . '</a>'; UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}", array('{login_url}' => $login_url, '{pass}' => $soucePassword))); $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); //$this->redirect(Yii::app()->controller->module->returnUrl); Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{login}}) before start.", ['{{login}}' => $model->email])); $this->refresh(); } else { Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :(")); $this->refresh(); } } } Yii::app()->theme = 'client'; $this->render('/user/registration', array('model' => $model, 'role' => $role)); } }
public function actionCreateOrg() { $org = Organization::model()->count(); if ($org == 0) { $this->layout = 'installation_layout'; $model = new Organization(); $user = new User(); $auth_assign = new AuthAssignment(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Organization']['organization_name']) && !empty($_POST['Organization']['phone']) && !empty($_POST['Organization']['email'])) { $country_model = new Country(); $country_model->name = $_POST['Organization']['country']; $country_model->save(); $state_model = new State(); $state_model->state_name = $_POST['Organization']['state']; $state_model->country_id = $country_model->id; $state_model->save(); $city_model = new City(); $city_model->city_name = $_POST['Organization']['city']; $city_model->country_id = $country_model->id; $city_model->state_id = $state_model->state_id; $city_model->save(); $model->attributes = $_POST['Organization']; $model->organization_created_by = 1; $model->organization_creation_date = new CDbExpression('NOW()'); $model->city = $city_model->city_id; $model->state = $state_model->state_id; $model->country = $country_model->id; if ($model->save(false)) { $user->user_organization_email_id = $model->email; $user->user_password = md5($model->email . $model->email); $user->user_type = 'admin'; $user->user_created_by = 1; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = $model->organization_id; $user->save(); $auth_assign->itemname = 'SuperAdmin'; $auth_assign->userid = $user->user_id; $auth_assign->save(false); $this->redirect(array('redirectLogin')); } } $this->render('create_org', array('model' => $model)); } else { Yii::app()->user->logout(); $this->redirect(array('login')); } }
public function createUser(RegistrationForm $form) { $transaction = Yii::app()->getDb()->beginTransaction(); try { $user = new User(); $password = rand(1000000, 9999999); $Company = new Company(); if ($form->organization_name) { $Company->name = $form->organization_name; } $Company->create = new CDbExpression('NOW()'); $Company->save(); $user->email = $form->email; $user->contact_phone = $form->phone; $user->contact_phone_prefix = $form->prefphone; $user->company_id = $Company->id; $user->status = User::STATUS_ACTIVE; //Сделать автопроверку выписки $user->setAttribute('hash', $this->hasher->hashPassword($password)); if ($user->save() && ($token = $this->tokenStorage->createAccountActivationToken($user)) !== false) { $user->sendCRMRegistration(); User::savePost($user); \Yii::import('application.modules.rbac.models.*'); $model = new AuthAssignment(); //$model->setAttributes(['userid' => $user->id,'itemname' => 'standart']); //Назаначаем роль владельца компании без инн // $model->setAttributes(['userid' => $user->id,'itemname' => 'own_wo_inn']); //Назаначаем роль владельца компании без инн $model->setAttributes(['userid' => $user->id, 'itemname' => 'owner']); //Назаначаем роль владельца компании без инн if (!$model->save()) { throw new CDbException(Yii::t('UserModule.rbac', 'There is an error occurred when saving data!')); } Yii::app()->eventManager->fire(UserEvents::SUCCESS_REGISTRATION, new UserRegistrationEvent($form, $user, $token, $password)); Yii::log(Yii::t('UserModule.user', 'Account {nick_name} was created', ['{nick_name}' => $user->email]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->commit(); $LoginForm = new LoginForm(); $LoginForm->email = $user->email; $LoginForm->password = $password; Yii::app()->authenticationManager->login($LoginForm, Yii::app()->getUser(), Yii::app()->getRequest()); return $user; } throw new CException(Yii::t('UserModule.user', 'Error creating account!')); } catch (Exception $e) { Yii::log(Yii::t('UserModule.user', 'Error {error} account creating!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->rollback(); Yii::app()->eventManager->fire(UserEvents::FAILURE_REGISTRATION, new UserRegistrationEvent($form, $user)); return false; } }
public function safeUp() { /* Всем администраторам назначается роль admin */ $adminRole = new AuthItem(); $adminRole->name = AuthItem::ROLE_ADMIN; $adminRole->description = Yii::t('RbacModule.rbac', 'Admin'); $adminRole->type = AuthItem::TYPE_ROLE; $adminRole->save(); $admins = User::model()->findAllByAttributes(['access_level' => User::ACCESS_LEVEL_ADMIN]); foreach ($admins as $admin) { $assign = new AuthAssignment(); $assign->itemname = $adminRole->name; $assign->userid = $admin->id; $assign->save(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->password = crypt(Sysparam::model()->findByPk(Constants::PARAMETRO_CONTRASENIA_REINICIO)->value); if ($model->save()) { $authAssign = new AuthAssignment(); $authAssign->itemname = $model->role; $authAssign->userid = $model->nick; $authAssign->save(); $fsu = new FileSystemUtil(); $fsu->createUserTmpFoderIfNotExists($model->nick); $this->audit->logAudit(Yii::app()->user->id, new DateTime(), Constants::AUDITORIA_OBJETO_USUARIO, Constants::AUDITORIA_OPERACION_ALTA, $model->nick); $this->render('/site/successfullOperation', array('header' => 'Usuario creado con éxito', 'message' => 'Haga click en volver para regresar a la gestión de usuarios', 'returnUrl' => Yii::app()->createUrl('user/admin'), 'viewUrl' => Yii::app()->createUrl("user/view", array("id" => $model->nick)))); return; } } $this->render('create', array('model' => $model)); }
public function actionManage() { $item = $this->getItem(); $assigned = $this->getAssigned($item->name); $model = new AuthAssignment(); if (isset($_POST['delete_AuthAssignment'])) { foreach ($_POST['AuthAssignment'] as $delete) { if ($delete['_delete']) { $model->deleteAll('userid=:userid', array(':userid' => $delete['userid'])); } } $this->redirect(array('view', 'name' => $item->name)); } elseif (isset($_POST['AuthAssignment'])) { $model->attributes = $_POST['AuthAssignment']; $model->itemname = $item->name; if ($model->save()) { $this->redirect(array('view', 'name' => $item->name)); } } $this->render('manage', array('model' => $model, 'item' => $item, 'assigned' => $assigned)); }
public function actionCreate() { $model = new User(); $model->scenario = 'Create'; $form = new Form('users.UserForm', $model); unset($form->elements['captcha']); $this->performAjaxValidation($model); if ($form->submitted('submit')) { $model = $form->model; if ($model->validate()) { $model->password = md5($model->password); $model->save(false); $assignment = new AuthAssignment(); $assignment->itemname = $_POST['User']['role']; $assignment->userid = $model->id; $assignment->save(); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('form' => $form)); }
public function actionAssign($id = null) { $user = User::model()->findByPk((int) $id); if (!$user) { $this->redirect(['userList']); } if (Yii::app()->getRequest()->isPostRequest) { /* получение названий ролей, которые есть в базе */ $existingRoles = Yii::app()->db->createCommand('SELECT name FROM {{user_user_auth_item}}')->queryColumn(); $transaction = Yii::app()->db->beginTransaction(); try { AuthAssignment::model()->deleteAll('userid = :userid', [':userid' => (int) $user->id]); // убираем дубликаты и несуществующие роли $roles = array_intersect(array_unique((array) Yii::app()->getRequest()->getPost('AuthItem')), $existingRoles); foreach ($roles as $op) { $model = new AuthAssignment(); $model->setAttributes(['userid' => $user->id, 'itemname' => $op]); if (!$model->save()) { throw new CDbException(Yii::t('RbacModule.rbac', 'There is an error occurred when saving data!')); } } $transaction->commit(); Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('RbacModule.rbac', 'Data was updated!')); /*сброс кэша меню*/ Yii::app()->getCache()->delete('YAdminPanel::' . $id . '::' . Yii::app()->getLanguage()); /*сброс кеша прав*/ Yii::app()->getCache()->delete(Yii::app()->getUser()->rbacCacheNameSpace . $id); $this->redirect(['assign', 'id' => $user->id]); } catch (Exception $e) { Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, $e->getMessage()); $transaction->rollback(); } } $rbacTree = new RbacTree($user); $tree = $rbacTree->getTreeRoles(); $this->render('assign', ['tree' => $tree, 'model' => $user]); }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); if (isset($_GET['role']) && $_GET['role'] == 'Customer') { $role = 'Customer'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') { $role = 'Author'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') { $role = 'Manager'; } else { $role = 'Customer'; } if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; if ($model->validate()) { $soucePassword = $this->generate_password(8); $model->password = UserModule::encrypting($soucePassword); $model->superuser = 0; $model->status = 1; $model->username = $model->email; if ($model->save()) { $AuthAssignment = new AuthAssignment(); $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id); $AuthAssignment->save(); //$login_url = '<a href="'.$this->createAbsoluteUrl('/user/login').'">'.Yii::app()->name.'</a>'; //UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}",array('{login_url}'=>$login_url, '{pass}'=>$soucePassword))); // новая служба системных сообщений $type_id = Emails::TYPE_11; $email = new Emails(); $criteria = new CDbCriteria(); $criteria->order = 'id DESC'; $criteria->limit = 1; $user = User::model()->findAll($criteria); $user = $user[0]; $email->from_id = 1; $email->to_id = $user->id; $rec = Templates::model()->findAll("`type_id`='{$type_id}'"); $title = $rec[0]->title; $body = $rec[0]->text; $id = Campaign::getId(); $email->campaign = Campaign::getName(); $email->name = $model->full_name; $email->login = $model->username; $email->password = $soucePassword; $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit'; $email->sendTo($user->email, $body, $type_id); $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); //$this->redirect(Yii::app()->controller->module->returnUrl); Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{email}}) before start.", ['{{email}}' => $model->email])); $this->refresh(); //Yii::app()->end(); } else { Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :(")); $this->refresh(); } } } Yii::app()->theme = 'client'; $this->render('/user/registration', array('model' => $model, 'role' => $role)); } }
/** * Сохранение данных и отправка письма для подтверждение email */ private function saveDataAndSendEmail($user, $form) { $transaction = Yii::app()->getDb()->beginTransaction(); try { $password = rand(1000000, 9999999); $user->email = $form->email; $user->contact_phone = $form->phone; $user->contact_phone_prefix = $form->prefphone; $user->old_contact_phone = $form->oldphone; $user->create_time = date('Y-m-d H:i:s'); $user->setAttribute('hash', Yii::app()->userManager->hasher->hashPassword($password)); //if ($user->save() && ($token = Yii::app()->userManager->tokenStorage->createAccountActivationToken($user)) !== false) { if ($user->save()) { $token = Yii::app()->userManager->tokenStorage->createAccountActivationToken($user); $user->sendCRMRegistration(); User::savePost($user); \Yii::import('application.modules.rbac.models.*'); $model = new AuthAssignment(); $model->setAttributes(['userid' => $user->id, 'itemname' => 'owner']); //Назаначаем роль владельца компании if (!$model->save()) { throw new CDbException(Yii::t('UserModule.rbac', 'There is an error occurred when saving data!')); } Yii::app()->eventManager->fire(UserEvents::SUCCESS_ACTIVATION, new UserActivationEvent($form, $user, $token, $password)); Yii::log(Yii::t('UserModule.user', 'Guest Account {nick_name} was registred', ['{nick_name}' => $user->email]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->commit(); $LoginForm = new LoginForm(); $LoginForm->email = $user->email; $LoginForm->password = $password; Yii::app()->authenticationManager->login($LoginForm, Yii::app()->getUser(), Yii::app()->getRequest()); return $user; } throw new CException(Yii::t('UserModule.user', 'Error registr account!')); } catch (Exception $e) { Yii::log(Yii::t('UserModule.user', 'Error {error} account registr!', ['{error}' => $e->__toString()]), CLogger::LEVEL_INFO, UserModule::$logCategory); $transaction->rollback(); Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATION, new UserActivationEvent($form, $user)); return false; } }
public function actionAprove($id) { $model= StudentRegistrationInfo::model()->findByPk($id); $info = new StudentInfo; $stud_trans = new StudentTransaction; $user =new User; $photo =new StudentPhotos; $address=new StudentAddress; $lang=new LanguagesKnown; $ass_comp = new assignCompanyUserTable; $auth_assign = new AuthAssignment; $qualification=new StudentAcademicRecordTrans; if(isset($_REQUEST['StudentRegistrationInfo'])) { $org_id = $model->organization_id; if($model->student_status==1){ $acd = Yii::app()->db->createCommand() ->select("academic_term_id,academic_term_name,academic_term_period_id") ->from('academic_term') ->where('current_sem=1 and academic_term_name =1 and academic_term_organization_id='.$org_id) ->queryAll(); if(!$acd){ Yii::app()->user->setFlash('notice','Semester-1 is not an Active semester'); $this->redirect(array('admin')); } $info->student_dtod_regular_status = 'Regular'; } elseif($model->student_status==2){ $acd = Yii::app()->db->createCommand() ->select("academic_term_id,academic_term_name,academic_term_period_id") ->from('academic_term') ->where('current_sem=1 and academic_term_name =3 and academic_term_organization_id='.$org_id) ->queryAll(); if(!$acd){ Yii::app()->user->setFlash('notice','Semester-3 is not an Active semester'); $this->redirect(array('admin')); } $info->student_dtod_regular_status = 'DTOD'; } $info->title = $model->student_title; $info->student_merit_no = $model->student_merit_no; $info->student_first_name = $model->student_first_name; $info->student_middle_name =$model->student_middle_name; $info->student_last_name = $model->student_last_name; $info->student_father_name = $model->student_father_name; $info->student_mother_name = $model->student_mother_name; $info->student_dob = $model->student_dob; $info->student_adm_date = new CDbExpression('NOW()'); $info->student_birthplace = $model->student_place_of_birth; $info->student_gender = $model->student_gender; $info->student_email_id_1 = $model->student_email_id; $info->student_mobile_no = $model->student_mobile; $info->student_created_by = Yii::app()->user->id; $info->student_creation_date = new CDbExpression('NOW()'); $user->user_organization_email_id = strtolower($info->student_email_id_1); $user->user_password = md5($info->student_email_id_1.$info->student_email_id_1); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = $org_id; $user->user_type = "student"; $photo->student_photos_path = $model->student_photo; $address->student_address_c_line1 = $model->student_address_c_line1; $address->student_address_c_line2 = $model->student_address_c_line2; $address->student_address_c_taluka = $model->student_address_c_taluka; $address->student_address_c_district = $model->student_address_c_district; $address->student_address_c_country = $model->student_address_c_country; $address->student_address_c_city = $model->student_address_c_city; $address->student_address_c_pin = $model->student_address_c_pin ; $address->student_address_c_state = $model->student_address_c_state; $address->student_address_p_line1 = $model->student_address_p_line1; $address->student_address_p_line2 = $model->student_address_p_line2; $address->student_address_p_taluka = $model->student_address_p_taluka; $address->student_address_p_district = $model->student_address_p_district; $address->student_address_p_country = $model->student_address_p_country; $address->student_address_p_city = $model->student_address_p_city; $address->student_address_p_pin = $model->student_address_p_pin ; $address->student_address_p_state = $model->student_address_p_state; $address->student_address_phone = $model->student_phoneno; $address->student_address_mobile = $model->student_mobile; if($info->save(false)){ $user->save(false); $photo->save(false); $address->save(false); $lang->save(false); $stud_trans->student_transaction_user_id = $user->user_id; $stud_trans->student_transaction_student_id = $info->student_id; //$stud_trans->student_transaction_branch_id = $model->student_branch_id; if(!empty($model->student_category_id)) $stud_trans->student_transaction_category_id = $model->student_category_id; $stud_trans->student_transaction_organization_id = $org_id; $stud_trans->student_transaction_student_address_id = $address->student_address_id; $stud_trans->student_transaction_languages_known_id= $lang->languages_known_id; $stud_trans->student_transaction_detain_student_flag='5'; $stud_trans->student_transaction_student_photos_id = $photo->student_photos_id; $stud_trans->student_transaction_branch_id=$_POST['StudentRegistrationInfo']['student_branch_id']; $stud_trans->student_academic_term_period_tran_id = $acd[0]['academic_term_period_id']; $stud_trans->student_academic_term_name_id = $acd[0]['academic_term_id']; $stud_trans->save(false); StudentInfo::model()->updateByPk($stud_trans->student_transaction_student_id, array('student_info_transaction_id'=>$stud_trans->student_transaction_id)); $org_data = Organization::model()->findByPk($org_id); $org_name = $org_data->organization_name; $org_arr = explode(' ',$org_name); $suffix_lab = ''; foreach($org_arr as $list) $suffix_lab .= $list[0]; $bizrule = 'return Yii::app()->user->getState("org_id")=='.$org_id.";"; $var_data = serialize(Yii::app()->user->getState('org_id')); $auth_assign->itemname = 'Student of '.$suffix_lab; $auth_assign->userid = $user->user_id; $auth_assign->bizrule = $bizrule; $auth_assign->data = $var_data; $auth_assign->save(); $ass_comp->assign_user_id = $user->user_id; $ass_comp->assign_org_id = $org_id; $ass_comp->assign_created_by = Yii::app()->user->id; $ass_comp->assign_creation_date = new CDbExpression('NOW()'); $ass_comp->save(); StudentRegistrationInfo::model()->updateByPk($id, array( 'student_aproved'=>'1', )); $this->redirect(array('admin')); } } $this->render('aprove',array('model'=>$model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new StudentTransaction(); $info = new StudentInfo(); $user = new User(); $photo = new StudentPhotos(); $address = new StudentAddress(); $lang = new LanguagesKnown(); $auth_assign = new AuthAssignment(); $student_fees_master = new StudentFeesMaster(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($info, $model, $user)); if (!empty($_POST['StudentTransaction']) || !empty($_POST['StudentInfo'])) { //print_r($_POST['StudentTransaction']); exit; $model->attributes = $_POST['StudentTransaction']; $info->attributes = $_POST['StudentInfo']; $user->attributes = $_POST['User']; $info->student_created_by = Yii::app()->user->id; $info->student_creation_date = new CDbExpression('NOW()'); $info->student_email_id_1 = strtolower($user->user_organization_email_id); $info->student_adm_date = date('Y-m-d', strtotime($_POST['StudentInfo']['student_adm_date'])); $user->user_organization_email_id = strtolower($info->student_email_id_1); $user->user_password = md5($info->student_email_id_1 . $info->student_email_id_1); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = Yii::app()->user->getState('org_id'); $user->user_type = "student"; if ($info->save(false)) { $user->save(false); $address->save(false); $lang->save(false); $photo->student_photos_path = "no-images"; $photo->save(); } if (empty($model->student_transaction_batch_id)) { $model->student_transaction_batch_id = 0; } $model->student_transaction_languages_known_id = $lang->languages_known_id; $model->student_transaction_student_id = $info->student_id; $model->student_transaction_user_id = $user->user_id; $model->student_transaction_student_address_id = $address->student_address_id; $model->student_transaction_student_photos_id = $photo->student_photos_id; $model->student_transaction_organization_id = Yii::app()->user->getState('org_id'); $flag = Studentstatusmaster::model()->findByAttributes(array('status_name' => 'Regular'))->id; $model->student_transaction_detain_student_flag = $flag; $model->save(); //Fees Assignment to a student=========== By Ravi Bhalodiya========================================================= $fees_data = FeesMaster::model()->findByAttributes(array('fees_branch_id' => $model->student_transaction_branch_id, 'fees_academic_term_id' => $model->student_academic_term_period_tran_id, 'fees_academic_term_name_id' => $model->student_academic_term_name_id, 'fees_quota_id' => $model->student_transaction_quota_id)); if ($fees_data) { $fees_master = FeesMasterTransaction::model()->findAll(array('condition' => 'fees_master_id=' . $fees_data->fees_master_id)); foreach ($fees_master as $list) { $fees_detail = FeesDetailsTable::model()->findByPk($list['fees_desc_id']); $student_fees_master->setIsNewRecord(true); $student_fees_master->student_fees_master_id = null; $student_fees_master->student_fees_master_student_transaction_id = $model->student_transaction_id; $student_fees_master->fees_master_table_id = $fees_data->fees_master_id; $student_fees_master->student_fees_master_details_id = $fees_detail->fees_details_name; $student_fees_master->fees_details_amount = $fees_detail->fees_details_amount; $student_fees_master->student_fees_master_org_id = Yii::app()->user->getState('org_id'); $student_fees_master->student_fees_master_created_by = Yii::app()->user->id; $student_fees_master->student_fees_master_creation_date = new CDbExpression('NOW()'); $student_fees_master->save(); } } //================================================================================================================== StudentInfo::model()->updateByPk($model->student_transaction_student_id, array('student_info_transaction_id' => $model->student_transaction_id)); $auth_assign->itemname = 'Student'; $auth_assign->userid = $user->user_id; $auth_assign->save(); $this->redirect(array('update', 'id' => $model->student_transaction_id)); } else { $this->render('create', array('model' => $model, 'info' => $info, 'user' => $user)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new StudentTransaction; $info =new StudentInfo; $user =new User; $photo =new StudentPhotos; $address=new StudentAddress; $lang=new LanguagesKnown; $auth_assign = new AuthAssignment; // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation(array($info,$model,$user)); if(!empty($_POST['StudentTransaction']) || !empty($_POST['StudentInfo'] )) { $stud_roll_no = StudentInfo::model()->findAll(); if(Yii::app()->controller->action->id=='create'){ if(empty($stud_roll_no)) { $rollno=$info->student_roll_no=1; } else { //$rand=mt_rand(1,2000); foreach($stud_roll_no as $s) { $stud[]=$s['student_roll_no']; $rollno_m=MAX($stud)+1; } if(StudentInfo::model()->exists('student_roll_no='.$rollno_m)) { $rollno=$rollno_m+1; } else { $rollno=$rollno_m; } } } else { } //echo $rollno; exit; /*$batch_id=$_POST['StudentTransaction']['student_transaction_batch_id']; $batch=Batch::model()->findByPk($batch_id); $course=$batch->course_id; $academic_year=AcademicTerm::model()->findByPk($course); $model->academic_term_period_id=$academic_year->academic_term_period_id; $model->course_id=$batch->course_id; $model->academic_term_id=$batch->academic_term_id; */ $model->attributes=$_POST['StudentTransaction']; $info->attributes=$_POST['StudentInfo']; $user->attributes=$_POST['User']; $info->student_created_by = Yii::app()->user->id; $info->student_creation_date = new CDbExpression('NOW()'); $info->student_email_id_1=strtolower($user->user_organization_email_id); $info->student_adm_date = date('Y-m-d',strtotime($_POST['StudentInfo']['student_adm_date'])); $info->student_roll_no=$rollno; $info->passport_exp_date=date('Y-m-d',strtotime($_POST['StudentInfo']['passport_exp_date'])); $user->user_organization_email_id = strtolower($info->student_email_id_1); $user->user_password = md5($info->student_email_id_1.$info->student_email_id_1); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_type = "student"; if($info->save(false)) { $user->save(false); $address->save(false); $lang->save(false); $photo->student_photos_path = "no-images"; $photo->save(); } //if(empty($model->student_transaction_batch_id)) //$model->student_transaction_batch_id=0; //$model->academic_term_id=$_POST['StudentTransaction']['academic_term_id']; //$model->academic_term_period_id=$_POST['StudentTransaction']['academic_term_period_id']; $model->course_id=$_POST['StudentTransaction']['course_id']; $model->student_transaction_languages_known_id= $lang->languages_known_id; $model->student_transaction_student_id = $info->student_id; $model->student_transaction_user_id = $user->user_id; $model->student_transaction_student_address_id = $address->student_address_id; $model->student_transaction_student_photos_id = $photo->student_photos_id; $flag = Studentstatusmaster::model()->findByAttributes(array('status_name'=>'Regular'))->id; $model->student_transaction_detain_student_flag = 1; $model->save(false); StudentInfo::model()->updateByPk($model->student_transaction_student_id, array('student_info_transaction_id'=>$model->student_transaction_id)); $auth_assign->itemname = 'Student'; $auth_assign->userid = $user->user_id; $auth_assign->bizrule = ''; $auth_assign->data = ''; $auth_assign->save(true); $this->redirect(array('update','id'=>$model->student_transaction_id)); } //end of isset if else { $this->render('create',array( 'model'=>$model,'info'=>$info,'user'=>$user )); } }
public function actionCreateUser() { $this->layout = 'installation_layout'; $model = new User(); //$ass_comp = new assignCompanyUserTable; //$model->setScenario('create'); $auth_assign = new AuthAssignment(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->user_password = md5($model->user_password . $model->user_password); $model->user_type = 'admin'; $model->user_created_by = 1; $model->user_creation_date = new CDbExpression('NOW()'); //$model->user_organization_id = $_REQUEST['id']; if ($model->save()) { //$ass_comp->assign_user_id = $model->user_id; //$ass_comp->assign_org_id = $_REQUEST['id']; //$ass_comp->assign_created_by = $model->user_id; //$ass_comp->assign_creation_date = new CDbExpression('NOW()'); //$ass_comp->save(); //$auth_assign->attributes = $_POST['AuthAssignment']; //$this->redirect(array('view','id'=>$model->user_id)); $auth_assign->itemname = 'SuperAdmin'; $auth_assign->userid = $model->user_id; $auth_assign->save(false); $this->redirect(array('site/redirectLogin')); } } $this->render('create_user', array('model' => $model)); }
/** * Manages all models. */ public function actionTransferemployee() { $model=new EmployeeTransaction('transferemployee'); $info=new EmployeeInfo; $user =new User; $photo =new EmployeePhotos; $address=new EmployeeAddress; $lang=new LanguagesKnown; $ass_comp = new assignCompanyUserTable; $auth_assign = new AuthAssignment; $this->performAjaxValidation(array($info,$model,$user)); if(!empty($_POST['user_id1'])) { $model->attributes=$_POST['EmployeeTransaction']; $info->attributes=$_POST['EmployeeInfo']; $trans_id = $_POST['user_id1']; $old_model = EmployeeTransaction::model()->resetScope()->findByPk($trans_id); $old_info = EmployeeInfo::model()->findByPk($old_model->employee_transaction_employee_id); $old_info->transfer_left_remarks= $_POST['EmployeeTransaction']['transfer_left_remarks']; $old_info->employee_left_transfer_date = new CDbExpression('NOW()'); $old_info->save(false); $old_model->employee_status = 1; $old_model->save(); $user = User::model()->findByPk($old_model->employee_transaction_user_id); $user->user_created_by = Yii::app()->user->id; $user->user_creation_date = new CDbExpression('NOW()'); $user->user_organization_id = $_POST['EmployeeTransaction']['employee_transaction_organization_id']; if($user->save()) { $org_data = Organization::model()->findByPk($_POST['EmployeeTransaction']['employee_transaction_organization_id']); $org_name = $org_data->organization_name; $org_arr = explode(' ',$org_name); $bizrule = 'return Yii::app()->user->getState("org_id")=='.$_POST['EmployeeTransaction']['employee_transaction_organization_id'].";"; $var_data = serialize($_POST['EmployeeTransaction']['employee_transaction_organization_id']); $suffix_lab = ''; foreach($org_arr as $list) $suffix_lab .= $list[0]; $auth_assign->itemname = 'Employee of '.$suffix_lab; $check = AuthAssignment::model()->findByAttributes(array('itemname'=>$auth_assign->itemname,'userid' => $user->user_id,'data' =>$var_data)); if(empty($check)){ $auth_assign->userid = $user->user_id; $auth_assign->bizrule = $bizrule; $auth_assign->data = $var_data; $auth_assign->save(); } $ass_comp->assign_user_id = $user->user_id; $ass_comp->assign_role_id = 3; $ass_comp->assign_org_id = $_POST['EmployeeTransaction']['employee_transaction_organization_id']; $ass_comp->assign_created_by = Yii::app()->user->id; $ass_comp->assign_creation_date = new CDbExpression('NOW()'); $ass_comp->save(); $info = $old_info; $info->employee_joining_date = new CDbExpression('NOW()'); $info->employee_type = $_POST['EmployeeInfo']['employee_type']; $info->employee_attendance_card_id = ''; $info->employee_created_by = Yii::app()->user->id; $info->employee_creation_date = new CDbExpression('NOW()'); $info->employee_left_transfer_date = NULL; $info->employee_id = null; $info->setIsNewRecord(true); $info->save(false); $model = $old_model; $model->employee_transaction_id = null; $model->setIsNewRecord(true); $model->employee_transaction_user_id = $user->user_id; $model->employee_transaction_employee_id = $info->employee_id; $model->employee_transaction_shift_id = $_POST['EmployeeTransaction']['employee_transaction_shift_id']; $model->employee_transaction_designation_id = $_POST['EmployeeTransaction']['employee_transaction_designation_id']; $model->employee_transaction_department_id = $_POST['EmployeeTransaction']['employee_transaction_department_id']; $model->employee_transaction_organization_id = $_POST['EmployeeTransaction']['employee_transaction_organization_id']; $model->employee_status = 0; $model->save(false); EmployeeInfo::model()->updateByPk($model->employee_transaction_employee_id, array('employee_info_transaction_id'=>$model->employee_transaction_id)); Yii::app()->user->setFlash('success',"Transfer of ".$info->employee_first_name.' to '.$org_name.' successfully.!'); $this->redirect(array('employeeTransaction/admin')); } } $this->render('transfer_employee',array( 'model'=>$model,'info'=>$info,'user'=>$user, )); }
/** * Update a user::role assignment. * The only attributes that can be changed are bizrule and data. * Ajax only method */ public function actionUpdate() { $authAssignment = new AuthAssignment('upate'); // $authAssignment is a CFormModel $form = $authAssignment->getForm(); if ($form->submitted($form->uniqueId)) { // there is no submit button from the juiDialog, so use the form id $response = array(); if ($authAssignment->save()) { $response['content'] = Yii::t('RbamModule.rbam', '"{user}::{role}" assignment updated.', array('{role}' => $authAssignment->itemName, '{user}' => $authAssignment->userName)); } else { $errors = array(); foreach ($authAssignment->getErrors() as $attribute => $attributeErrors) { foreach ($attributeErrors as $error) { $errors[] = array('attribute' => $attribute, 'label' => $authAssignment->getAttributeLabel($attribute), 'error' => $error); } } $response = compact('errors'); } header('Content-type: application/json'); echo CJSON::encode($response); Yii::app()->end(); } }
/** * Экшен создания учетной записи администратора: * * @return nothing **/ public function actionCreateuser() { $model = new InstallForm('createUser'); if (isset($this->session['InstallForm']['createUser'])) { $model->setAttributes($this->session['InstallForm']['createUser']); if ($model->validate() && $this->session['InstallForm']['createUserStep'] === true) { $this->session['InstallForm'] = array_merge($this->session['InstallForm'], ['createUser' => $model->attributes, 'createUserStep' => false]); $this->_markFinished('createuser'); $this->_setSession(); $this->redirect(['/install/default/sitesettings']); } } if (($data = Yii::app()->getRequest()->getPost('InstallForm')) !== null) { // Сбрасываем сессию текущего пользователя, может поменяться id Yii::app()->getUser()->clearStates(); $model->setAttributes($data); if ($model->validate()) { $user = new User(); $user->deleteAll(); $user->setAttributes(['nick_name' => $model->userName, 'email' => $model->userEmail, 'gender' => User::GENDER_THING, 'access_level' => User::ACCESS_LEVEL_ADMIN, 'status' => User::STATUS_ACTIVE, 'email_confirm' => User::EMAIL_CONFIRM_YES, 'hash' => Yii::app()->userManager->hasher->hashPassword($model->userPassword), 'birth_date' => null]); if ($user->save()) { //@TODO заменить на обработку через событие if (Yii::app()->hasModule('rbac')) { Yii::import('application.modules.rbac.models.*'); $assign = new AuthAssignment(); $assign->itemname = AuthItem::ROLE_ADMIN; $assign->userid = $user->id; $assign->save(); } $login = new LoginForm(); $login->email = $model->userEmail; $login->password = $model->userPassword; Yii::app()->authenticationManager->login($login, Yii::app()->user, Yii::app()->request); Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('InstallModule.install', 'The administrator has successfully created!')); $this->session['InstallForm'] = array_merge($this->session['InstallForm'], ['createUser' => $model->attributes, 'createUserStep' => true]); $this->_setSession(); $this->redirect(['/install/default/createuser']); } else { $model->addErrors($user->getErrors()); } } } $this->render('_view', ['data' => ['model' => $model]]); }
/** * @desc addassignments */ public function actionManage() { // get changable collumnnames $colUsername = Yii::app()->controller->module->columnUsername; $colUserid = Yii::app()->controller->module->columnUserid; // check access to view $this->checkAccess('RbacAssignmentViewer', true); if (isset($_GET['userid'])) { // warn if user is protected if (in_array($_GET['userid'], $this->protectedUsers)) { $this->messageWarnings[] = "Warning! User is protected by Controller"; } // user must exist if ($user = User::model()->findByAttributes(array("{$colUserid}" => urldecode($_GET['userid'])))) { $this->manageUser = $user; } else { throw new CHttpException("Selected User " . urldecode($_GET['username']) . " does not exist"); } } elseif (isset($_POST['userid'])) { // check access for edit assignments $this->checkAccess('RbacAssignmentEditor', true); if (in_array($_POST['userid'], $this->protectedUsers)) { $this->messageErrors[] = "Sorry, User is protected by Controller"; $this->actionIndex(); } $username = $_POST['username']; $userid = (int) $_POST['userid']; if (!($user = User::model()->findByAttributes(array("{$colUserid}" => $userid)))) { throw new CHttpException("Managed User {$username} does not exist"); } // add selected assignments if (isset($_POST['addAssignments'])) { // fill bizRule with deny-always code if selected from user $bizRule = isset($_POST['secureMode']) ? 'return false;' : ''; foreach ($_POST['addAssignments'] as $itemname) { // add default code to bizRule if selected if (isset($_POST['addData'])) { $item = AuthItem::model()->findByAttributes(array('name' => $itemname)); $bizRule .= $item->data; } // add assignment $assignment = new AuthAssignment(); $assignment->attributes = array('userid' => $userid, 'itemname' => $itemname, 'bizrule' => $bizRule, 'data' => ''); if (!$assignment->validate()) { throw new CHttpException("New Assignment validation Error"); } $assignment->save(); $this->messageSuccess[] = "Assignment {$itemname} succesfull added."; } } // remove selected assignments if (isset($_POST['removeAssignments'])) { foreach ($_POST['removeAssignments'] as $itemname) { $assignment = AuthAssignment::model()->findByAttributes(array('userid' => $userid, 'itemname' => $itemname)); $assignment->delete(); $this->messageSuccess[] = "Assignment {$itemname} succesfull removed."; } } $this->manageUser = $user; } else { $this->actionIndex(); } $this->manageUser = $user; $this->_getSearchFields(); $displayHelper = new RBACDisplayHelper($this, 'renderItemAssign'); $displayHelper->setUser($this->manageUser); $this->doRender('manage', array('displayHelper' => $displayHelper, 'manageUser' => $this->manageUser, 'getVars' => $this->getGetVars())); Yii::app()->end(); }
public function actionRegister() { $accountMember = new AccountMember(); if (!Yii::app()->user->checkAccess('Admin')) { throw new CHttpException(403, 'You are not authorized to perform this action.'); } // Collect input data if (isset($_POST['AccountMember'])) { $accountMember->attributes = $_POST['AccountMember']; if ($accountMember->validate()) { // Create account $account = new Account(); $account->username = $accountMember->username; $account->password = $accountMember->password; // Create member if ($account->save()) { $member = new Member(); $member->account_id = $account->id; $member->name = $accountMember->name; $member->department = $accountMember->department; $member->role = $accountMember->role; if ($member->save()) { $auth = new AuthAssignment(); $auth->itemname = $member->role; $auth->userid = $account->id; if ($auth->save()) { $this->redirect(array('member')); } //echo $account->password; } else { $accountMember->addErrors($member->getErrors()); } } else { $accountMember->addErrors($account->getErrors()); } } } $this->render('register', array('model' => $accountMember)); }
public function actionAssign($id) { $user = Users::model()->findByPk((int) $id); if (!$user) { throw new CHttpException(404); } $items = AuthItem::model()->findAll(array('order' => 'type DESC')); $itemsData = CHtml::listData(AuthItemChild::model()->findAll(), 'child', 'parent'); if (Yii::app()->request->isPostRequest && count($_POST)) { $itemsArray = CHtml::listData($items, 'name', 'description'); $transaction = Yii::app()->db->beginTransaction(); try { if (count($_POST)) { AuthAssignment::model()->deleteAll('userid = :userid', array(':userid' => (int) $user->id)); foreach ($_POST as $op => $val) { if (!isset($itemsArray[$op])) { continue; } $model = new AuthAssignment(); $model->setAttributes(array('userid' => $user->id, 'itemname' => $op)); if (!$model->save()) { throw new CDbException('При сохранении произошла ошибка!'); } } } $transaction->commit(); Yii::app()->user->setFlash('notice', 'Данные обновлены!'); $this->redirect(array('assign', 'id' => $user->id)); } catch (Exception $e) { Yii::app()->user->setFlash('error', $e->getMessage()); $transaction->rollback(); } } //построить дерево $tree = array(); foreach ($items as $item) { if ($item->type === AuthItem::TYPE_ROLE && !isset($tree[$item->name])) { $tree[$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations', 'class' => 'root')) . $item->description . " ({$item->getType()})"); } if ($item->type === AuthItem::TYPE_TASK) { // проверить есть ли для нее родитель if (isset($itemsData[$item->name]) && $itemsData[$item->name]) { $tree[$itemsData[$item->name]]['children'][$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations', 'class' => 'root')) . $item->description . " ({$item->getType()})"); } else { $tree[$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations')) . $item->description . " ({$item->getType()})"); } } if ($item->type == AuthItem::TYPE_OPERATION) { if (isset($itemsData[$item->name]) && $itemsData[$item->name]) { // задача по своей сути $parent = $itemsData[$item->name]; if (isset($itemsData[$parent]) && $itemsData[$parent]) { $tree[$itemsData[$parent]]['children'][$itemsData[$item->name]]['children'][$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations')) . $item->description . " ({$item->getType()})"); } else { $tree[$itemsData[$item->name]]['children'][$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations')) . $item->description . " ({$item->getType()})"); } } else { $tree[$item->name] = array('text' => CHtml::checkBox($item->name, Yii::app()->user->checkAccess($item->name, $user->id), array('name' => 'operations')) . $item->description . " ({$item->getType()})"); } } } $this->render('assign', array('tree' => $tree, 'model' => $user)); }
public function getRole() { $assigment = AuthAssignment::model()->findByAttributes(array( 'userid' => $this->id )); if (!$assigment) { $assigment = new AuthAssignment(); $assigment->itemname = AuthItem::ROLE_DEFAULT; $assigment->userid = $this->id; $assigment->save(); } return $assigment->role; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->pagename = "Register " . $this->pagename; $model = new Users('createUser'); $transaction = $model->getDbConnection()->beginTransaction(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Users'])) { $model->attributes = $_POST['Users']; $oldpassword = $model->password; $user = Users::model()->find('email=:email and status=0', array(':email' => $model->email)); if ($user) { $model = $user; } $model->password = $oldpassword; $model->password_repeat = $oldpassword; $model->status = 1; $model->password = md5(trim($model->password)); $model->key = $model->password; $model->password_repeat = $model->password; //try { if ($model->save()) { if (!$user) { $authmodel = new AuthAssignment(); $authmodel->itemname = 'manager'; $authmodel->userid = $model->id; } if ($user || $authmodel->save()) { $transaction->commit(); $identity = new UserIdentity($model->email, $model->password); $identity->authenticate(); Yii::app()->user->login($identity, 0); if (Yii::app()->user->IsGuest) { $this->redirect(Yii::app()->baseUrl . '/site/login'); } $this->redirect(Yii::app()->baseUrl . '/appointments/index'); //$this->redirect(array('view', 'id' => $model->id)); } else { $transaction->rollback(); $model->password = $oldpassword; $model->password_repeat = $oldpassword; } } // } catch (Exception $e) { // $transaction->rollback(); // $model->password=$oldpassword; // $model->password_repeat=$oldpassword; // } //} } $this->render('create', array('model' => $model)); }
/** * Registration user */ public static function register($model, $post, $role = 'Customer') { $model->attributes = $post; if (isset($_COOKIE['partner'])) { $model->pid = intval($_COOKIE['partner']); } if ($model->validate()) { $soucePassword = UserModule::generate_password(8); $model->password = UserModule::encrypting($soucePassword); $model->superuser = 0; $model->status = 1; if ($model->save()) { $AuthAssignment = new AuthAssignment(); $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id); $AuthAssignment->save(); if ($role == 'Author') { if ($model->profile == null) { $profile = new Profile(); $profile->user_id = $model->id; $profile->mailing_for_executors = 1; $profile->save(); } } $webmasterlog = new WebmasterLog(); $webmasterlog->pid = $model->pid; $webmasterlog->uid = $model->id; $webmasterlog->date = date("Y-m-d"); $webmasterlog->action = WebmasterLog::REG; $webmasterlog->save(); // новая служба системных сообщений $type_id = Emails::TYPE_11; $email = new Emails(); $criteria = new CDbCriteria(); $criteria->order = 'id DESC'; $criteria->limit = 1; $user = User::model()->findAll($criteria); $user = $user[0]; $email->from_id = 1; $email->to_id = $user->id; $rec = Templates::model()->findAll("`type_id`='{$type_id}'"); $id = Company::getId(); $email->company = Company::getName(); $email->name = $model->full_name; $email->login = $model->email; $email->password = $soucePassword; $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit'; $email->sendTo($user->email, $rec[0]->title, $rec[0]->text, $type_id); $identity = new UserIdentity($model->email, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); //$this->redirect(Yii::app()->controller->module->returnUrl[0]); return true; //Yii::app()->end(); } else { //Yii::app()->user->setFlash('reg_failed',UserModule::t("Sorry, something wrong... :(")); //$this->refresh(); echo 'Cant save'; Yii::app()->end(); } } else { return false; } }