public function testSaveAndLoadGroup() { $u = array(); for ($i = 0; $i < 5; $i++) { $user = new User(); $user->setScenario('createUser'); $user->username = "******"; $user->title->value = 'Mr.'; $user->firstName = "Uuuuuu{$i}"; $user->lastName = "Uuuuuu{$i}son"; $user->setPassword("uuuuu{$i}"); $this->assertTrue($user->save()); $u[] = $user; } $a = new Group(); $a->name = 'AAA'; $this->assertTrue($a->save()); $this->assertEquals(0, $a->users->count()); $this->assertEquals(0, $a->groups->count()); $b = new Group(); $b->name = 'BBB'; $this->assertTrue($b->save()); $this->assertEquals(0, $b->users->count()); $this->assertEquals(0, $b->groups->count()); $a->users->add($u[0]); $a->groups->add($b); $this->assertTrue($a->save()); $this->assertEquals(1, $a->users->count()); $b->forget(); unset($b); $a->forget(); unset($a); }
public function actionRegistration() { $model = new User(); $model->setScenario('registration'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $setting = Settings::model()->findByPk(1); if ($setting->defaultUserStatus == 1) { $model->status = 0; } else { $model->status = 1; } if ($model->save()) { if ($setting->defaultUserStatus == 1) { Yii::app()->user->setFlash('registration', 'Регистрация прошла успешно. Теперь вы можете авторизоваться..'); } else { Yii::app()->user->setFlash('registration', 'Ждите подтверждения администратора.'); } $this->refresh(); } } $this->render('registration', array('model' => $model)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (!Yii::app()->user->checkAccess('user.create')) { throw new Http403Exception(); } $model = new User('create'); /* @var CDbAuthManager */ $auth = Yii::app()->authManager; $rolesAll = $auth->getAuthItems(2); $roles = array(); foreach ($rolesAll as $roleId => $role) { $roles[$roleId] = $role->description; } $rolesNames = array_keys($roles); $assignments = array_keys($auth->getAuthAssignments($model->id)); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if (!empty($_POST['User']['password'])) { $model->setScenario('changePassword'); $model->password = md5($_POST['User']['password']); $model->passwordConfirm = md5($_POST['User']['passwordConfirm']); } if ($model->save()) { if (isset($_POST['User']['roles'])) { $this->processRoles($model, (array) $_POST['User']['roles'], $rolesNames); } $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'roles' => $roles, 'assignments' => $assignments)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); $ass_comp = new assignCompanyUserTable(); $model->setScenario('create'); // 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_organization_id = Yii::app()->user->getState('org_id'); $model->user_created_by = Yii::app()->user->id; $model->user_creation_date = new CDbExpression('NOW()'); if ($model->save()) { /*$ass_comp->assign_user_id = $model->user_id; $ass_comp->assign_role_id = 2; $ass_comp->assign_org_id = Yii::app()->user->getState('org_id'); $ass_comp->assign_created_by = Yii::app()->user->id; $ass_comp->assign_creation_date = new CDbExpression('NOW()'); $ass_comp->save();*/ //$this->redirect(array('view','id'=>$model->user_id)); $this->redirect(array('admin')); } } $this->render('create', 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 User(); $model->setScenario('create'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if ($model->save()) { Yii::app()->user->setFlash('success', 'L\'utilisateur a été enregistré avec succès.'); $this->redirect(array('view', 'id' => $model->_id)); } } $this->render('create', 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 User(); $model->setScenario('ucreate'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if ($model->save()) { $this->redirect(array('admin')); } } $this->render('create', array('model' => $model)); }
public function testSaveAndLoadGroup() { $u = array(); for ($i = 0; $i < 5; $i++) { $user = new User(); $user->setScenario('createUser'); $user->username = "******"; $user->title->value = 'Mr.'; $user->firstName = "Uuuuuu{$i}"; $user->lastName = "Uuuuuu{$i}son"; $user->setPassword("uuuuu{$i}"); $this->assertTrue($user->save()); // Clear cache of user so the groups properly get accounted for later. // This was needed after we added isActive which calls save twice when a user is // created $id = $user->id; $user->forget(); $u[] = User::getById($id); } $a = new Group(); $a->name = 'AAA'; $this->assertTrue($a->save()); $this->assertEquals(0, $a->users->count()); $this->assertEquals(0, $a->groups->count()); $b = new Group(); $b->name = 'BBB'; $this->assertTrue($b->save()); $this->assertEquals(0, $b->users->count()); $this->assertEquals(0, $b->groups->count()); $a->users->add($u[0]); $a->groups->add($b); $this->assertTrue($a->save()); $this->assertEquals(1, $a->users->count()); $b->forget(); unset($b); $a->forget(); unset($a); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new User(); $model->setScenario('subscribe'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $criteria = new EMongoCriteria(); $criteria->login = $model->login; $userLogin = User::model()->findAll($criteria); if (count($userLogin) > 0) { Yii::app()->user->setFlash('error', Yii::t('common', 'loginExist')); $this->render('create', array('model' => $model)); } else { if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('common', 'userSaved')); $this->redirect(array('view', 'id' => $model->_id)); } else { Yii::app()->user->setFlash('error', Yii::t('common', 'missingFields')); } } } $this->render('create', array('model' => $model)); }
/** * action to subscribe a new user account. */ public function actionSubscribe() { $model = new User(); $model->setScenario('subscribe'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->telephone = str_replace(" ", "", $model->telephone); $profil = implode("", $model->profil); $userLogin = $model->getAllUsersByLogin($model); if (count($userLogin) > 0) { Yii::app()->user->setFlash('error', Yii::t('common', 'loginExist')); } else { if ($model->profil == array("clinicien")) { if ($model->save()) { CommonMailer::sendSubscribeAdminMail($model, NULL); CommonMailer::sendMailInscriptionUser($model->email, $model->login, $model->prenom, $model->nom, $model->password, NULL); Yii::app()->user->setFlash('success', Yii::t('common', 'welcomeTo') . Yii::app()->name); $this->redirect(array('site/index')); } } if ($profil == "neuropathologiste") { if ($model->validate()) { if (empty($_POST['User']['centre'])) { $model->addError('centre', Yii::t('common', 'referenceCenterRequired')); } else { if ($model->save()) { CommonMailer::sendSubscribeUserMail($model, $profil); CommonMailer::sendMailConfirmationProfilEmail($model, $profil, $_POST['User']['centre']); Yii::app()->user->setFlash('success', Yii::t('common', 'success_register')); $this->redirect(array('site/login')); } } } } if ($profil == "geneticien" || $profil == "chercheur") { if ($model->save()) { CommonMailer::sendSubscribeUserMail($model, $profil); CommonMailer::sendMailConfirmationProfilEmail($model, $profil, NULL); Yii::app()->user->setFlash('success', Yii::t('common', 'success_register')); $this->redirect(array('site/login')); } } Yii::app()->user->setFlash('error', Yii::t('common', 'userNotSaved')); } } $this->render('subscribe', array('model' => $model)); }
/** * action to subscribe a new user account. */ public function actionSubscribe() { $model = new User(); $model->setScenario('subscribe'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->profil = 0; $model->inactif = 1; if ($model->save()) { CommonMailer::sendSubscribeAdminMail($model); CommonMailer::sendSubscribeUserMail($model); Yii::app()->user->setFlash('success', Yii::t('common', 'success_register')); if (isset($_GET['layout'])) { if ($_GET['layout'] == 'vitrine_layout') { $this->redirect(array('vitrine/view', 'id' => $_SESSION['biobank_id'])); } } else { $this->redirect(array('site/index')); } } else { Yii::app()->user->setFlash('error', Yii::t('common', 'error_register')); } } $this->render('subscribe', array('model' => $model)); }
public function actionCreate() { $title = Zurmo::t('UsersModule', 'Create User'); $breadCrumbLinks = array($title); $user = new User(); $user->language = Yii::app()->language; $user->currency = Yii::app()->currencyHelper->getActiveCurrencyForCurrentUser(); $user->setScenario('createUser'); $userPasswordForm = new UserPasswordForm($user); $userPasswordForm->setScenario('createUser'); $this->attemptToValidateAjaxFromPost($userPasswordForm, 'UserPasswordForm'); $view = new UsersPageView(ZurmoDefaultAdminViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $this->makeTitleBarAndEditView($this->attemptToSaveModelFromPost($userPasswordForm), 'UserCreateView'), $breadCrumbLinks, 'UserBreadCrumbView')); echo $view->render(); }
public function testCreateNewUserFromPostNoBadValues() { $_FAKEPOST = array('UserPasswordForm' => array('title' => array('value' => ''), 'firstName' => 'Red', 'lastName' => 'Jiambo', 'username' => 'redjiambo', 'newPassword' => '123456', 'newPassword_repeat' => '123456', 'jobTitle' => '', 'officePhone' => '', 'manager' => array('id' => ''), 'mobilePhone' => '', 'department' => '', 'primaryEmail' => array('emailAddress' => '', 'optOut' => 0, 'isInvalid' => 0), 'primaryAddress' => array('street1' => '', 'street2' => '', 'city' => '', 'state' => '', 'postalCode' => '', 'country' => ''))); $user = new User(); $user->setScenario('createUser'); $userPasswordForm = new UserPasswordForm($user); $userPasswordForm->setScenario('createUser'); $userPasswordForm->setAttributes($_FAKEPOST['UserPasswordForm']); $userPasswordForm->validate(); $this->assertEquals(array(), $userPasswordForm->getErrors()); $this->assertTrue($userPasswordForm->save()); $user->forget(); $user = User::getByUsername('redjiambo'); $this->assertEquals('Red', $user->firstName); $this->assertEquals(null, $user->officePhone); $this->assertEquals(null, $user->jobTitle); $this->assertEquals(null, $user->mobilePhone); $this->assertEquals(null, $user->department); }
/** * @covers EMongoUniqueValidator */ function testUniqueValidator() { $c = new User(); $c->setScenario('testUnqiue'); $c->username = '******'; $this->assertTrue($c->save()); $c = new User(); $c->setScenario('testUnqiue'); $c->username = '******'; $this->assertFalse($c->validate()); $this->assertNotEmpty($c->getError('username')); }
public function actionEdit() { $model = new User(); $model->setScenario('edit'); $user_id = Yii::app()->user->getId(); //$userData = User::model()->findAllByAttributes(array('id'=>$id)); $model = $this->loadModel($user_id); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; //if(!isset($this->isNewRecord)) { if ($model->validate()) { if ($model->save()) { $this->redirect(array('post/index')); } } else { $errores = $model->getErrors(); } //} } $this->render('edit', array('model' => $model)); }