validate() public method

Validate the form
public validate ( )
Exemplo n.º 1
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         //echo UActiveForm::validate(array($model, $profile));
         $model->validate();
         $model->getErrors();
         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()) {
                 $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, t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url, '{username}' => $model->username, '{password}' => $model->password, '{site_name}' => Yii::app()->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', 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', t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             }
             // else
             //$profile->validate();
         }
         $this->render('/user/registration', array('model' => $model));
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     if (Yii::app()->user->isAuthenticated()) {
         $this->controller->redirect(Yii::app()->user->returnUrl);
     }
     $module = Yii::app()->getModule('user');
     if ($module->registrationDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     $form = new RegistrationForm();
     $event = new CModelEvent($this->controller, array("registrationForm" => $form));
     $module->onBeginRegistration($event);
     if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if ($user = Yii::app()->userManager->createUser($form)) {
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Account was created! Check your email!'));
                 $module->onSuccessRegistration(new CModelEvent($this->controller, array("user" => $user)));
                 $this->controller->redirect(array($module->registrationSuccess));
             }
             $module->onErrorRegistration(new CModelEvent($this->controller, array("registrationForm" => $form)));
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error creating account!'));
         }
         $module->onErrorRegistration(new CModelEvent($this->controller, array("registrationForm" => $form)));
     }
     $this->controller->render('registration', array('model' => $form, 'module' => $module));
 }
Exemplo n.º 3
0
 /**
  * Validate user registration information and register new user.
  */
 function registerUser($args, &$request)
 {
     $this->validate($request);
     import('classes.user.form.RegistrationForm');
     $regForm = new RegistrationForm();
     $regForm->readInputData();
     if ($regForm->validate()) {
         $regForm->execute();
         if (Config::getVar('email', 'require_validation')) {
             // Send them home; they need to deal with the
             // registration email.
             $request->redirect(null, 'index');
         }
         $reason = null;
         Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
         if ($reason !== null) {
             $this->setupTemplate($request, true);
             $templateMgr =& TemplateManager::getManager();
             $templateMgr->assign('pageTitle', 'user.login');
             $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason');
             $templateMgr->assign('errorParams', array('reason' => $reason));
             $templateMgr->assign('backLink', $request->url('login'));
             $templateMgr->assign('backLinkLabel', 'user.login');
             return $templateMgr->display('common/error.tpl');
         }
         if ($source = $request->getUserVar('source')) {
             $request->redirectUrl($source);
         } else {
             $request->redirect('login');
         }
     } else {
         $this->setupTemplate($request, true);
         $regForm->display();
     }
 }
	/**
	 * 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.º 5
0
 /**
  * @throws CHttpException
  */
 public function run()
 {
     if (false === Yii::app()->getUser()->getIsGuest()) {
         $this->getController()->redirect(\yupe\helpers\Url::redirectUrl(Yii::app()->getModule('user')->loginSuccess));
     }
     $module = Yii::app()->getModule('user');
     if ($module->registrationDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     $form = new RegistrationForm();
     if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if ($user = Yii::app()->userManager->createUser($form)) {
                 if (!$module->emailAccountVerification) {
                     $this->autoLoginUser($form);
                 }
                 Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Account was created! Check your email!'));
                 $this->getController()->redirect(Url::redirectUrl($module->registrationSuccess));
             }
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error creating account!'));
         }
     }
     $this->getController()->render('registration', ['model' => $form, 'module' => $module]);
 }
 /**
  * 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()
 {
     $profile = new User();
     $model = new RegistrationForm();
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo CActiveForm::validate(array($model, $profile), array('email', 'username'));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm']) && isset($_POST['User'])) {
             $profile->attributes = $_POST['User'];
             $model->attributes = $_POST['RegistrationForm'];
             if ($model->validate() && $profile->validate()) {
                 $profile->role = User::ROLE_MEMBER;
                 if ($profile->save()) {
                     $model->user_id = $profile->user_id;
                     $soucePassword = $model->password;
                     $model->password = UserModule::encrypting($model->password);
                     $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                     $model->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))); }
                      */
                     $identity = new UserIdentity($model->username, $soucePassword);
                     $identity->authenticate();
                     Yii::app()->user->login($identity, 0);
                     $this->redirect(Yii::app()->controller->module->loginUrl);
                     /*
                      * 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();
                 $model->validate();
             }
         }
         $this->render('/user/registration', array('login' => $model, 'model' => $profile));
     }
 }
Exemplo n.º 8
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.º 9
0
 public function run()
 {
     $form = new RegistrationForm();
     if (Yii::app()->request->isPostRequest && !empty($_POST['RegistrationForm'])) {
         $module = Yii::app()->getModule('user');
         $form->setAttributes($_POST['RegistrationForm']);
         // проверка по "черным спискам"
         // проверить на email
         if (!$module->isAllowedEmail($form->email)) {
             // перенаправить на экшн для фиксации невалидных email-адресов
             $this->controller->redirect(array(Yii::app()->getModule('user')->invalidEmailAction));
         }
         if (!$module->isAllowedIp(Yii::app()->request->userHostAddress)) {
             // перенаправить на экшн для фиксации невалидных ip-адресов
             $this->controller->redirect(array(Yii::app()->getModule('user')->invalidIpAction));
         }
         if ($form->validate()) {
             // если требуется активация по email
             if ($module->emailAccountVerification) {
                 $registration = new Registration();
                 // скопируем данные формы
                 $registration->setAttributes($form->getAttributes());
                 if ($registration->save()) {
                     // отправка email с просьбой активировать аккаунт
                     $mailBody = $this->controller->renderPartial('application.modules.user.views.email.needAccountActivationEmail', array('model' => $registration), true);
                     Yii::app()->mail->send($module->notifyEmailFrom, $registration->email, Yii::t('user', 'Регистрация на сайте {site} !', array('{site}' => Yii::app()->name)), $mailBody);
                     // запись в лог о создании учетной записи
                     Yii::log(Yii::t('user', "Создана учетная запись {nick_name}!", array('{nick_name}' => $registration->nick_name)), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Учетная запись создана! Инструкции по активации аккаунта отправлены Вам на email!'));
                     $this->controller->refresh();
                 } else {
                     $form->addErrors($registration->getErrors());
                     Yii::log(Yii::t('user', "Ошибка при создании  учетной записи!"), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 }
             } else {
                 // если активации не требуется - сразу создаем аккаунт
                 $user = new User();
                 $user->createAccount($form->nick_name, $form->email, $form->password);
                 if ($user && !$user->hasErrors()) {
                     Yii::log(Yii::t('user', "Создана учетная запись {nick_name} без активации!", array('{nick_name}' => $user->nick_name)), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     // отправить email с сообщением о успешной регистрации
                     $emailBody = $this->controller->renderPartial('application.modules.user.views.email.accountCreatedEmail', array('model' => $user), true);
                     Yii::app()->mail->send($module->notifyEmailFrom, $user->email, Yii::t('user', 'Регистрация на сайте {site} !', array('{site}' => Yii::app()->name)), $emailBody);
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Учетная запись создана! Пожалуйста, авторизуйтесь!'));
                     $this->controller->redirect(array('/user/account/login/'));
                 } else {
                     $form->addErrors($user->getErrors());
                     Yii::log(Yii::t('user', "Ошибка при создании  учетной записи без активации!"), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 }
             }
         }
     }
     $this->controller->render('registration', array('model' => $form));
 }
Exemplo n.º 10
0
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (!empty($_POST['RegistrationForm'])) {
         $model->attributes = $_POST['RegistrationForm'];
         if ($model->validate()) {
             if (User::model()->exists('email=:email and status!=:status', array(':email' => $model->email, ':status' => L::r_item('userStatus', 'not_active')))) {
                 $model->addError('email', 'Пользователь с таким почтовым адресом уже зарегестрирован в нашей системе.');
             } else {
                 // регистрация пошла, отпраляю почту и создаю пользователя со статусом "не активен"
                 Yii::import('ext.yii-mail.*');
                 $message = new YiiMailMessage();
                 $message->view = 'email_confirmation';
                 $message->setBody(array('hash' => sha1($model->email . Yii::app()->params['salt']), 'email' => $model->email, 'date' => date('YmdHis')), 'text/html');
                 $message->subject = Yii::app()->name . ' - Подтверждение почтового адреса/E-mail confirmation';
                 $message->addTo($model->email);
                 $message->from = Yii::app()->params['registrationEmail'];
                 if (Yii::app()->mail->send($message)) {
                     if (!($user = User::model()->find('email=:email', array(':email' => $model->email)))) {
                         $user = new User();
                     } else {
                         # надо удалить потеряного клиента
                         Client::model()->deleteByPk($user->username);
                     }
                     $user->username = $model->username;
                     $user->password = $model->password;
                     $user->password_confirm = $model->password_confirm;
                     $user->created = date('Y-m-d H:i:s');
                     $user->email = $model->email;
                     $user->city = $model->city;
                     $user->name = $model->name;
                     $user->status = L::r_item('userStatus', 'not_active');
                     if ($user->save()) {
                         if (!($client = Client::model()->find('username=:username', array(':username' => $user->username)))) {
                             $client = new Client();
                         }
                         # Добавляю клиента
                         $client->attributes = $model->attributes;
                         $client->card = Client::model()->find(array('select' => 'max(card) as maxCardNumber'))->maxCardNumber + 1;
                         $client->save();
                         Yii::app()->user->setFlash('registration', 'На указанный Вами e-mail было отправленно письмо с кодом подтверждения. Введите его.');
                         $this->redirect(array('users/confirmation'));
                     }
                 } else {
                     $model->addError('email', 'Мы не можем отправить почту на указаный Вами адрес.');
                 }
             }
         }
     }
     $model->password = null;
     $model->password_confirm = null;
     $this->render('registration', array('registration_form' => $model));
 }
 /**
  * Validate user registration information and register new user.
  * @param $args array
  * @param $request PKPRequest
  */
 function registerUser($args, &$request)
 {
     $this->validate($request);
     $this->setupTemplate($request, true);
     import('classes.user.form.RegistrationForm');
     if (checkPhpVersion('5.0.0')) {
         // WARNING: This form needs $this in constructor
         $regForm = new RegistrationForm();
     } else {
         $regForm =& new RegistrationForm();
     }
     $regForm->readInputData();
     if ($regForm->validate()) {
         $regForm->execute();
         $reason = null;
         if (Config::getVar('security', 'implicit_auth')) {
             Validation::login('', '', $reason);
         } else {
             Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
         }
         if (!Validation::isLoggedIn()) {
             if (Config::getVar('email', 'require_validation')) {
                 // Inform the user that they need to deal with the
                 // registration email.
                 $this->setupTemplate($request, true);
                 $templateMgr =& TemplateManager::getManager();
                 $templateMgr->assign('pageTitle', 'user.register.emailValidation');
                 $templateMgr->assign('errorMsg', 'user.register.emailValidationDescription');
                 $templateMgr->assign('backLink', $request->url(null, 'login'));
                 $templateMgr->assign('backLinkLabel', 'user.login');
                 return $templateMgr->display('common/error.tpl');
             }
         }
         if ($reason !== null) {
             $this->setupTemplate($request, true);
             $templateMgr =& TemplateManager::getManager();
             $templateMgr->assign('pageTitle', 'user.login');
             $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason');
             $templateMgr->assign('errorParams', array('reason' => $reason));
             $templateMgr->assign('backLink', $request->url(null, 'login'));
             $templateMgr->assign('backLinkLabel', 'user.login');
             return $templateMgr->display('common/error.tpl');
         }
         if ($source = $request->getUserVar('source')) {
             $request->redirectUrl($source);
         } else {
             $request->redirect(null, 'login');
         }
     } else {
         $regForm->display();
     }
 }
Exemplo n.º 12
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.º 13
0
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     if (($uid = Yii::app()->user->id) === true) {
         $this->redirect(Yii::app()->homeUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             //$profile->attributes=$_POST['Profile'];
             if ($model->validate() && $profile->validate()) {
                 $sourcePassword = $model->password;
                 $model->password = Yii::app()->user->encrypt($model->password);
                 $model->verifyPassword = Yii::app()->user->encrypt($model->verifyPassword);
                 $model->activkey = Yii::app()->user->encrypt(microtime() . $model->password);
                 $model->createtime = time();
                 $model->lastvisit = Yii::app()->user->autoLogin && Yii::app()->user->loginNotActive ? time() : 0;
                 $model->superuser = 0;
                 $model->status = 0;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     $headers = "From: " . Yii::app()->params['adminEmail'] . "\r\nReply-To: " . Yii::app()->params['adminEmail'];
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl('user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     mail($model->email, "You registered from " . Yii::app()->name, "Please activate your account go to {$activation_url}.", $headers);
                     if (Yii::app()->user->loginNotActive) {
                         if (Yii::app()->user->autoLogin) {
                             $identity = new UserIdentity($model->username, $sourcePassword);
                             $identity->authenticate();
                             Yii::app()->user->login($identity, 0);
                             $this->redirect(Yii::app()->user->returnUrl);
                         } else {
                             Yii::app()->user->setFlash('registration', Yii::t("user", "Thank you for your registration. Please check your email or login."));
                             $this->refresh();
                         }
                     } else {
                         Yii::app()->user->setFlash('registration', Yii::t("user", "Thank you for your registration. Please check your email."));
                         $this->refresh();
                     }
                 }
             }
         }
         $this->render('/user/registration', array('form' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 14
0
 /**
  * Validate user registration information and register new user.
  * @param $args array
  * @param $request PKPRequest
  */
 function registerUser($args, $request)
 {
     $this->validate($request);
     $this->setupTemplate($request);
     import('lib.pkp.classes.user.form.RegistrationForm');
     $regForm = new RegistrationForm($request->getSite());
     $regForm->readInputData();
     if (!$regForm->validate()) {
         return $regForm->display($request);
     }
     $regForm->execute($request);
     // Inform the user of the email validation process. This must be run
     // before the disabled account check to ensure new users don't see the
     // disabled account message.
     if (Config::getVar('email', 'require_validation')) {
         $this->setupTemplate($request);
         $templateMgr = TemplateManager::getManager($request);
         $templateMgr->assign('requireValidation', true);
         $templateMgr->assign('pageTitle', 'user.login.registrationPendingValidation');
         $templateMgr->assign('messageTranslated', __('user.login.accountNotValidated', array('email' => $regForm->getData('email'))));
         return $templateMgr->fetch('frontend/pages/message.tpl');
     }
     $reason = null;
     if (Config::getVar('security', 'implicit_auth')) {
         Validation::login('', '', $reason);
     } else {
         Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
     }
     if ($reason !== null) {
         $this->setupTemplate($request);
         $templateMgr = TemplateManager::getManager($request);
         $templateMgr->assign('pageTitle', 'user.login');
         $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason');
         $templateMgr->assign('errorParams', array('reason' => $reason));
         $templateMgr->assign('backLink', $request->url(null, 'login'));
         $templateMgr->assign('backLinkLabel', 'user.login');
         return $templateMgr->fetch('frontend/pages/error.tpl');
     }
     if ($source = $request->getUserVar('source')) {
         return $request->redirectUrlJson($source);
     } else {
         $request->redirect(null, 'user', 'registrationComplete');
     }
 }
Exemplo n.º 15
0
 public function run()
 {
     $module = Yii::app()->getModule('user');
     if ($module->registrationDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     $form = new RegistrationForm('default');
     if (($data = Yii::app()->getRequest()->getPost('RegistrationForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate()) {
             if ($user = Yii::app()->userManager->createUser($form)) {
                 $paramModel = Yii::app()->request->getParam('model', null);
                 $paramExternalId = Yii::app()->request->getParam('external_id', null);
                 if (!is_null($paramModel) && !is_null($paramExternalId)) {
                     $Response = Response::createResponseByOtherModelData($paramModel, $paramExternalId);
                     if (!is_null($Response)) {
                         if ($Response->save()) {
                             $this->getController()->render('successRegister', ['model' => $paramModel, 'external_id' => $paramExternalId, 'response_id' => $Response->primaryKey]);
                             Yii::app()->end();
                         } else {
                             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => print_r($Response->getErrors(), true)]));
                         }
                     } else {
                         Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('default', 'Ошибка создания заказа, errmsgcreate', ['errmsgcreate' => "Can't create Response by createResponseByOtherModelData"]));
                     }
                 } else {
                     //								Yii::app()->authenticationManager->logout(Yii::app()->getUser());
                     Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Аккаунт создан! По указаному адресу email Вам отправлена сслыка для активации Вашего "Личного кабинета"!'));
                     Yii::app()->session['success_reg'] = true;
                     $this->getController()->redirect(Url::redirectUrl('/cabinet'));
                 }
             }
             Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Не удалось зарегистрировать!'));
         }
     }
     $form->prefphone = '+7';
     $this->getController()->render('registration', ['model' => $form, 'module' => $module]);
 }
Exemplo n.º 16
0
 /**
  * Validate user registration information and register new user.
  * @param $args array
  * @param $request PKPRequest
  */
 function registerUser($args, $request)
 {
     $this->validate($request);
     $this->setupTemplate($request);
     import('lib.pkp.classes.user.form.RegistrationForm');
     $regForm = new RegistrationForm($request->getSite());
     $regForm->readInputData();
     if (!$regForm->validate()) {
         return new JSONMessage(true, $regForm->fetch($request));
     }
     $regForm->execute($request);
     if (Config::getVar('email', 'require_validation')) {
         // Send them home; they need to deal with the
         // registration email.
         return $request->redirectUrlJson($request->url(null, 'index'));
     }
     $reason = null;
     if (Config::getVar('security', 'implicit_auth')) {
         Validation::login('', '', $reason);
     } else {
         Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
     }
     if ($reason !== null) {
         $this->setupTemplate($request);
         $templateMgr = TemplateManager::getManager($request);
         $templateMgr->assign('pageTitle', 'user.login');
         $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason');
         $templateMgr->assign('errorParams', array('reason' => $reason));
         $templateMgr->assign('backLink', $request->url(null, 'login'));
         $templateMgr->assign('backLinkLabel', 'user.login');
         return $templateMgr->fetchJson('frontend/pages/error.tpl');
     }
     if ($source = $request->getUserVar('source')) {
         return $request->redirectUrlJson($source);
     }
     return $request->redirectUrlJson($request->getRouter()->getHomeUrl($request));
 }
 /**
  * Validate user registration information and register new user.
  */
 function registerUser($args, &$request)
 {
     $this->validate();
     $this->setupTemplate(true);
     import('classes.user.form.RegistrationForm');
     //%CBP% get registration criteria, if defined
     $journal =& Request::getJournal();
     $CBPPlatformDao =& DAORegistry::getDAO('CBPPlatformDAO');
     $templateMgr =& TemplateManager::getManager();
     $registrationCriteria = $CBPPlatformDao->getRegistrationCriteria($journal->getId());
     $templateMgr->assign('registrationCriteria', $registrationCriteria);
     if ($registrationCriteria != null) {
         if (Request::getUserVar('registrationCriteria') == 1) {
             $reason = null;
             $templateMgr->assign('registrationCriteriaChecked', 1);
         } else {
             $reason = 1;
             $templateMgr->assign('registrationCriteriaReqd', 1);
         }
     }
     if (checkPhpVersion('5.0.0')) {
         // WARNING: This form needs $this in constructor
         $regForm = new RegistrationForm();
     } else {
         $regForm =& new RegistrationForm();
     }
     $regForm->readInputData();
     if ($regForm->validate()) {
         $regForm->execute();
         if (Config::getVar('email', 'require_validation')) {
             // Send them home; they need to deal with the
             // registration email.
             Request::redirect(null, 'index');
         }
         $reason = null;
         if (Config::getVar('security', 'implicit_auth')) {
             Validation::login('', '', $reason);
         } else {
             Validation::login($regForm->getData('username'), $regForm->getData('password'), $reason);
         }
         if ($reason !== null) {
             $this->setupTemplate(true);
             $templateMgr =& TemplateManager::getManager();
             $templateMgr->assign('pageTitle', 'user.login');
             $templateMgr->assign('errorMsg', $reason == '' ? 'user.login.accountDisabled' : 'user.login.accountDisabledWithReason');
             $templateMgr->assign('errorParams', array('reason' => $reason));
             $templateMgr->assign('backLink', Request::url(null, 'login'));
             $templateMgr->assign('backLinkLabel', 'user.login');
             return $templateMgr->display('common/error.tpl');
         }
         if ($source = Request::getUserVar('source')) {
             Request::redirectUrl($source);
         } else {
             Request::redirect(null, 'login');
         }
     } else {
         $regForm->display();
     }
 }
Exemplo n.º 18
0
{
    $file = "classes" . DIRECTORY_SEPARATOR . "{$className}.php";
    require_once $file;
}
//параметры для подключения к базе данных
$db_host = 'localhost';
$db_user = '******';
$db_password = '';
$db_name = 'regform';
$msg = '';
//обьект базы данных
$db = new DB($db_host, $db_user, $db_password, $db_name);
//обьект формы
$form = new RegistrationForm($_POST);
if ($_POST) {
    if ($form->validate()) {
        $email = $db->escape($form->getEmail());
        $username = $db->escape($form->getUsername());
        $password = new Password($db->escape($form->getPassword()));
        $res = $db->query("SELECT * FROM users WHERE username = '******'");
        if ($res) {
            $msg = 'Such user already exists!';
        } else {
            $db->query("INSERT INTO users (email, username, password) VALUES ('{$email}','{$username}','{$password}')");
            header('location: index.php?msg=You have been registered');
        }
    } else {
        $msg = $form->passwordsMatch() ? 'Please fill in fields' : 'Passwords don\'t match';
    }
}
?>
Exemplo n.º 19
0
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $this->redirect(Yii::app()->controller->module->returnUrl);
     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'])) {
             $RegistrationForm = $_POST['RegistrationForm'];
             $model->attributes = $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;
                 $model->create_at = date('Y-m-d H:i:s');
                 //添加推荐人ID
                 $model->recommend = $RegistrationForm['recommend'] != "用户名/手机号" ? $RegistrationForm['recommend'] : "";
                 if ($RegistrationForm['recommend'] && $RegistrationForm['recommend'] != "用户名/手机号") {
                     $recommend = $RegistrationForm['recommend'];
                     if (is_numeric($recommend)) {
                         $recomID = $this->getRecommendByPhone($recommend);
                     } else {
                         $recomID = $this->getRecommendByName($recommend);
                     }
                     $model->recomID = $recomID;
                 }
                 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->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('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 20
0
 /**
  * Save changes to a registration.
  */
 function updateRegistration($args, &$request)
 {
     $this->validate();
     $this->setupTemplate($request);
     import('classes.registration.form.RegistrationForm');
     $schedConf =& $request->getSchedConf();
     $registrationId = $request->getUserVar('registrationId') == null ? null : (int) $request->getUserVar('registrationId');
     $registrationDao = DAORegistry::getDAO('RegistrationDAO');
     if ($registrationId != null && $registrationDao->getRegistrationSchedConfId($registrationId) == $schedConf->getId() || $registrationId == null) {
         $registrationForm = new RegistrationForm($registrationId);
         $registrationForm->readInputData();
         if ($registrationForm->validate()) {
             $registrationForm->execute();
             if ($request->getUserVar('createAnother')) {
                 $request->redirect(null, null, null, 'selectRegistrant', null, array('registrationCreated', 1));
             } else {
                 $request->redirect(null, null, null, 'registration');
             }
         } else {
             $templateMgr =& TemplateManager::getManager($request);
             $templateMgr->append('pageHierarchy', array($request->url(null, null, 'manager', 'registration'), 'manager.registration'));
             if ($registrationId == null) {
                 $templateMgr->assign('registrationTitle', 'manager.registration.createTitle');
             } else {
                 $templateMgr->assign('registrationTitle', 'manager.registration.editTitle');
             }
             $registrationForm->display();
         }
     } else {
         $request->redirect(null, null, null, 'registration');
     }
 }
 /**
  * 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));
     }
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (isset($_GET['role']) && $_GET['role'] == 'Customer') {
         $role = 'Customer';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') {
         $role = 'Author';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') {
         $role = 'Manager';
     } else {
         $role = 'Customer';
     }
     if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             if ($model->validate()) {
                 $soucePassword = $this->generate_password(8);
                 $model->password = UserModule::encrypting($soucePassword);
                 $model->superuser = 0;
                 $model->status = 1;
                 $model->username = $model->email;
                 if ($model->save()) {
                     $AuthAssignment = new AuthAssignment();
                     $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id);
                     $AuthAssignment->save();
                     //$login_url = '<a href="'.$this->createAbsoluteUrl('/user/login').'">'.Yii::app()->name.'</a>';
                     //UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}",array('{login_url}'=>$login_url, '{pass}'=>$soucePassword)));
                     // новая служба системных сообщений
                     $type_id = Emails::TYPE_11;
                     $email = new Emails();
                     $criteria = new CDbCriteria();
                     $criteria->order = 'id DESC';
                     $criteria->limit = 1;
                     $user = User::model()->findAll($criteria);
                     $user = $user[0];
                     $email->from_id = 1;
                     $email->to_id = $user->id;
                     $rec = Templates::model()->findAll("`type_id`='{$type_id}'");
                     $title = $rec[0]->title;
                     $body = $rec[0]->text;
                     $id = Campaign::getId();
                     $email->campaign = Campaign::getName();
                     $email->name = $model->full_name;
                     $email->login = $model->username;
                     $email->password = $soucePassword;
                     $email->page_cabinet = 'http://' . $_SERVER['SERVER_NAME'] . '/user/profile/edit';
                     $email->sendTo($user->email, $body, $type_id);
                     $identity = new UserIdentity($model->username, $soucePassword);
                     $identity->authenticate();
                     Yii::app()->user->login($identity, 0);
                     //$this->redirect(Yii::app()->controller->module->returnUrl);
                     Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{email}}) before start.", ['{{email}}' => $model->email]));
                     $this->refresh();
                     //Yii::app()->end();
                 } else {
                     Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :("));
                     $this->refresh();
                 }
             }
         }
         Yii::app()->theme = 'client';
         $this->render('/user/registration', array('model' => $model, 'role' => $role));
     }
 }
Exemplo n.º 23
0
 public function actionPromo($cat = null)
 {
     $link = '';
     Yii::import('application.modules.user.forms.*');
     $model = new \RegistrationForm('promoReg');
     $category = \StoreCategory::model()->findByPk($cat);
     if ($category) {
         $link = '/store' . \Product::model()->linkBuilder($category, $link);
     } else {
         $link = '#';
     }
     if (Yii::app()->getRequest()->getPost('RegistrationForm')) {
         $model->setAttributes(Yii::app()->getRequest()->getPost('RegistrationForm'));
         if ($model->validate()) {
             if ($user = Yii::app()->userManager->createUser($model)) {
                 \Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, \Yii::t('UserModule.user', 'Аккаунт создан! Проверьте свой email!'));
                 Yii::app()->session['success_reg'] = true;
             }
             $this->redirect('/site/index');
         }
     }
     $this->layout = 'promo';
     $this->render('promo', ['category' => $category, 'link' => $link, 'model' => $model]);
 }
Exemplo n.º 24
0
 /**
  * Registers new member
  */
 public function actionRegister()
 {
     // is current user has the required privilege ?
     if (!Yii::app()->user->checkAccess('site_register')) {
         throw new CHttpException(403, 'You are not authorized to perform this action.');
     }
     $registration = new RegistrationForm();
     // collect user input data
     if (isset($_POST['RegistrationForm'])) {
         $registration->attributes = $_POST['RegistrationForm'];
         print_r($_POST['RegistrationForm']);
         // validate user input and redirect to the previous page if valid
         if ($registration->validate()) {
             $member = new Member();
             $member->attributes = $registration->attributes;
             if ($member->save()) {
                 // create an account model
                 $account = new Account();
                 $account->username = $registration->username;
                 $account->password = $registration->password;
                 $account->id_member = $member->id;
                 if ($account->save()) {
                     $auth = Yii::app()->authManager;
                     $auth->assign('member', (int) $account->id);
                     // redirects to index page
                     //$this->redirect(array('index'));
                 } else {
                     // what's wrong? get the error message
                     $registration->addErrors($member->getErrors());
                 }
             } else {
                 // what's wrong? get the error message
                 $registration->addErrors($account->getErrors());
             }
         }
     }
     // display the registration form
     $this->render('register', array('model' => $registration));
 }
Exemplo n.º 25
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.º 26
0
    /**
     * Registration user
     */
    public function actionRegistration()
    {
        $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 = 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));
                            $messageText = '<b>Welcome to instanttop!</b><br><br>
										Click on this link 
							<p><a href="' . $activation_url . '">' . $activation_url . '</a></p>
							<p>to activate your account or copy and paste the link into a
								browser. Dont forget your Login name is your user name or your E-mail.
								We are always here to help you can contact our customer care
								team via email 24 hours a day</p> 
							<p>Kind regards,<br>
							Your' . Yii::app()->name . ' team </p>';
                            UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), $messageText);
                        }
                        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('/user/registration', array('model' => $model, 'profile' => $profile));
        }
    }
 /**
  * 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()
 {
     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.º 29
0
 /**
  * Save changes to a registration.
  */
 function updateRegistration()
 {
     $this->validate();
     $this->setupTemplate();
     import('registration.form.RegistrationForm');
     $schedConf =& Request::getSchedConf();
     $registrationId = Request::getUserVar('registrationId') == null ? null : (int) Request::getUserVar('registrationId');
     $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
     if ($registrationId != null && $registrationDao->getRegistrationSchedConfId($registrationId) == $schedConf->getId() || $registrationId == null) {
         if (checkPhpVersion('5.0.0')) {
             // WARNING: This form needs $this in constructor
             $registrationForm = new RegistrationForm($registrationId);
         } else {
             $registrationForm =& new RegistrationForm($registrationId);
         }
         $registrationForm->readInputData();
         if ($registrationForm->validate()) {
             $registrationForm->execute();
             if (Request::getUserVar('createAnother')) {
                 Request::redirect(null, null, null, 'selectRegistrant', null, array('registrationCreated', 1));
             } else {
                 Request::redirect(null, null, null, 'registration');
             }
         } else {
             $templateMgr =& TemplateManager::getManager();
             $templateMgr->append('pageHierarchy', array(Request::url(null, null, 'manager', 'registration'), 'manager.registration'));
             if ($registrationId == null) {
                 $templateMgr->assign('registrationTitle', 'manager.registration.createTitle');
             } else {
                 $templateMgr->assign('registrationTitle', 'manager.registration.editTitle');
             }
             $registrationForm->display();
         }
     } else {
         Request::redirect(null, null, null, 'registration');
     }
 }
Exemplo n.º 30
0
 /**
  * Страница авторизации/регистрации
  */
 public function actionLogin()
 {
     $model = new UserLogin();
     $registration_form = new RegistrationForm();
     $user_recovery_form = new UserRecoveryForm();
     // if it is ajax validation request
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['UserLogin'])) {
         $model->attributes = $_POST['UserLogin'];
         if ($model->validate()) {
             //print_r($model->attributes);die;
             $this->lastViset();
             $this->redirect(array('my/index'));
         }
     }
     if (isset($_POST['RegistrationForm'])) {
         $registration_form->attributes = $_POST['RegistrationForm'];
         $registration_form->username = $registration_form->email;
         if ($registration_form->validate()) {
             $soucePassword = $registration_form->password;
             $registration_form->activkey = UserModule::encrypting(microtime() . $registration_form->password);
             $registration_form->password = UserModule::encrypting($registration_form->password);
             $registration_form->verifyPassword = UserModule::encrypting($registration_form->verifyPassword);
             $registration_form->superuser = 0;
             $registration_form->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
             if ($registration_form->save()) {
                 $activation_url = $this->createAbsoluteUrl('site/activation', array("activkey" => $registration_form->activkey, "email" => $registration_form->email));
                 //UserModule::sendMail($registration_form->email,UserModule::t("Вы зарегистрировались на сайте {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Для активации вашего аккаунта, перейдите пожалуста по ссылке {activation_url}",array('{activation_url}'=>$activation_url)));
                 UserModule::sendMail($registration_form->email, UserModule::t("Вы зарегистрировались на сайте {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Здравствуйте. Благодарим Вас за регистрацию на сервисе сохранения закладок " . Yii::app()->name . ". Для активации аккаунта перейдите по ссылке.<br> {activation_url}", array('{activation_url}' => $activation_url)));
                 return $this->redirect(array('site/regsuccess'));
             }
         }
     }
     if (isset($_POST['UserRecoveryForm'])) {
         $user_recovery_form->attributes = $_POST['UserRecoveryForm'];
         if ($user_recovery_form->validate()) {
             $user = User::model()->notsafe()->findbyPk($user_recovery_form->user_id);
             //$activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->createUrl(implode(array("/user/recovery")),array("activkey" => $user->activkey, "email" => $user->email));
             $activation_url = $this->createAbsoluteUrl('site/recovery', array("activkey" => $user->activkey, "email" => $user->email));
             $subject = UserModule::t("Запрос на восстановление пароля на сайте {site_name}", array('{site_name}' => Yii::app()->name));
             $message = UserModule::t("Вы запросили восстановление пароля на сайте {site_name}. Для получения нового пароля, перейдите по ссылке <br> {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
             UserModule::sendMail($user->email, $subject, $message);
             Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Ссылка на восстановление пароля<br>отправлена на вашу почту."));
             $this->refresh();
         }
     }
     $this->render('login', array('model' => $model, 'registration_form' => $registration_form, 'user_recovery_form' => $user_recovery_form));
 }