/**
	 * 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.º 2
0
 /**
  * Activation d'un compte utilisateur. En principe on arrive ici avec une url d'activation
  * qui a été fournie par mail à l'utilisateur
  */
 public function actionActivation()
 {
     $email = trim($_GET['email']);
     $activkey = trim($_GET['activkey']);
     if ($email && $activkey) {
         /** @var User $user */
         $user = User::model()->findByAttributes(array('email' => $email));
         if (isset($user) && $user->status) {
             // compte déjà activé
             $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Your account is already active")));
         } elseif (isset($user) && isset($user->activkey) && $user->activkey == $activkey) {
             // on enregistre une nouvelle clé d'activation pour éviter une activation parasite sur ce compte par la suite
             $user->activkey = UserModule::encrypting(microtime());
             // activation du compte
             $user->status = 1;
             if (!$user->save()) {
                 $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "The activation has failed. Please contact the administrator")));
             } else {
                 $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Your account has been successfully activated")));
             }
         } else {
             // erreur : utilisateur inconnu, clé d'activation incorrecte...
             $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Incorrect activation URL")));
         }
     } else {
         // erreur sur les paramètres du $_GET
         $this->render('/user/message', array('title' => Yii::t("UserModule.user", "User activation"), 'content' => Yii::t("UserModule.msg", "Incorrect activation URL")));
     }
 }
Exemplo n.º 3
0
	/**
	 * Activation user account
	 */
	public function actionActivation () {
		$email = $_GET['email'];
		$activkey = $_GET['activkey'];
		if ($email&&$activkey) {
			$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
			if (isset($find)&&$find->status) {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is active.")));
			} elseif(isset($find->activkey) && ($find->activkey==$activkey)) {
				$find->activkey = UserModule::encrypting(microtime());
				$find->status = 1;
				$find->save();
                if (!Yii::app()->controller->module->autoLogin) {
                    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated.")));
                } else {
                    $identity=new UserIdentity($find->username, '');
                    $identity->authenticate(true);
                    Yii::app()->user->login($identity,0);
                    Yii::app()->user->setFlash('userActivationSuccess', UserModule::t("You account is activated."));
                    $this->redirect(Yii::app()->controller->module->returnUrl);
                }
			} else {
			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
			}
		} else {
			$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
		}
	}
Exemplo n.º 4
0
 /**
  * Authenticates a user.
  * The example implementation makes sure if the username and password
  * are both 'demo'.
  * In practical applications, this should be changed to authenticate
  * against some persistent user identity storage (e.g. database).
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     if (strpos($this->username, "@")) {
         $user = User::model()->notsafe()->findByAttributes(array('email' => $this->username));
     } else {
         $user = User::model()->notsafe()->findByAttributes(array('username' => $this->username));
     }
     if ($user === null) {
         if (strpos($this->username, "@")) {
             $this->errorCode = self::ERROR_EMAIL_INVALID;
         } else {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         }
     } else {
         if (UserModule::encrypting($this->password) !== $user->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             if ($user->status == 0) {
                 $this->errorCode = self::ERROR_STATUS_NOTACTIV;
             } else {
                 if ($user->status == -1) {
                     $this->errorCode = self::ERROR_STATUS_BAN;
                 } else {
                     $this->_id = $user->id;
                     if (!$this->username) {
                         $this->username = $user->username;
                     }
                     $this->errorCode = self::ERROR_NONE;
                 }
             }
         }
     }
     return !$this->errorCode;
 }
	/**
	 * Recovery password
	 */
	public function actionRecovery () {
		$form = new UserRecoveryForm;
		if (Y::userId()) {
    		$this->redirect(Y::module()->returnUrl);
			Y::end();
		}

		$email = isset($_GET['email']) ? $_GET['email'] : '';
		$activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
		if ($email&&$activkey) {	//get new pass
			
			$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
    		if(isset($find)&&$find->activkey==$activkey) {
				$form2 = new UserChangePassword;
    			if(isset($_POST['UserChangePassword'])) {
					$form2->attributes=$_POST['UserChangePassword'];
					if($form2->validate()) {
						$find->password = UserModule::encrypting($form2->password);
						if ($find->status==0) {
							$find->status = 1;
						}
						$find->save();
						Y::flash('recoveryMessage',Users::t("New password is saved."));
						$this->redirect(Y::module()->recoveryUrl);
					}
				} 
				$this->render('changepassword',array('form'=>$form2));
    		} else {
    			Y::flash('recoveryMessage',Users::t("Incorrect recovery link."));
				$this->redirect(Y::module()->recoveryUrl);
    		}
    	} else {	//send email
	    	if(isset($_POST['UserRecoveryForm'])) {
	    		$form->attributes=$_POST['UserRecoveryForm'];
	    		
	    		if($form->validate()) {
	    			$user = User::model()->notsafe()->findbyPk($form->user_id);
	    			$user->activkey = Y::module()->encrypting(microtime().$user->password);	
	    			$user->save();
	    			$activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->siteUrl('user/recovery',array("activkey" => $user->activkey, "email" => urldecode($user->email)));
					
					$subject = Users::t("You have requested the password recovery site {site_name}",
	    					array(
	    						'{site_name}'=>Yii::app()->name,
	    					));
	    			$message = Users::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.",
	    					array(
	    						'{site_name}'=>Yii::app()->name,
	    						'{activation_url}'=>$activation_url,
	    					));
					
	    			UserModule::sendMail($user->email,$subject,$message);
	    			
					Y::flash('recoveryMessage',Users::t("Please check your email. An instructions was sent to your email address."));
	    			$this->refresh();
	    		}
	    	}
    		$this->render('recovery',array('form'=>$form));
    	}
	}
Exemplo n.º 6
0
 /**
  * Activation user account
  */
 public function actionActivation()
 {
     $email = $_GET['email'];
     $activkey = $_GET['activkey'];
     if ($email && $activkey) {
         $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
         if (isset($find) && $find->status) {
             $this->autoLogin($find->username);
             // update user_id in invite table
             Invite::model()->updateNewUser($find);
             // account already active
             Yii::app()->user->setFlash('success', 'Congratulations! Your account is now active. Please follow the directions below to set up your location.');
             $this->redirect('/userlocation/locate');
             //			    $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Your account is active.")));
         } elseif (isset($find->activkey) && $find->activkey == $activkey) {
             $find->activkey = UserModule::encrypting(microtime());
             $find->status = 1;
             $find->save();
             $this->autoLogin($find->username);
             // direct to autolocate with activation message
             Yii::app()->user->setFlash('success', 'Congratulations! Your account is now active. Please follow the directions below to set up your location.');
             $this->redirect('/userlocation/locate');
             // $this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Your account is activated.")));
         } else {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL. Please email support@geogram.com if you need assistance.")));
         }
     } else {
         $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL. Please email support@geogram.com if you need assistance.")));
     }
 }
Exemplo n.º 7
0
	/**
	 * Change password
	 */
	public function actionChangepassword() {
		$model = new UserChangePassword;
		if (Yii::app()->user->id) {
			
			// ajax validator
			if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form')
			{
				echo UActiveForm::validate($model);
				Yii::app()->end();
			}
			
			if(isset($_POST['UserChangePassword'])) {
					$model->attributes=$_POST['UserChangePassword'];
					if($model->validate()) {
						$new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
						$new_password->password = UserModule::encrypting($model->password);
						$new_password->activkey=UserModule::encrypting(microtime().$model->password);
						$new_password->save();
						Yii::app()->user->setFlash('success',UserModule::t("New password is saved."));
						$this->redirect(array("profile"));
					}
			}
			$this->render('changepassword',array('model'=>$model));
	    }
	}
Exemplo n.º 8
0
 /**
  * Change password
  */
 public function actionChangepassword()
 {
     if (isAdmin()) {
         $this->layout = '//layouts/main';
     }
     $model = new UserChangePassword();
     if (Yii::app()->user->id) {
         // ajax validator
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
             echo UActiveForm::validate($model);
             Yii::app()->end();
         }
         if (isset($_POST['UserChangePassword'])) {
             $model->attributes = $_POST['UserChangePassword'];
             if ($model->validate()) {
                 //$new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
                 $new_password = User::model()->findbyPk(Yii::app()->user->id);
                 $new_password->password = UserModule::encrypting($model->password);
                 $new_password->activkey = UserModule::encrypting(microtime() . $model->password);
                 if ($new_password->save()) {
                     Yii::app()->user->setFlash('success', UserModule::t("Thay đổi mật khẩu thành công"));
                     $this->redirect(array("profile"));
                 } else {
                     Yii::app()->user->setFlash('error', UserModule::t("Thay đổi mật khẩu không thành công"));
                 }
             }
         }
         $this->render('changepassword', array('model' => $model));
     }
 }
 /**
  * Change password
  */
 public function actionChangepassword()
 {
     $model = new UserChangePassword();
     if (Yii::app()->user->id) {
         // ajax validator
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
             echo UActiveForm::validate($model);
             Yii::app()->end();
         }
         if (isset($_POST['UserChangePassword'])) {
             $model->attributes = $_POST['UserChangePassword'];
             if ($model->validate()) {
                 $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
                 $new_password->password = UserModule::encrypting($model->password);
                 $new_password->activkey = UserModule::encrypting(microtime() . $model->password);
                 $new_password->save();
                 ///ALSO SAVE PASS oN SERVER
                 $u = User::model()->findByAttributes(array('password' => $new_password->password));
                 $rm_msg = $model->remoteupdatepass($u->email, $new_password->password);
                 Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved " . $rm_msg));
                 $this->redirect(array("profile"));
             }
         }
         $this->render('changepassword', array('model' => $model));
     }
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     if (Yii::app()->getModule('user')->disableUsername) {
         $model->username = time() + rand(0, 9999999);
     }
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->getReturnUrl());
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
Exemplo n.º 11
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));
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     Yii::app()->theme = 'client';
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->returnUrl);
     } else {
         $email = isset($_GET['email']) ? $_GET['email'] : '';
         $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
         if ($email && $activkey) {
             $form2 = new UserChangePassword();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Incorrect recovery link."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $user->activkey = UserModule::encrypting(microtime() . $user->password);
                     $user->save();
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     echo '<br>' . $activation_url;
                     echo '<br>' . Yii::app()->controller->module->recoveryUrl;
                     $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl));
                     $subject = UserModule::t("You have requested the password recovery site {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("You have requested the password recovery site {site_name}. To receive a new password, go to <a href=\"{activation_url}\">{activation_url}</a>.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
Exemplo n.º 13
0
 public function loginBySina()
 {
     $SAEOAuth = Yii::app()->SAEOAuth;
     $client = $SAEOAuth->getSinaClient();
     $sina_id = $SAEOAuth->getUserID();
     $sina_info = $client->show_user($sina_id);
     $model = new WeiboForm();
     $user = $model->getUserBySinaID($sina_id);
     if (empty($user)) {
         if (Yii::app()->user->isGuest or 1) {
             $username = $sina_id;
             $password = '******';
             $model->username = $sina_id;
             $model->password = $password;
             $model->verifyPassword = $password;
             $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->sina_id = $sina_id;
             $model->email = $sina_id . '@hhb.com';
             $model->save();
             $user = $model;
         } else {
             $user = User::model()->findByPk(Yii::app()->user->id);
             $user->sina_id = $sina_id;
             $user->save();
         }
     }
     $profile = $user->profile;
     if (empty($profile)) {
         $profile = new Profile();
         $profile->user_id = $model->id;
     }
     $profile->name = $sina_info['name'];
     $profile->location = $sina_info['location'];
     $profile->current_province = $sina_info['province'];
     $profile->current_city = $sina_info['city'];
     $profile->avatar = $sina_info['profile_image_url'];
     $profile->save();
     $username = $user->username;
     $password = $user->password;
     $identity = new UserIdentity($username, $password);
     $identity->authenticateWeibo();
     //必须设置默认时间,才能多域名共享登录session
     $duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
     // 30 days
     Yii::app()->user->login($identity, $duration);
 }
Exemplo n.º 14
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));
     }
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (isset($_GET['role']) && $_GET['role'] == 'Customer') {
         $role = 'Customer';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') {
         $role = 'Author';
     } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') {
         $role = 'Manager';
     } else {
         $role = 'Customer';
     }
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'simple-registration-form') {
         echo UActiveForm::validate($model);
         Yii::app()->end();
     }
     if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             if ($model->validate()) {
                 $soucePassword = $this->generate_password(8);
                 $model->password = UserModule::encrypting($soucePassword);
                 $model->superuser = 0;
                 $model->status = 1;
                 $model->username = $model->email;
                 if ($model->save()) {
                     $AuthAssignment = new AuthAssignment();
                     $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id);
                     $AuthAssignment->save();
                     $login_url = '<a href="' . $this->createAbsoluteUrl('/user/login') . '">' . Yii::app()->name . '</a>';
                     UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}", array('{login_url}' => $login_url, '{pass}' => $soucePassword)));
                     $identity = new UserIdentity($model->username, $soucePassword);
                     $identity->authenticate();
                     Yii::app()->user->login($identity, 0);
                     //$this->redirect(Yii::app()->controller->module->returnUrl);
                     Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{login}}) before start.", ['{{login}}' => $model->email]));
                     $this->refresh();
                 } else {
                     Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :("));
                     $this->refresh();
                 }
             }
         }
         Yii::app()->theme = 'client';
         $this->render('/user/registration', array('model' => $model, 'role' => $role));
     }
 }
Exemplo n.º 16
0
 /**
  * Change password
  */
 public function actionChangepassword()
 {
     $form = new UserChangePassword();
     if (Yii::app()->user->id) {
         if (isset($_POST['UserChangePassword'])) {
             $form->attributes = $_POST['UserChangePassword'];
             if ($form->validate()) {
                 $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
                 $new_password->password = UserModule::encrypting($form->password);
                 $new_password->activkey = UserModule::encrypting(microtime() . $form->password);
                 $new_password->save();
                 Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved."));
                 $this->redirect(array("profile"));
             }
         }
         $this->render('changepassword', array('form' => $form));
     }
 }
Exemplo n.º 17
0
function editPassword($editor, $id, $values)
{
    $password = $values['password'];
    $current_user = Users::model()->findByPk($id);
    $old_password = $current_user->password;
    //$enc_password = UserModule::encrypting($password);
    if ($password !== $old_password) {
        $activkey = UserModule::encrypting(microtime() . $password);
        $enc_password = UserModule::encrypting($password);
        $editor->field('activkey')->setValue($activkey);
        $editor->field('password')->setValue($enc_password);
    }
    //else{
    //  $editor->field( 'password' )->setValue( $enc_password );
    //$editor->field( 'user_role' )->setValue( $current_user->user_role );
    //$editor->field( 'client_id' )->setValue( $current_user->client_id );
    // }
}
Exemplo n.º 18
0
 /**
  * Activation user account
  */
 public function actionActivation($email, $key)
 {
     if ($email && $key) {
         $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
         if (isset($find) && $find->status) {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is active.")));
         } elseif (isset($find->activkey) && $find->activkey == $key) {
             $find->activkey = UserModule::encrypting(microtime());
             $find->status = 1;
             $find->save();
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is activated.")));
         } else {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
         }
     } else {
         $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
     }
 }
 /**
  * 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.º 20
0
	/**
	 * Change password
	 */
	public function actionChangepassword() {
		$model = new UserChangePassword;
		if (Y::userId()) {
			
			// ajax validator
			if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form')
				Y::end(UActiveForm::validate($model));
			
			if(isset($_POST['UserChangePassword'])) {
					$model->attributes=$_POST['UserChangePassword'];
					if($model->validate()) {
						$new_password = User::model()->notsafe()->findbyPk(Y::userId());
						$new_password->password = UserModule::encrypting($model->password);
						$new_password->activkey=UserModule::encrypting(microtime().$model->password);
						$new_password->save();
						Y::flashRedir('profileMessage',Users::t("New password is saved."),$this->module->profileUrl);
					}
			}
			$this->render('changepassword',array('model'=>$model));
	    }
	}
 /**
  * Activation user account
  */
 public function actionActivation()
 {
     $email = $_GET['email'];
     $activkey = $_GET['activkey'];
     if ($email && $activkey) {
         $record = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $email));
         $find = $record->userLogin2userDetails;
         if (isset($find) && $find->is_active) {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is active.")));
         } elseif (isset($find->activkey) && $find->activkey == $activkey) {
             $find->activkey = UserModule::encrypting(microtime());
             $find->is_active = 1;
             $find->save();
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is activated.")));
         } else {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
         }
     } else {
         $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL..")));
     }
 }
Exemplo n.º 22
0
 /**
  * Activation user account
  */
 public function actionActivation()
 {
     $this->seo(Yii::t('admin', 'Account activation'));
     $email = $_GET['email'];
     $activkey = $_GET['activkey'];
     if ($email && $activkey) {
         $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
         if (isset($find) && $find->status) {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("You account is active.")));
         } elseif (isset($find->activkey) && $find->activkey == $activkey) {
             $find->activkey = UserModule::encrypting(microtime());
             $find->status = 1;
             $find->save();
             $content = UserModule::t("You account is activated.") . ' <a href = "' . Yii::app()->createUrl('user/login') . '">' . Yii::t('admin', 'Back to login form') . '</a>';
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => $content));
         } else {
             $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
         }
     } else {
         $this->render('/user/message', array('title' => UserModule::t("User activation"), 'content' => UserModule::t("Incorrect activation URL.")));
     }
 }
Exemplo n.º 23
0
 public function actionTwitterCallBack()
 {
     //JUST TO BUILD A SESSION
     $isguest = Yii::app()->user->getIsGuest();
     //JUST TO BUILD A SESSION
     /* SOME COMMENTS FROM TWITTER API EXAMPLES
     	
     	
     		/* If the oauth_token is old redirect to the connect page. */
     if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
         $_SESSION['oauth_status'] = 'oldtoken';
         //header('Location: ./clearsessions.php');
         $this->redirect(Yii::app()->homeUrl);
     }
     /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
     $twitter = Yii::app()->twitter->getTwitterTokened($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
     /* Request access tokens from twitter */
     $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']);
     /* Save the access tokens. Normally these would be saved in a database for future use. */
     $_SESSION['access_token'] = $access_token;
     /* Remove no longer needed request tokens */
     unset($_SESSION['oauth_token']);
     unset($_SESSION['oauth_token_secret']);
     if (200 == $twitter->http_code) {
         /* The user has been verified and the access tokens can be saved for future use */
         $_SESSION['status'] = 'verified';
         //get an access twitter object
         $twitter = Yii::app()->twitter->getTwitterTokened($access_token['oauth_token'], $access_token['oauth_token_secret']);
         //get user details
         $twuser = $twitter->get("account/verify_credentials");
         //get matching twid if exists
         $olduser = User::model()->notsafe()->findByAttributes(array('twid' => $twuser->id));
         //this could be better
         $fakepassword = "******" . $twuser->id;
         //is this a new twitter accout
         if ($olduser === null) {
             //yes
             $model = new User();
             //make the user module
             $profile = new Profile();
             //since im using the yii user module i have a profile model as well
             $profile->regMode = true;
             //lets make some general information
             $userdata = array("username" => "tw_" . $twuser->screen_name, "password" => $fakepassword, "email" => $twuser->screen_name . '@twitter.com');
             $model->attributes = $userdata;
             $model->password = UserModule::encrypting($fakepassword);
             //set the password
             $model->lastvisit = $model->createtime = time();
             //set create andvisit time
             $model->superuser = 0;
             //probably not
             $model->status = 1;
             //active
             $model->regmethod = "twitter";
             //stats for me
             $model->twid = $twuser->id;
             //set the twid
             //these are profile feilds (you can probably omit)
             $twname = explode(" ", $twuser->name);
             $profile->firstname = $twname[0];
             //$user_info['first_name'];
             $profile->lastname = $twname[1];
             //$user_info['last_name'];
             $profile->birthday = "2000-01-01";
             //try and save the new user
             if ($model->save()) {
                 //word it saved
                 //again since i have a profile for each user aswell
                 $profile->user_id = $model->id;
                 $profile->save();
                 //now lets log them in
                 $identity = new UserIdentity($userdata['username'], $fakepassword);
                 $identity->authenticate();
                 $duration = 3600 * 24 * 30;
                 Yii::app()->user->login($identity, $duration);
                 //e.t. phone home
                 $this->redirect(Yii::app()->homeUrl);
             } else {
                 echo "FAIL<br><pre>";
                 print_r($model->getErrors());
                 die;
             }
         } else {
             //this user exists so lets log them in
             $identity = new UserIdentity("tw_" . $twuser->screen_name, $fakepassword);
             $identity->authenticate();
             $duration = 3600 * 24 * 30;
             Yii::app()->user->login($identity, $duration);
             //e.t. phone home
             $this->redirect(Yii::app()->homeUrl);
         }
     } else {
         /* Save HTTP status for error dialog on connnect page.*/
         //header('Location: /clearsessions.php');
         $this->redirect(Yii::app()->homeUrl);
     }
 }
 /**
  * Transfers collected values to the {@link HUserInfoForm::model}
  * 
  * @access public
  * @return void
  */
 public function getValidUserModel()
 {
     if ($this->hasErrors()) {
         return null;
     }
     // syncing only when we have a new model
     if ($this->_model->isNewRecord && strpos($this->scenario, '_pass') === false) {
         $this->_model->setAttributes(array($this->emailAtt => $this->email, $this->nameAtt => $this->username), false);
         if (HOAuthAction::$useYiiUser) {
             $this->_model->superuser = 0;
             $this->_model->status = Yii::app()->getModule('user')->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
             $this->_model->activkey = UserModule::encrypting(microtime() . $this->_model->email);
         }
     }
     return $this->model;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Guardians();
     $check_flag = 0;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if ($_POST['student_id']) {
         $guardian = Students::model()->findByAttributes(array('id' => $_POST['student_id']));
         $gid = $guardian->parent_id;
     } elseif ($_POST['guardian_id']) {
         $gid = $_POST['guardian_id'];
     } elseif ($_POST['guardian_mail']) {
         $gid = $_POST['guardian_mail'];
     }
     if ($gid != NULL and $gid != 0) {
         $model = Guardians::model()->findByAttributes(array('id' => $gid));
         $this->render('create', array('model' => $model, 'radio_flag' => 1, 'guardian_id' => $gid));
     } elseif ((isset($_POST['student_id']) or isset($_POST['guardian_id']) or isset($_POST['guardian_mail'])) and ($gid == NULL or $gid == 0)) {
         Yii::app()->user->setFlash('errorMessage', UserModule::t("Guardian not found..!"));
     }
     if (isset($_POST['Guardians'])) {
         $model->attributes = $_POST['Guardians'];
         $model->validate();
         if ($_POST['Guardians']['user_create'] == 1) {
             $check_flag = 1;
         }
         //print_r($_POST['Guardians']); exit;
         if ($model->save()) {
             //echo $model->ward_id; exit;
             $student = Students::model()->findByAttributes(array('id' => $model->ward_id));
             $student->saveAttributes(array('parent_id' => $model->id));
             if ($_POST['Guardians']['user_create'] == 0) {
                 //adding user for current guardian
                 $user = new User();
                 $profile = new Profile();
                 $user->username = substr(md5(uniqid(mt_rand(), true)), 0, 10);
                 $user->email = $model->email;
                 $user->activkey = UserModule::encrypting(microtime() . $model->first_name);
                 $password = substr(md5(uniqid(mt_rand(), true)), 0, 10);
                 $user->password = UserModule::encrypting($password);
                 $user->superuser = 0;
                 $user->status = 1;
                 if ($user->save()) {
                     //assign role
                     $authorizer = Yii::app()->getModule("rights")->getAuthorizer();
                     $authorizer->authManager->assign('parent', $user->id);
                     //profile
                     $profile->firstname = $model->first_name;
                     $profile->lastname = $model->last_name;
                     $profile->user_id = $user->id;
                     $profile->save();
                     //saving user id to guardian table.
                     $model->saveAttributes(array('uid' => $user->id));
                     //$model->uid = $user->id;
                     //$model->save();
                     // for sending sms
                     $sms_settings = SmsSettings::model()->findAll();
                     $to = '';
                     if ($sms_settings[0]->is_enabled == '1' and $sms_settings[2]->is_enabled == '1') {
                         // Checking if SMS is enabled.
                         if ($model->mobile_phone) {
                             $to = $model->mobile_phone;
                         }
                         if ($to != '') {
                             // Send SMS if phone number is provided
                             $college = Configurations::model()->findByPk(1);
                             $from = $college->config_value;
                             $message = 'Welcome to ' . $college->config_value;
                             SmsSettings::model()->sendSms($to, $from, $message);
                         }
                         // End send SMS
                     }
                     // End check if SMS is enabled
                     UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password)));
                 }
             }
             $this->redirect(array('addguardian', 'id' => $model->ward_id));
         }
     }
     $this->render('create', array('model' => $model, 'check_flag' => $check_flag));
 }
 /**
  * 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));
     }
 }
 private function _createUser($username, $email, $password)
 {
     $mUser = new User();
     $mUser->attributes = array('username' => $username, 'password' => $password, 'email' => $email, 'superuser' => 0, 'status' => User::STATUS_ACTIVE);
     $mUser->activkey = UserModule::encrypting(microtime() . $mUser->password);
     //if (!$mUser->validate()) {
     //    return FALSE;
     //}
     $mUser->password = UserModule::encrypting($mUser->password);
     if (!$mUser->save()) {
         return FALSE;
     }
     return $mUser->id;
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     $model = new RegistrationForm();
     if (isset(Yii::app()->eauth)) {
         //Yii::app()->eauth->popup = true;
         $services = array_keys(Yii::app()->eauth->services);
         if (isset(Yii::app()->session['eauth'])) {
             $services = array_diff($services, array_keys(Yii::app()->session['eauth']));
             foreach (Yii::app()->session['eauth'] as $data) {
                 foreach ($data as $property => $value) {
                     if (array_key_exists($property, $model->attributes)) {
                         $model->{$property} = $value;
                     }
                 }
             }
         }
     }
     $model->id = null;
     $model->superuser = 0;
     $model->status = 1;
     if (!$model->username) {
         $model->username = $model->nickname;
     }
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate($model);
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             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()) {
                     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 (isset(Yii::app()->session['eauth'])) {
                         foreach (Yii::app()->session['eauth'] as $service => $info) {
                             $userOauth = new UserOauth();
                             $userOauth->service = $service;
                             $userOauth->foreign_id = $info['id'];
                             $userOauth->user_id = $model->id;
                             $userOauth->save();
                         }
                     }
                     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();
                     }
                 }
             }
         }
         $this->render('/user/registration', array('model' => $model, 'services' => isset($services) ? $services : array()));
     }
 }
Exemplo n.º 29
0
 /**
  * Change password
  */
 public function actionChangeEmail()
 {
     $user = $this->loadUser();
     $model = new UserChangePassword();
     $model->scenario = 'changePassword';
     if (Yii::app()->user->id) {
         // ajax validator
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
             echo UActiveForm::validate($model);
             Yii::app()->end();
         }
         if (isset($_POST['UserChangePassword'])) {
             $model->attributes = $_POST['UserChangePassword'];
             if ($model->validate()) {
                 $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
                 //验证旧密码是否正确
                 if (UserModule::encrypting($_POST['UserChangePassword']['currentPassword']) != $new_password->password) {
                     $model->addError('currentPassword', '验证错误');
                 } else {
                     $new_password->password = UserModule::encrypting($model->password);
                     $new_password->activkey = UserModule::encrypting(microtime() . $model->password);
                     $new_password->save();
                     Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved."));
                     $this->redirect(array("/user"));
                 }
             }
         }
         $this->render('ChangeEmail', array('model' => $model));
     }
 }
Exemplo n.º 30
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));
     }
 }