Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $password = $_POST['User']['password'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 //send mail
                 UserModule::sendMail($model->email, UserModule::t("You are registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password)));
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('/rights/assignment/user', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     //profile pic
     //UWprofilepic::handleProfilePic($model,$profile);
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 // roles
                 $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
                 $authorizer->authManager->assign($_POST['User']['auth'], $model->id);
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  *
  * @return void
  */
 public function actionCreate()
 {
     $model = new User('create');
     $profile = new Profile();
     if (($data = Yii::app()->getRequest()->getPost('User')) !== null) {
         $model->setAttributes($data);
         $model->setAttributes(array('hash' => Yii::app()->userManager->hasher->hashPassword(Yii::app()->userManager->hasher->generateRandomPassword())));
         $profile->setAttributes(Yii::app()->getRequest()->getPost('Profile'));
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $transaction = Yii::app()->db->beginTransaction();
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 $transaction->commit();
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'New user was created!'));
                 $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
             } else {
                 $transaction->rollback();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 4
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->username = $_POST['User']['username'];
         $model->password = $_POST['User']['password'];
         $model->email = $_POST['User']['email'];
         $model->superuser = $_POST['User']['superuser'];
         $model->status = $_POST['User']['status'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 5
0
 }
 /**
  * Displays a particular model.
  */
 public function actionView()
 {
     $this->layout = '//layouts/column2';
     $model = $this->loadModel();
     $this->render('view', array('model' => $model));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '//layouts/column2';
     $model = new User();
     $profile = new Profile();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $model->createtime = time();
         $model->lastvisit = time();
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     $manager = !User::model()->isAuthor();
     $admin = User::model()->isAdmin();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $_temp = array('', 'icq', 'sms', 'email');
         $_POST['Profile']['mailing_list'] = array_search($_POST['Profile']['mailing_list'], $_temp);
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $fields = ProfileField::model()->findAll();
     $this->render('create', array('model' => $model, 'profile' => $profile, 'fields' => $fields, 'manager' => $manager, 'admin' => $admin));
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     //var_dump("test");exit;
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     //var_dump($model);exit;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     //var_dump($_POST['ajax']);exit;
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             //var_dump($_POST['RegistrationForm']);exit;
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = AdminModule::encrypting(microtime() . $model->password);
                 $model->password = AdminModule::encrypting($model->password);
                 $model->verifyPassword = AdminModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/admin/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         AdminModule::sendMail($model->email, AdminModule::t("Anda registrasi dari {site_name}", array('{site_name}' => Yii::app()->name)), AdminModule::t("Silahkan Aktifkan akun anda melalui link {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Hubungi Admin untuk mengaktifkan akun anda."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan {{login}}.", array('{{login}}' => CHtml::link(AdminModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda atau login."));
                         } else {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     if (Yii::app()->getModule('user')->disableUsername) {
         $model->username = time() + rand(0, 9999999);
     }
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->getReturnUrl());
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 9
0
 public function actionCreate()
 {
     $model = new Staff();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile), 'staff-form');
     if (isset($_POST['Staff'])) {
         $model->attributes = $_POST['Staff'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Profile']['group_id'])) {
                     foreach ($_POST['Profile']['group_id'] as $groupid) {
                         $userGroup = new UserGroup();
                         $userGroup->profile_id = $model->id;
                         $userGroup->group_id = $groupid;
                         $userGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'An error occured while trying to create new user, please try again.');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->render('create', array('model' => $model, 'profile' => $profile));
             }
         } else {
             $profile->validate();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 10
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         if (isset($_POST['Profile'])) {
             $profile->attributes = $_POST['Profile'];
             $profile->user_id = 0;
         }
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $_POST['Profile']['firstname'] = $model->firstname;
                 $_POST['Profile']['lastname'] = $model->lastname;
                 if (isset($_POST['Profile'])) {
                     $profile->user_id = $model->id;
                     $profile->save();
                 }
                 //Function in components/Controller.php
                 //$this->assignRole($model->id, 'Subscription');
                 if (isset($_POST['System']['role'])) {
                     $this->assignRole($model->id, $_POST['System']['role']);
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
             //} else {
             //$profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $specials = $this->get_specials($model->profile->specials);
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $_temp = array('', 'icq', 'sms', 'email');
         $_POST['Profile']['mailing_list'] = array_search($_POST['Profile']['mailing_list'], $_temp);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $specials = $this->get_specials();
     $this->render('create', array('model' => $model, 'profile' => $profile, 'specials' => $specials));
 }
Exemplo n.º 12
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $user = new User();
     $profile = new Profile();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation(array($user, $profile));
     if (isset($_POST['User'], $_POST['Profile'])) {
         // populate input into $model and $profile
         $user->attributes = $_POST['User'];
         $profile->attributes = $_POST['Profile'];
         // validate both $model and $profile
         $valid = $user->validate();
         $valid = $profile->validate() && $valid;
         if ($valid) {
             if ($user->save()) {
                 $profile->user_id = $user->id;
                 $profile->email = $user->username;
                 if ($profile->save()) {
                     $this->redirect(array('view', 'id' => $user->id));
                 }
             }
         }
     }
     $this->render('create', array('user' => $user, 'profile' => $profile));
 }
	/**
	 * Registration user
	 */
	public function actionRegistration() 
	{
        
        if(Y::module()->isRegistrationClose) $this->redirect('close');
		$model = new RegistrationForm;
        $profile=new Profile;
        $profile->regMode = true;
            
		// ajax validator
		if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form')
			Y::end(UActiveForm::validate(array($model,$profile)));
		
		if (Y::userId()) {
			$this->redirect(Y::module()->cabinetUrl);
		} else {
			if(isset($_POST['RegistrationForm'])) {
				$model->attributes=$_POST['RegistrationForm'];
				$profile->attributes= isset($_POST['Profile'])?$_POST['Profile']:array();
				if($model->validate()&&$profile->validate())
				{
					$soucePassword = $model->password;
					$model->activkey=UserModule::encrypting(microtime().$soucePassword);
					$model->password=UserModule::encrypting($soucePassword);
					$model->verifyPassword=UserModule::encrypting($model->verifyPassword);
					$model->createtime=time();
					$model->lastvisit=((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin)?time():0;
					$model->superuser=0;
					$model->status=((Y::module()->activeAfterRegister)?User::STATUS_ACTIVE:User::STATUS_NOACTIVE);
						
					if ($model->save()) {
						$profile->user_id=$model->id;
						$profile->save();
						if (Y::module()->sendActivationMail) {
							$activation_url = $this->createAbsoluteUrl('/user/activation',array("activkey" => $model->activkey, "email" => $model->email));
							UserModule::sendMail($model->email,Users::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),Users::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url)));
						}
							
						if ((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin) {
							$identity=new UserIdentity($model->username,$soucePassword);
								$identity->authenticate();
								Y::user()->login($identity,0);
								$this->redirect(Y::module()->returnUrl);
						} else {
							if (!Y::module()->activeAfterRegister&&!Y::module()->sendActivationMail) {
								Y::flash('/user/registration',Users::t("Thank you for your registration. Contact Admin to activate your account."));
							} elseif(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false) {
								Y::flash('/user/registration',Users::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(Users::t('Login'),Y::module()->loginUrl))));
							} elseif(Y::module()->loginNotActiv) {
								Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email or login."));
							} else {
								Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email."));
							}
							$this->refresh();
						}
					}
				} else $profile->validate();
			}
		    $this->render('/user/registration',array('model'=>$model,'profile'=>$profile,'lang'=>Yii::app()->language));
	    }
	}
Exemplo n.º 14
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 /**
                  * date added:	03 December 2013
                  * purpose:		save Pstc (profile field) during User Update
                  */
                 //$profile->pstc=$_POST['Profile']['pstc'];
                 if ($profile->accesslist != '') {
                     $profile->accesslist = implode(',', $_POST['Profile']['accesslist']);
                 }
                 //converting to string...
                 $profile->save();
                 $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
                 $authorizer->authManager->assign($_POST['accesslevel'], $model->id);
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 15
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $model->createtime = time();
         $model->lastvisit = time();
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 // assign user the 'Authenticated' role for Rights module
                 $authenticatedName = Rights::module()->authenticatedName;
                 Rights::assign($authenticatedName, $model->id);
                 // end of change
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 16
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = $_POST['Profile'];
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->createtime = time();
                 $model->lastvisit = (Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin ? time() : 0;
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     // assign user the 'Authenticated' role for Rights module
                     $authenticatedName = Rights::module()->authenticatedName;
                     Rights::assign($authenticatedName, $model->id);
                     // end of change
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UserModule::sendMail($model->email, UserModule::t("You have registered at {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate your account. Go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for registering. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             }
         }
         $this->render('/user/registration', array('form' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 17
0
 public function actionIndex()
 {
     $model = new User();
     $model->superuser = 0;
     //not super user
     $model->status = User::STATUS_ACTIVE;
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     $assignedListId = "";
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->getModule("user")->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->getModule("user")->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 // To prevent having empty id for object model
                 // Save the  assigned listid*/
                 $listOfListId = explode(",", $_POST['assignedListId']);
                 foreach ($listOfListId as $key => $value) {
                     $listidModel = ListId::model()->findByAttributes(array('list_id_value' => $value));
                     if ($listidModel) {
                         $newAssignment = new AssignedAllowedListId();
                         $newAssignment->list_id = $listidModel->id;
                         $newAssignment->user_id = $model->id;
                         $newAssignment->save();
                     }
                 }
             }
             $assignedListId = $_POST['assignedListId'];
             Yii::app()->user->setFlash("success", "Success! New user created ");
             $this->redirect(array('/ManageUser'));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'selectedAllowedId' => $assignedListId));
 }
Exemplo n.º 18
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $this->seo(Yii::t('admin', 'Registration'));
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 //Стартуем транзакции чтобы убедиться в целостности данных
                 $transaction = Yii::app()->db->beginTransaction();
                 try {
                     //Сохраняем все данные
                     $model->save(false);
                     $profile->user_id = $model->id;
                     $profile->save();
                     $roles = $this->setUserRoles($model->id);
                     $roles->save();
                     $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     $send = Email::sendUserNoReply($model->username, $model->email, Yii::t('admin', 'Confirm registration'), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     if ($send) {
                         Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                     } else {
                         Yii::app()->user->setFlash('registration', Yii::t('admin', 'Upon registration error occurred. Please re-register or contact us.'));
                     }
                     if ($transaction->commit()) {
                     }
                     $this->refresh();
                 } catch (Exception $e) {
                     $transaction->rollback();
                 }
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 19
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $modelClass = new Classes();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 /*Add role for user. added by phihx. date 14/02/2014*/
                 if (!empty($_POST['user_role'])) {
                     //foreach($_POST['user_role'] as $role){
                     Rights::assign($_POST['user_role'], $model->id);
                     //}
                 }
                 if (!empty($_POST['Classes']['id'])) {
                     $userClass = new UsersClass();
                     $userClass->user_id = $model->id;
                     $userClass->class_id = $_POST['Classes']['id'];
                     $userClass->save();
                 }
                 Yii::app()->user->setFlash('success', translate('Thêm mới người dùng thành công.'));
             }
             $this->redirect(PIUrl::createUrl('/user'));
         } else {
             $profile->validate();
         }
     }
     /* Get All role. Added by Phihx. date 14/02/2014*/
     $allRoles = $this->getAllRoleUser();
     //$allClass = Classes::model()->findAll();
     /*Get classes*/
     $arrClass[''] = '---Chọn lớp---';
     $classes = Classes::model()->findAllByAttributes(array('status' => Classes::STATUS_ACTIVE));
     if (!empty($classes)) {
         foreach ($classes as $class) {
             $arrClass[$class->id] = $class->name;
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'modelClass' => $modelClass, 'allRoles' => $allRoles, 'arrClass' => $arrClass, 'userCurrenRole' => array('student')));
 }
Exemplo n.º 20
0
 public function actionCreateAjax($ccmp_id)
 {
     if (isset($_POST['User'])) {
         //$this->performAjaxValidation($model4update, 'branch-form');
         try {
             $user = new User();
             $user->username = $_POST['User']['username'];
             $user->email = $_POST['User']['email'];
             $user->superuser = 0;
             $user->status = 1;
             $profile = new Profile();
             $profile->attributes = $_POST['Profile'];
             if (!$user->validate() || !$profile->validate()) {
                 $this->renderPartial("/Customers/_form_horizontal_ajax", array('ccmp_id' => $ccmp_id, 'model4updateuser' => $user, 'model4updateprofile' => $profile));
                 exit;
             }
             $pass = CcmpCompany::createCustomerUser($user, $profile, $ccmp_id);
             $yiiuser = Yii::app()->getComponent('user');
             $yiiuser->setFlash('success', "Customer user created with password " . $pass);
             if (isset($_POST['email_pass'])) {
                 $message = new YiiMailMessage();
                 $message->setSubject('New user created');
                 $message->setBody('New user created. <br />
                                username: <b>' . $user->username . '</b>, password:<b> ' . $pass . '</b>', 'text/html');
                 $message->addTo($_POST['email_pass']);
                 $message->from = '*****@*****.**';
                 $sent = Yii::app()->mail->send($message);
             }
         } catch (Exception $e) {
             $this->renderPartial("/Customers/_form_horizontal_ajax", array('ccmp_id' => $ccmp_id, 'model4updateuser' => $user, 'model4updateprofile' => $profile));
             exit;
         }
     }
     $model4newuser = new User();
     $model4newprofile = new Profile();
     $this->renderPartial("/Customers/_form_horizontal_ajax", array('ccmp_id' => $ccmp_id, 'model4updateuser' => $model4newuser, 'model4updateprofile' => $model4newprofile));
     //$this->render('view', array('model' => $model, 'model4grid' => $model4grid, 'model4update' => $model4update));
 }
Exemplo n.º 21
0
	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new User('create');
		if($this->module->isRegistrationClose) {
			$model->status = User::STATUS_ACTIVE;
		}
		$profile=new Profile;
		// ajax validator
		if(isset($_POST['ajax']) && $_POST['ajax']==='create-user-form')
		{
			echo UActiveForm::validate(array($model,$profile));
			Yii::app()->end();
		}
		
		if(isset($_POST['User']))
		{
			$model->attributes=$_POST['User'];
			$model->activkey=Y::module()->encrypting(microtime().$model->password);
			$model->createtime=time();
			$model->lastvisit=time();
			$profile->attributes=$_POST['Profile'];
			
			$profile->user_id=0;
			if($model->validate()&&$profile->validate()) {
				$model->password=Y::module()->encrypting($model->password);
				if($model->save()) {
					$profile->user_id=$model->id;
					$profile->save();
					//UserModule::sendMail($email, $subject, 'registration');
				}
				$this->redirect(array('view','id'=>$model->id));
			} else $profile->validate();
		}

		$this->render('create',array(
			'model'=>$model,
			'profile'=>$profile,
		));
	}
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     $org = new Organisation();
     // ajax validator
     //if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form')
     //{
     //        echo UActiveForm::validate(array($model,$profile));
     //        Yii::app()->end();
     //}
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         if ($_POST['RegistrationForm']['service'] == 2) {
             ////////////////////////////////////////////////////////////////////////////////
             //$name = trim($org->name);
             $name = trim($_POST['Organisation']['name']);
             $exOrgCount = Organisation::model()->count('name=:param_name', array(':param_name' => $name));
             if ($exOrgCount > 0) {
                 $org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message' => Yii::t('app', 'Group Name already exists'))));
             } else {
                 if (strlen($name) == 0) {
                     $org->validatorList->add(CValidator::createValidator('required', $org, 'name', array('message' => Yii::t('app', 'Group Name canot be blank'))));
                 }
             }
             ////////////////////////////////////////////////////////////////////////////////
             echo UActiveForm::validate(array($model, $profile, $org));
             Yii::app()->end();
         } else {
             echo UActiveForm::validate(array($model, $profile));
             Yii::app()->end();
         }
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             $valid = $model->validate();
             $valid = $profile->validate() && $valid;
             if ($_POST['RegistrationForm']['service'] == 2) {
                 $org->name = trim($_POST['Organisation']['name']);
                 $valid = $org->validate() && $valid;
             }
             //if($model->validate()&&$profile->validate())
             if ($valid) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 $orgDuplicateCheck = false;
                 $flag = true;
                 $role = 'Authenticated';
                 if ($model->service == 1) {
                     $orgDuplicateCheck = true;
                     $role = 'Individual';
                 } else {
                     if ($model->service == 2 && isset($_POST['Organisation']['name'])) {
                         $org->name = trim($_POST['Organisation']['name']);
                         $flag = Organisation::model()->exists('name=:param_name_check', array(':param_name_check' => $org->name));
                         if (!$flag) {
                             $orgDuplicateCheck = true;
                         }
                         $role = 'Org_Admin';
                     } else {
                         //$org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message'=>Yii::t('app','Group Name Already Exists'))));
                         $org->validate();
                         Yii::app()->user->setFlash('registration', UserModule::t("Group Name already exists"));
                     }
                 }
                 if ($orgDuplicateCheck) {
                     if ($model->save()) {
                         $profile->user_id = $model->id;
                         $profile->firstname = $model->firstname;
                         $profile->lastname = $model->lastname;
                         $profile->save();
                         $this->assignRole($model->id, $role);
                         //If Service=2 ~ Organisation Save New (Non-Existent) Organisation
                         if (!$flag) {
                             $org->created_by = $model->id;
                             $org->type = 'Other';
                             //$org->timestamp_create = date('Y-m-d H:i:s');
                             if ($org->save()) {
                                 $model->organisation_id = $org->id;
                                 $model->organisation_administrator = 1;
                                 $model->save(false);
                                 try {
                                     //Create Organisation Group
                                     $group = new Group();
                                     $group->group_name = $org->name;
                                     $group->parent_group_id = 0;
                                     $group->organisation_id = $org->id;
                                     $group->timestamp_created = date('Y-m-d H:i":');
                                     $group->save(false);
                                     $groupMember = new GroupMember();
                                     $groupMember->group_id = $group->group_id;
                                     $groupMember->user_id = $model->id;
                                     $groupMember->manager_flag = 1;
                                     //$groupMember->created_by = 0;
                                     //$groupMember->timestamp_created = date('Y-m-d H:i:s');
                                     $groupMember->save(false);
                                 } catch (Exception $ex) {
                                     Yii::log($ex->getMessage(), 'error', 'Custom');
                                 }
                             } else {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Oop! Soemthing Went Wrong"));
                             }
                         }
                         if (Yii::app()->controller->module->sendActivationMail) {
                             $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                             UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate your account by going to {activation_url}", array('{activation_url}' => $activation_url)));
                         }
                         if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                             $identity = new UserIdentity($model->username, $soucePassword);
                             $identity->authenticate();
                             Yii::app()->user->login($identity, 0);
                             $this->redirect(Yii::app()->controller->module->returnUrl);
                         } else {
                             if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                             } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                             } elseif (Yii::app()->controller->module->loginNotActiv) {
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email to login."));
                             } else {
                                 //Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email."));
                                 Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your spam/junk folder if you email is not in inbox."));
                             }
                             $this->refresh();
                         }
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile, 'org' => $org));
     }
 }
Exemplo n.º 23
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Customer();
     $profile = new Profile();
     $address = new CheckoutAddress();
     //Yii::app()->session['cid'] = '';
     $this->performAjaxValidation(array($model, $profile), 'customer-form');
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate() && $this->validateAddress()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             $model->type = 1;
             if ($model->save()) {
                 Yii::app()->session['cid'] = $model->id;
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Customer']['c_group_id'])) {
                     foreach ($_POST['Customer']['c_group_id'] as $groupid) {
                         $customerGroup = new CustomerCGroup();
                         $customerGroup->user_id = $model->id;
                         $customerGroup->c_group_id = $groupid;
                         $customerGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 foreach ($this->_address as $address) {
                     $address->user_id = $model->id;
                     $address->save();
                 }
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, Yii::t('info', 'Customer was successfully created'));
                 $this->renderPartial('_view', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
                 Yii::app()->end();
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'An error occurred while trying to create new customer, please try again.'));
                 /*$this->render('create',array(
                 			'model'=>$model,
                 			'profile'=>$profile,
                 		));*/
             }
         } else {
             $profile->validate();
             $this->validateAddress();
             //echo GxActiveForm::validateMultiple(array($model,$profile,$address));
             //Yii::app()->end();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form_address', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'address' => $this->_address));
 }
Exemplo n.º 24
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     if (isset($_GET['period']) and !empty($_GET['period']) and !empty($_GET['sahkoposti']) and $_GET['session'] == Yii::app()->getSession()->getSessionId() and !empty($_GET['kayttokoodi'])) {
         Yii::app()->user->setState('period', $_GET['period']);
         Yii::app()->user->setState('sahkoposti', $_GET['sahkoposti']);
         Yii::app()->user->setState('kayttokoodi', $_GET['kayttokoodi']);
     }
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 // Uusi myyja
                 if (isset($_POST['myyja']) and $_POST['myyja'] == 1) {
                     Yii::app()->user->setState('myyja', true);
                     $vahvistuskoodi = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 8)), 0, 8);
                     $model->myyja_vahvistus = $vahvistuskoodi;
                     if (isset($_POST['paa_myyja'])) {
                         $model->paa_myyja = $_POST['paa_myyja'];
                     }
                     $model->myyja = 1;
                 }
                 // Uusi myyja -->
                 if (isset($_POST['myyjaID']) and !empty($_POST['myyjaID'])) {
                     $model->myyjaID = $_POST['myyjaID'];
                 }
                 $model->status = 1;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->mainosten_lahetys = 1;
                     $profile->save();
                     /*
                     							if (Yii::app()->controller->module->sendActivationMail) {
                     								$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $model->activkey, "email" => $model->email));
                     								UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url)));
                     							}
                     */
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi. Aktivoitintiviesti on lähetetty sähköpostiisi."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi. Aktivoitintiviesti on lähetetty sähköpostiisi."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi."));
                             $model = new UserLogin();
                             $model->username = $_POST['RegistrationForm']['username'];
                             $model->password = $_POST['RegistrationForm']['password'];
                             if ($model->validate()) {
                                 if (isset(Yii::app()->user->myyja)) {
                                     $this->redirect(array('/user/profile/edit'));
                                 } else {
                                     $this->redirect(array('/site/kiitos_rekisteroinnista'));
                                 }
                             }
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 25
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '';
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $post_user = $_POST['User'];
         /**
          * for customer user 
          *  - email is username
          *  - password generated
          */
         if (isset($_POST['user_type']) && $_POST['user_type'] == 'customer') {
             $post_user['username'] = $post_user['email'];
             $post_user['password'] = DbrLib::rand_string(8);
             $post_user['status'] = User::STATUS_ACTIVE;
         }
         $model->attributes = $post_user;
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 if (Yii::app()->sysCompany->getActiveCompany()) {
                     //create person
                     $model_person = new PprsPerson();
                     $model_person->pprs_first_name = $profile->first_name;
                     $model_person->pprs_second_name = $profile->last_name;
                     if (isset($post_user['ccmp_id'])) {
                         $model_person->pprs_ccmp_id = $post_user['ccmp_id'];
                     } else {
                         $model_person->pprs_ccmp_id = Yii::app()->sysCompany->getActiveCompany();
                     }
                     $model_person->save();
                 }
                 $profile->user_id = $model->id;
                 $profile->person_id = $model_person->primaryKey;
                 $profile->save();
                 /**
                  * customer user
                  * - add role user customer
                  * - redirect to view
                  */
                 if (isset($_POST['user_type']) && $_POST['user_type'] == 'customer') {
                     //add role user customer
                     $aa_model = new Authassignment();
                     $aa_model->itemname = Yii::app()->getModule('user')->customerUser['role'];
                     $aa_model->userid = $model->id;
                     $aa_model->save();
                     //redirect to view
                     $this->redirect(array('viewCustomer', 'id' => $model->id));
                 }
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     if (isset($_GET['type']) && $_GET['type'] == 'customer') {
         $this->menu_route = "user/admin/customerAdmin";
         $view = 'create_customer';
     } else {
         $view = 'create';
     }
     if (Yii::app()->getModule('user')->view) {
         $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view;
         if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) {
             $view = $alt_view;
             $this->layout = Yii::app()->getModule('user')->layout;
         }
     }
     $this->render($view, array('model' => $model, 'profile' => $profile));
 }
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUserRelatedByCreatedBy !== null) {
             if (!$this->aUserRelatedByCreatedBy->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUserRelatedByCreatedBy->getValidationFailures());
             }
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if (!$this->aUserRelatedByUpdatedBy->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUserRelatedByUpdatedBy->getValidationFailures());
             }
         }
         if ($this->aUserRelatedByDeletedBy !== null) {
             if (!$this->aUserRelatedByDeletedBy->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUserRelatedByDeletedBy->getValidationFailures());
             }
         }
         if ($this->aProfile !== null) {
             if (!$this->aProfile->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aProfile->getValidationFailures());
             }
         }
         if ($this->aStatus !== null) {
             if (!$this->aStatus->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aStatus->getValidationFailures());
             }
         }
         if ($this->aProfilePropertyRelatedByInverseProfilePropertyId !== null) {
             if (!$this->aProfilePropertyRelatedByInverseProfilePropertyId->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aProfilePropertyRelatedByInverseProfilePropertyId->getValidationFailures());
             }
         }
         if (($retval = ProfilePropertyPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collConceptPropertysRelatedBySkosPropertyId !== null) {
             foreach ($this->collConceptPropertysRelatedBySkosPropertyId as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collConceptPropertysRelatedByProfilePropertyId !== null) {
             foreach ($this->collConceptPropertysRelatedByProfilePropertyId as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSchemaPropertyElements !== null) {
             foreach ($this->collSchemaPropertyElements as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collSchemaPropertyElementHistorys !== null) {
             foreach ($this->collSchemaPropertyElementHistorys as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     Profile::$regMode = true;
     $model = new RegistrationForm();
     $profile = new Profile();
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 //$soucePassword = $model->password;
                 //$realp = PasswordHelper::generateStrongPassword();
                 //$model->password = $realp;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = PasswordHelper::hashPassword($model->password);
                 $model->verifyPassword = $model->password;
                 $model->superuser = 0;
                 $model->type = 1;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         $name = $_POST['Profile']['first_name'] . ' ' . $_POST['Profile']['last_name'];
                         UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("<div style='border: 1px solid #FCC32A;border-radius:5px;box-shadow:1px 5px 5px;background-color:#FFFFEE;'><div style='background-color:#333;border-radius:5px;padding:10px;'><img src='http://yorshop.com/img/main_logo.png' style='float:left'/><h2 style='color: #FFF;width:70%;margin-left:15%;'>Successful  Registration</h2><hr/></div><div style='padding:10px;'><p><strong>Dear {name},</strong></p><p>Thank you for registering at <a href='{site_url}' target='blank'>{site_name}</a>.</p><p>Please activate your account by clicking: <a href='{activation_url}' target='blank'>{activation_url}</a> or copy and paste it in your browser.</p><p><a href='{site_url}' target='blank' ><img src='http://yorshop.com/img/form_submit.png'/></a></p></div><div style='padding:0px 10px 0px;'><p>If you need any assistance or have any inquiry or suggestion, feel free to contact our customer service team at <a href='mailto:info@yorshop.com'>info@yorshop.com</a> or call us at <strong>0700 967 7467</strong> between 8am and 10pm on weekdays and 9am to 6pm on weekends, we would be happy to guide you.</p> <address>Thank You!<br/>Your Yorshop Team</address></div></div>", array('{activation_url}' => $activation_url, '{name}' => $name, '{site_name}' => Yii::app()->name, '{site_url}' => UtilityHelper::yiiparam('site_name'))));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         if (isset($this->location)) {
             $this->render('frontend.views.user.registration', array('model' => $model, 'profile' => $profile));
         } else {
             $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
         }
     }
 }
Exemplo n.º 28
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     Yii::import('application.modules.user.models.*');
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = 1;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     //if (Yii::app()->controller->module->sendActivationMail) {
                     //$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $model->activkey, "email" => $model->email));
                     //UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url)));
                     //}
                     // Add them to Subscribe system
                     if ($_POST['subscribe']) {
                         $email = $model->email;
                         $subscription = Subscribers::model()->find('email = :email', array(':email' => $email));
                         if (isset($subscription->id)) {
                         } else {
                             $subscription = new Subscribers();
                             $subscription->email = $email;
                             $subscription->activation = $subscription->generateActivation($email);
                             $subscription->subscribed = 1;
                             $subscription->confirmed = 0;
                             $subscription->ip_address = $_SERVER['REMOTE_ADDR'];
                             if ($subscription->save()) {
                                 $url = 'http://' . $_SERVER['HTTP_HOST'] . '/e/' . $subscription->activation;
                                 $unsub_url = 'http://' . $_SERVER['HTTP_HOST'] . '/unsub/' . $subscription->activation;
                                 $sbj = "Confirmation - XXX Coupon Daily P**n Deals";
                                 $to = array($subscription->email);
                                 $reply_hash = 'XXX Coupon Confirmation <*****@*****.**>';
                                 $mail = $this->ses;
                                 //Yii::import('application.extensions.sesmail.*');
                                 //require_once('vendors/aws-sdk/sdk.class.php');
                                 //$mail = new YiiSesMail;
                                 $mail->view = 'confirm';
                                 $mail->setBody(array('url' => $url, 'ip_address' => $subscription->ip_address, 'unsub_url' => $unsub_url));
                                 $mail->send($reply_hash, $to, $sbj);
                             }
                         }
                     }
                     if (!empty($_POST['RegistrationForm']['redirect'])) {
                         Yii::app()->user->setFlash('success', "Okay, you're set.  We are sending you off to your offer now.  Thanks for joining us!");
                         $this->redirect(urldecode($_POST['RegistrationForm']['redirect']));
                     } else {
                         Yii::app()->user->setFlash('success', "Okay, you're set.  Thank you for registering with us.  Enjoy the offers!");
                         $this->redirect('/');
                     }
                     /*if ((Yii::app()->controller->module->loginNotActiv||(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false))&&Yii::app()->controller->module->autoLogin) {
                     				$identity=new UserIdentity($model->username,$soucePassword);
                     				$identity->authenticate();
                     				Yii::app()->user->login($identity,0);
                     				$this->redirect(Yii::app()->controller->module->returnUrl);
                     		} else {
                     			if (!Yii::app()->controller->module->activeAfterRegister&&!Yii::app()->controller->module->sendActivationMail) {
                     				Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                     			} elseif(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false) {
                     				Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(UserModule::t('Login'),Yii::app()->controller->module->loginUrl))));
                     			} elseif(Yii::app()->controller->module->loginNotActiv) {
                     				Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email or login."));
                     			} else {
                     				Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email."));
                     			}
                     			$this->refresh();
                     		}*/
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/registration/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 29
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '';
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 if (Yii::app()->sysCompany->getActiveCompany()) {
                     //create person
                     $model_person = new PprsPerson();
                     $model_person->pprs_first_name = $profile->first_name;
                     $model_person->pprs_second_name = $profile->last_name;
                     $model_person->pprs_ccmp_id = Yii::app()->sysCompany->getActiveCompany();
                     $model_person->save();
                 }
                 $profile->user_id = $model->id;
                 $profile->person_id = $model_person->primaryKey;
                 $profile->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $view = 'create';
     if (Yii::app()->getModule('user')->view) {
         $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view;
         if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) {
             $view = $alt_view;
             $this->layout = Yii::app()->getModule('user')->layout;
         }
     }
     $this->render($view, array('model' => $model, 'profile' => $profile));
 }
 /**
  * @expectedException CDbException
  */
 public function testValidationBeforeSaveFail()
 {
     $model = new Profile();
     $model->owner = new User();
     $this->assertTrue($model->validate());
 }