/**
	 * 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.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new User();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $password = $_POST['User']['password'];
         $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $model->password = Yii::app()->controller->module->encrypting($model->password);
             if ($model->save()) {
                 //send mail
                 UserModule::sendMail($model->email, UserModule::t("You are registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password)));
                 $profile->user_id = $model->id;
                 $profile->save();
             }
             $this->redirect(array('/rights/assignment/user', 'id' => $model->id));
         } else {
             $profile->validate();
         }
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 3
0
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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();
             $organ = Organ::model()->findByAttributes(array('Email' => $email));
             $find = User::model()->findByAttributes(array('OrganID' => $organ->ID, 'IsMain' => '1'));
             if (isset($find) && $find->ActiveKey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->PassWord = Yii::app()->controller->module->encrypting($form2->password);
                         $find->ActiveKey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         User::model()->updateByPk($find->ID, array('PassWord' => $find->PassWord, 'ActiveKey' => $find->ActiveKey));
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved."));
                         $this->redirect(array('recovery/finish'));
                     }
                 }
                 $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'])) {
                 $status = 2;
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->findByPk($form->user_id);
                     //激活码
                     if ($user->ActiveKey == null) {
                         $user->ActiveKey = $user->encrypting(microtime() . $user->PassWord);
                         $user->verifyPassword = $user->PassWord;
                         $user->save();
                     }
                     //获取邮箱
                     $organinfo = Organ::model()->findByPk($user->OrganID);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->ActiveKey, "email" => $organinfo->Email));
                     $subject = UserModule::t("找回 {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 {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url . ' '));
                     $res = UserModule::sendMail($organinfo->Email, $subject, $message);
                     if ($res == 'ok') {
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address."));
                     } else {
                         $this->render('recovery', array('form' => $form, 'emailError' => $res));
                         exit;
                     }
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * 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.º 5
0
 public function actionCreate()
 {
     $model = new Staff();
     $profile = new Profile();
     $this->performAjaxValidation(array($model, $profile), 'staff-form');
     if (isset($_POST['Staff'])) {
         $model->attributes = $_POST['Staff'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             if ($model->save()) {
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Profile']['group_id'])) {
                     foreach ($_POST['Profile']['group_id'] as $groupid) {
                         $userGroup = new UserGroup();
                         $userGroup->profile_id = $model->id;
                         $userGroup->group_id = $groupid;
                         $userGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->redirect(array('view', 'id' => $model->id));
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, 'An error occured while trying to create new user, please try again.');
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
                     Yii::app()->end();
                 }
                 $this->render('create', array('model' => $model, 'profile' => $profile));
             }
         } else {
             $profile->validate();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'profile' => $profile), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile));
 }
Exemplo n.º 6
0
	/**
	 * Recovery password
	 */
	public function actionRecovery () {
		$form = new UserRecoveryForm;
		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('success',UserModule::t("New password is saved."));
								$this->redirect(Yii::app()->controller->module->recoveryUrl);
							}
						} 
						$this->render('changepassword',array('model'=>$form2));
		    		} else {
		    			Yii::app()->user->setFlash('error',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);
							$activation_url = 'http://' . $_SERVER['HTTP_HOST'].$this->createUrl(implode(Yii::app()->controller->module->recoveryUrl),array("activkey" => $user->activkey, "email" => $user->email));
							
							$subject = UserModule::t("You have requested a password recovery of {site_name}",
			    					array(
			    						'{site_name}'=>Yii::app()->name,
			    					));
			    			$message = UserModule::t("You have requested our password recovery services. To receive a new password, go to {activation_url}. Sincerely, Team of {site_name}",
			    					array(
			    						'{site_name}'=>Yii::app()->name,
			    						'{activation_url}'=>$activation_url,
			    					));
							
			    			UserModule::sendMail($user->email,$subject,$message);
			    			
							Yii::app()->user->setFlash('info',UserModule::t("Please check your email. Further instructions are sent to your email address."));
			    			$this->refresh();
			    		}
			    	}
		    		$this->render('recovery',array('model'=>$form));
		    	}
		    }
	}
Exemplo n.º 7
0
 public function actionSendEmail()
 {
     Yii::import('application.modules.user.UserModule');
     $email = urldecode($_POST['email']);
     $subject = urldecode($_POST['subject']);
     $message = urldecode($_POST['message']);
     if ($email) {
         UserModule::sendMail($email, $subject, $message);
     }
 }
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
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}. Để nhận được mật khẩu mới bạn hãy vào link sau: {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     if (Yii::app()->request->isAjaxRequest) {
                         jsonOut(array('error' => false, 'msg' => 'Xin vui lòng kiểm tra email. Một hướng dẫn đã chuyển đến email của bạn.'), false);
                     }
                     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();
                 } else {
                     if (Yii::app()->request->isAjaxRequest) {
                         jsonOut(array('error' => true, 'msg' => CActiveForm::validate($form)));
                     }
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
 /**
  * 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));
         }
     }
 }
 /**
  * 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.º 12
0
    /**
     * Recovery password
     */
    public function actionRecovery()
    {
        $form = new UserRecoveryForm();
        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);
                        $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                        $subject = UserModule::t("You have requested the password recovery site {site_name}", array('{site_name}' => Yii::app()->name));
                        $message = UserModule::t('<p> You have requested to reset your {site_name}. password, No problem! Click the link below to create a new password </p> <a href="' . $activation_url . '">{activation_url}</a>.<br>							If you did not request to change your password, let us know and we’ll make sure everything is okay with your account. You can email us at support@instanttop.com <p>Kind regards,<br>
							Your' . Yii::app()->name . ' team </p>', 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));
            }
        }
    }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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 = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $email));
             if (isset($find) && $find->userLogin2userDetails->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->pwd = Yii::app()->controller->module->encrypting($form2->password);
                         $find->userLogin2userDetails->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->userLogin2userDetails->is_active == 0) {
                             $find->userLogin2userDetails->is_active = 1;
                         }
                         $find->save();
                         $find->userLogin2userDetails->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 = AUserLogin::model()->scope_select_all()->findByAttributes(array('login_name' => $form->login_or_email));
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->userLogin2userDetails->activkey, "email" => $user->login_name));
                     $subject = UserModule::t("You have requested the password recovery for {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Hi, \n You have requested the password recovery for {site_name}. To receive a new password, go to {activation_url}. \n Regards, \n tw.in team", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->login_name, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. Instructions has been sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
Exemplo n.º 14
0
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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("Новый пароль сохранен."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('model' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Неверная ссылка."));
                 $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);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), 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("Ссылка на восстановление пароля отправлена на вашу почту."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('model' => $form));
         }
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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('success', "New password is saved.");
                         $this->redirect(Yii::app()->controller->module->loginUrl);
                     }
                 }
                 $this->render('/recovery/changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('error', "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);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("[{site_name}] Password Recovery", array('{site_name}' => Yii::app()->params['system_name']));
                     $message = UserModule::t("recovery password can be done by following the link: <br>\n\t\t\t\t\t\t\t\t\t\t  {activation_url}. <br><br><br>\n\t\t\t\t\t\t\t\t\t\t  Best regard {site_name} :)<br>" . date("M d-m-Y | H:i") . " WIB", array('{site_name}' => Yii::app()->params['system_name'], '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('info', "Please check your email. An instructions was sent to your email address.");
                     $this->refresh();
                 }
             }
             $this->render('/recovery/recovery', array('form' => $form));
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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("Salasana vaihdettu onnistuneesti."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Linkki on vanhentunut."));
                 $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);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("Olet pyytänyt salasanan vaihtoa ohjelmasta {site_name} \r\n", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("Olet pyytänyt salasanan vaihtoa ohjelmasta {site_name}. \r\nVaihda uusi salasana menemällä osoitteeseen \r\n{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("Tarkista sähköpostisi. Sähköpostiisi on lähetetty linkki jonka avulla voit vaihtaa salasanasi."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }
Exemplo n.º 17
0
 public function actionSendMail()
 {
     date_default_timezone_set('UTC');
     $startdate = date('Y-m-d H:i:s', strtotime('+1 hours'));
     $enddate = date('Y-m-d H:i:s', strtotime('+2 hours 1 minute'));
     $Poses = Pos::model()->findAll(array('select' => '*', 'condition' => 'date > "' . $startdate . '" and date < "' . $enddate . '"'));
     $users = User::Model()->findAll(array('select' => '*'));
     $subject = 'POS Timer Alert';
     foreach ($Poses as $pos) {
         $message = 'The ' . $pos->type . ' in ' . $pos->location . ' is due out of reinforced at ' . $pos->date . PHP_EOL;
         foreach ($users as $user) {
             $profiles = Profile::model()->findByPk($user->id);
             if ($profiles->subscribe) {
                 $email = $user->email;
                 echo $email . '  ' . $subject . '  ' . $message;
                 UserModule::sendMail($email, $subject, $message);
             }
         }
     }
 }
Exemplo n.º 18
0
 public static function sendAccount($params)
 {
     $select1 = "OrderSN as No,CreateTime,Payment,BuyerID,RealPrice as Price,BuyerName,1";
     $select2 = "ReturnNO as No,CreateTime,PayMethod as Payment,ServiceID as BuyerID,Price,2";
     if ($params['type'] == 1) {
         $seaCon1 = self::getOrderCond($params, $select1);
         $data1 = Yii::app()->papdb->createCommand($seaCon1)->queryAll();
         $count1 = Yii::app()->papdb->createCommand(str_replace($select1, 'sum(RealPrice)', $seaCon1))->queryScalar();
     } else {
         if ($params['type'] == 2) {
             $seaCon2 = self::getReturnCond($params, $select2);
             $data2 = Yii::app()->papdb->createCommand($seaCon2)->queryAll();
             $count2 = Yii::app()->papdb->createCommand(str_replace($select2, 'sum(Price)', $seaCon2))->queryScalar();
         } else {
             $seaCon1 = self::getOrderCond($params, $select1);
             $data1 = Yii::app()->papdb->createCommand($seaCon1)->queryAll();
             $count1 = Yii::app()->papdb->createCommand(str_replace($select1, 'sum(RealPrice)', $seaCon1))->queryScalar();
             $seaCon2 = self::getReturnCond($params, $select2);
             $data2 = Yii::app()->papdb->createCommand($seaCon2)->queryAll();
             $count2 = Yii::app()->papdb->createCommand(str_replace($select2, 'sum(Price)', $seaCon2))->queryScalar();
         }
     }
     $count1 = $count1 ? $count1 : 0;
     $count2 = $count2 ? $count2 : 0;
     $gain = $count1 - $count2;
     $day = date('t', $params['starttime']);
     $organ = Organ::model()->findByPk($params['OrganID'], array('select' => 'OrganName,Email'))->attributes;
     $email = $organ['Email'];
     $subject = '由你配 - ' . $params['uyear'] . '年' . $params['umonth'] . '月对账单';
     $message = "\n            <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n        <html xmlns='http://www.w3.org/1999/xhtml'>\n         <head>\n        <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n        <title>由你配 - 打印对账单</title>\n        </head>\n         <body>\n        <link rel='stylesheet' type='text/css' href='" . F::themeUrl() . "/css/jpd/account.css'/>\n        <div class='wrapper' style='width:700px; background:#fff; margin:0 auto'>\n            <div class='head' style='height:55px; line-height:55px; border-bottom:1px solid #0566c2; background:url(\"http://192.168.2.29:8000/themes/default/images/jpd/logo_account.jpg\") #1f76c8 no-repeat'>\n                <div class='title' style='margin:0 auto; text-align:center'>\n                <span style='font-family:微软雅黑; font-size:24px; font-weight: bold; color:#fff; word-spacing:8px; letter-spacing: 1.5px;'>" . $params['uyear'] . "年" . $params['umonth'] . "月对账单</span>\n                </div>\n            </div>\n            <div class='info' style='padding:0 20px; font-size:12px; color:#343434'>\n                <p style='margin:0px; line-height:28px'>亲爱的" . $organ['OrganName'] . ",您好!</p>\n                <p style='margin:0px; line-height:28px'>感谢您使用由你配平台,以下是您" . $params['umonth'] . "月的平台交易明细:</p>\n            </div>\n            <div class='summary' style=' height:60px; line-height:30px; border-bottom:2px solid #c9c7c7; border-top:2px solid #c9c7c7; background:#f2f2f2; padding:0 30px'>\n                <div class='float_l all' style='font-size:14px; font-weight:bold; color:#565656; line-height:60px;float:left'>\n                    本月净收益: <span class='blue' style='color:#1f76c8'>" . $gain . "</span> 元\n\n                </div>\n                <div class='float_r detial' style='font-size:12px; font-weight:bold; line-height:30px;float:right'>\n                    <p style='margin:0px; line-height:28px'>本月总收入: <span class='blue f14' style='color:#1f76c8;font-size:14px'>" . $count1 . "</span>元\n                        <span class='m_left50' style='margin-left:50px'>本月总支出: \n                        <span class='blue f14' style='color:#1f76c8;font-size:14px'>" . $count2 . "</span>元</span></p>\n                    <p style='margin:0px; line-height:28px'>账单周期:" . $params['uyear'] . "年" . $params['umonth'] . "月01日—" . $params['uyear'] . "年" . $params['umonth'] . "月" . $day . "日</p>\n        </div>\n        </div>";
     if (!empty($data1)) {
         $message .= "<p class='line30' style='line-height:35px; margin:0px; margin-left:7px'><b class='f14 blue' style='color:#1f76c8;font-size:14px'>订单明细:</b></p>\n        <table class='table' cellpadding='0'  cellspacing='0' style='width:685px; text-align:center; border:1px solid #c9c7c7; border-top:none; margin:0 auto; border-right:none; border-bottom:none'>\n            <thead>\n                <tr style='background:#5783ad; line-height:35px; color:#fff; font-weight:bold; font-size:14px; letter-spacing:1px'>\n                <td>时间</td><td>交易类型</td><td>修理厂名称</td><td>订单编号</td><td class='last'>收入(元)</td></tr>\n            </thead>\n            <tbody>";
         foreach ($data1 as $k => $v) {
             $payment = $v['Payment'] == 1 ? '支付宝担保' : '物流代收款';
             $class = $k % 2 != 0 ? ';background:#eef6fd' : '';
             $message .= "<tr style='line-height:30px" . $class . "'><td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . date('Y-m-d', $v['CreateTime']) . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $payment . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $v['BuyerName'] . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $v['No'] . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>¥" . $v['Price'] . "</td>\n                </tr>";
         }
         $message .= "</tbody></table>";
     }
     if (!empty($data2)) {
         $message .= "<p class='line30' style='line-height:35px; margin:0px; margin-left:7px'><b class='f14 blue' style='color:#1f76c8;font-size:14px'>退货明细:</b></p>\n        <table class='table' cellpadding='0'  cellspacing='0' style='width:685px; text-align:center; border:1px solid #c9c7c7; border-top:none; margin:0 auto; border-right:none; border-bottom:none'>\n            <thead>\n                <tr style='background:#5783ad; line-height:35px; color:#fff; font-weight:bold; font-size:14px; letter-spacing:1px'>\n                <td>时间</td><td>退款方式</td><td>修理厂名称</td><td>退货单号</td><td class='last'>支出(元)</td></tr>\n            </thead>\n            <tbody>";
         foreach ($data2 as $k => $v) {
             $payment = $v['Payment'] == 0 ? '支付宝担保' : '物流代收款';
             $v['BuyerName'] = Organ::model()->findByPk($v['BuyerID'], array('select' => 'OrganName'))->attributes['OrganName'];
             $class = $k % 2 != 0 ? ';background:#eef6fd' : '';
             $message .= "<tr style='line-height:30px" . $class . "'><td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . date('Y-m-d', $v['CreateTime']) . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $payment . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $v['BuyerName'] . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>" . $v['No'] . "</td>\n                    <td style='border-bottom:1px solid #c9c7c7; border-right:1px solid #c9c7c7; font-size:12px; color:#343434'>¥" . $v['Price'] . "</td>\n                </tr>";
         }
         $message .= "</tbody></table>";
     }
     $message .= "</div></body></html>";
     return UserModule::sendMail($email, $subject, $message);
 }
Exemplo n.º 19
0
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     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 = PasswordHelper::hashPassword($form2->password);
                         $find->activkey = PasswordHelper::hashPassword(microtime() . $form2->password);
                         $find->password_update_time = date('Y-m-d H:i:s');
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         $passwordHistory = new PasswordHistory();
                         $passwordHistory->profile_id = $find->id;
                         $passwordHistory->password = $find->password;
                         $passwordHistory->save();
                         Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Your password has been changed. Please login with your new password."));
                         $this->redirect(Yii::app()->controller->module->loginUrl);
                     }
                 }
                 if (isset($this->location)) {
                     $this->render('frontend.views.recovery.changepassword', array('form' => $form2));
                 } else {
                     $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);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = UserModule::t("You have requested password recovery for {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = UserModule::t("You have requested password recovery for {site_name}. To change your password, click <a href='{$activation_url}'>here</a> or copy and paste this link into your browser: {$activation_url}", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     UserModule::sendMail($user->email, $subject, $message);
                     //echo $message.'here';
                     Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email, the reset link was sent to your email address."));
                     $this->refresh();
                 }
             }
             if (isset($this->location)) {
                 $this->render('frontend.views.recovery.recovery', array('form' => $form));
             } else {
                 $this->render('recovery', array('form' => $form));
             }
         }
     }
 }
Exemplo n.º 20
0
 /**
  * 添加推送信息
  */
 public function actionAddpush()
 {
     $organID = Commonmodel::getOrganID();
     $userID = Yii::app()->user->id;
     $content = trim($_POST['content']);
     $sendway = $_POST['sendway'];
     $ids = substr($_POST['ids'], 0, -1);
     $contactID = explode(',', $ids);
     $count = count($contactID);
     $sendTime = time();
     // 判断是否还有剩下的可发送数量
     $this->Iscanpush($sendway, $count, $organID);
     $pushMessage = new Pushmessage();
     $pushMessage->Content = $content;
     $pushMessage->SendWay = $sendway;
     $pushMessage->OrganID = $organID;
     $pushMessage->UserID = $userID;
     $pushMessage->SendTime = $sendTime;
     if ($pushMessage->save()) {
         //如果保存成功,则发送
         $pushID = Yii::app()->db->getLastInsertID();
         for ($i = 0; $i < $count; $i++) {
             $relationcon = new PushContactRelation();
             $relationcon->PushID = $pushID;
             $relationcon->ContactID = $contactID[$i];
             $relationcon->OrganID = $organID;
             $rbool = $relationcon->save();
             if ($rbool && $sendway == 1) {
                 // 发送邮件
                 $model = $this->getBussineContact($contactID[$i]);
                 $sex = $model['sex'] == '男' ? '先生' : '女士';
                 $message = "\n\t\t\t\t<p>尊敬的" . $model['name'] . $sex . ",</p>\n\t\t\t\t<p>嘉配服务平台为您推送信息:{$content}</p>\n\t\t\t\t<p style='text-align: right;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 嘉配服务平台&nbsp;&nbsp;&nbsp;&nbsp;</p>\n\t\t\t\t<p style='text-align: right;'>" . date('Y年m月d日', time()) . "</p>";
                 $toemail = $model['email'];
                 $bool = UserModule::sendMail($toemail, '嘉配服务平台', $message);
             }
         }
         $result['data'] = $bool;
         // $rbool;
     }
     echo json_encode($result);
 }
 /**
  * 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));
     }
 }
 /**
  * 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()));
     }
 }
 public function actionPartialfees()
 {
     if (isset($_POST['FinanceFees']) and isset($_POST['FinanceFees']['fees_paid'])) {
         $model = $this->loadModel($_POST['FinanceFees']['id']);
         $dt = date('Y-m-d');
         $model->saveAttributes(array('date' => $dt));
         $student = Students::model()->findByAttributes(array('id' => $_POST['FinanceFees']['student_id']));
         $collection = FinanceFeeCollections::model()->findByAttributes(array('id' => $_POST['FinanceFees']['fee_collection_id']));
         $check_admission_no = FinanceFeeParticulars::model()->findAllByAttributes(array('finance_fee_category_id' => $collection->fee_category_id, 'admission_no' => $student->admission_no));
         $to_student = "";
         if (count($check_admission_no) > 0) {
             // If any particular is present for this student
             $adm_amount = 0;
             foreach ($check_admission_no as $adm_no) {
                 $adm_amount = $adm_amount + $adm_no->amount;
             }
             $fees = $adm_amount;
         } else {
             // If any particular is present for this student category
             $check_student_category = FinanceFeeParticulars::model()->findAllByAttributes(array('finance_fee_category_id' => $collection->fee_category_id, 'student_category_id' => $student->student_category_id, 'admission_no' => ''));
             if (count($check_student_category) > 0) {
                 $cat_amount = 0;
                 foreach ($check_student_category as $stu_cat) {
                     $cat_amount = $cat_amount + $stu_cat->amount;
                 }
                 $fees = $cat_amount;
             } else {
                 //If no particular is present for this student or student category
                 $check_all = FinanceFeeParticulars::model()->findAllByAttributes(array('finance_fee_category_id' => $collection->fee_category_id, 'student_category_id' => NULL, 'admission_no' => ''));
                 if (count($check_all) > 0) {
                     $all_amount = 0;
                     foreach ($check_all as $all) {
                         $all_amount = $all_amount + $all->amount;
                     }
                     $fees = $all_amount;
                 } else {
                     $fees = 0;
                     // If no particular is found.
                 }
             }
         }
     } elseif (isset($_REQUEST['id'])) {
         $model = $this->loadModel($_REQUEST['id']);
     }
     // Flag to know if we will render the form or try to add
     // new jon.
     $flag = true;
     if (isset($_POST['FinanceFees']) and isset($_POST['FinanceFees']['fees_paid'])) {
         $flag = false;
         $fees_paid = $model->fees_paid + $_POST['FinanceFees']['fees_paid'];
         if ($model->saveAttributes(array('fees_paid' => $fees_paid))) {
             $transaction = new FinanceTransaction();
             $transaction->amount = $_POST['FinanceFees']['fees_paid'];
             $transaction->collection_id = $_POST['FinanceFees']['fee_collection_id'];
             $transaction->student_id = $_POST['FinanceFees']['student_id'];
             $transaction->transaction_date = date('Y-m-d');
             $transaction->save();
             if ($fees == $fees_paid) {
                 $model->saveAttributes(array('is_paid' => 1));
             }
             $sms_settings = SmsSettings::model()->findByAttributes(array('settings_key' => 'FeesEnabled'));
             if ($sms_settings->is_enabled == '1') {
                 // Checking if SMS is enabled.
                 $guardian = Guardians::model()->findByAttributes(array('ward_id' => $_POST['FinanceFees']['student_id']));
                 $student = Students::model()->findByAttributes(array('id' => $_POST['FinanceFees']['student_id']));
                 if (count($guardian) != 0 && $guardian->mobile_phone && $guardian->mobile_phone != "") {
                     $to = $guardian->mobile_phone;
                 } else {
                     if ($student->phone1) {
                         $to = $student->phone1;
                     } else {
                         if ($student->phone2) {
                             $to = $student->phone2;
                         }
                     }
                 }
                 $balance = $fees - $fees_paid > 0 ? $fees - $fees_paid : 0;
                 SmsSettings::model()->sendSmsFees($to, $student->first_name . ' ' . $student->last_name, $fees_paid, $balance);
                 if (defined('EMAIL_ALERT_ADDRESS')) {
                     UserModule::sendMail(constant('EMAIL_ALERT_ADDRESS'), UserModule::t("Student paid fees : {student_name}", array('{student_name}' => $student->first_name . ' ' . $student->last_name)), UserModule::t("Student has paid fees: {student_name} of Rs. {fee_amount}", array('{student_name}' => $old_model->firstname . " " . $old_model->lastname, 'fee_amount' => $fees_paid)));
                 }
             }
             echo CJSON::encode(array('status' => 'success'));
             exit;
         } else {
             echo CJSON::encode(array('status' => 'error'));
             exit;
         }
     }
     if ($flag) {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
         $this->renderPartial('partialfees', array('model' => $model), false, true);
     }
 }
 /**
  * Sends email activation email, when it is needed	
  * 
  * @param CActiveRecord $user current user model
  * @access protected
  * @return void
  */
 protected function sendActivationMail($user)
 {
     if ($this->useYiiUser) {
         // why not to put this code not in controller, but in the User model of `yii-user` module?
         // for now I can only copy-paste this code from controller...
         if (Yii::app()->getModule('user')->sendActivationMail) {
             $activation_url = Yii::app()->createAbsoluteUrl('/user/activation/activation', array("activkey" => $user->activkey, "email" => $user->email));
             UserModule::sendMail($user->email, UserModule::t("You registered on {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, please go to {activation_url}", array('{activation_url}' => $activation_url)));
         }
     } else {
         if (method_exists($user, 'sendActivationMail')) {
             $user->sendActivationMail();
         }
     }
 }
	/**
	 * 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.º 27
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Customer();
     $profile = new Profile();
     $address = new CheckoutAddress();
     //Yii::app()->session['cid'] = '';
     $this->performAjaxValidation(array($model, $profile), 'customer-form');
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         $profile->attributes = $_POST['Profile'];
         $profile->user_id = 0;
         if ($model->validate() && $profile->validate() && $this->validateAddress()) {
             $realp = PasswordHelper::generateStrongPassword();
             $model->password = $realp;
             $model->activkey = PasswordHelper::hashPassword(microtime() . $model->password);
             $model->password = PasswordHelper::hashPassword($model->password);
             $model->status = 0;
             $model->type = 1;
             if ($model->save()) {
                 Yii::app()->session['cid'] = $model->id;
                 $profile->user_id = $model->id;
                 $profile->save();
                 if (!empty($_POST['Customer']['c_group_id'])) {
                     foreach ($_POST['Customer']['c_group_id'] as $groupid) {
                         $customerGroup = new CustomerCGroup();
                         $customerGroup->user_id = $model->id;
                         $customerGroup->c_group_id = $groupid;
                         $customerGroup->save();
                     }
                 }
                 $passwordHistory = new PasswordHistory();
                 $passwordHistory->profile_id = $model->id;
                 $passwordHistory->password = $model->password;
                 $passwordHistory->save();
                 foreach ($this->_address as $address) {
                     $address->user_id = $model->id;
                     $address->save();
                 }
                 if (Yii::app()->getModule('user')->sendActivationMail) {
                     $activation_url = $this->createAbsoluteUrl('/user/activation', array("activkey" => $model->activkey, "email" => $model->email));
                     UserModule::sendMail($model->email, UserModule::t("Your {site_name} account has been created", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, go to <a href='{activation_url}'>{activation_url}</a>.<br/><br/>Username: "******"<br/>Password: "******"<br/>", array('{activation_url}' => $activation_url)));
                 }
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, Yii::t('info', 'Customer was successfully created'));
                 $this->renderPartial('_view', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
                 Yii::app()->end();
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'An error occurred while trying to create new customer, please try again.'));
                 /*$this->render('create',array(
                 			'model'=>$model,
                 			'profile'=>$profile,
                 		));*/
             }
         } else {
             $profile->validate();
             $this->validateAddress();
             //echo GxActiveForm::validateMultiple(array($model,$profile,$address));
             //Yii::app()->end();
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form_address', array('model' => $model, 'profile' => $profile, 'address' => $this->_address), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'profile' => $profile, 'address' => $this->_address));
 }
 /**
  * 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.º 29
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Students();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Students'])) {
         $model->attributes = $_POST['Students'];
         $list = $_POST['Students'];
         if ($model->admission_date) {
             $model->admission_date = date('Y-m-d', strtotime($model->admission_date));
         }
         if ($model->date_of_birth) {
             $model->date_of_birth = date('Y-m-d', strtotime($model->date_of_birth));
         }
         //$model->photo_data=CUploadedFile::getInstance($model,'photo_data');
         if ($file = CUploadedFile::getInstance($model, 'photo_data')) {
             $model->photo_file_name = $file->name;
             $model->photo_content_type = $file->type;
             $model->photo_file_size = $file->size;
             $model->photo_data = file_get_contents($file->tempName);
         }
         /*else{
         	  if(isset($_POST['photo_file_name'])){
                      $model->photo_file_name=$_POST['photo_file_name'];
         		  $model->photo_content_type=$_POST['photo_content_type'];
         		  $model->photo_file_size=$_POST['photo_file_size'];
         		  $model->photo_data=hex2bin($_POST['photo_data']);
         	  }
           }*/
         //echo $model->photo_data.'----';
         /*if(isset($_FILES['Students']))
         		{
         			print_r($_FILES['Students']);
         			exit;
         			$tmpName = $_FILES['Students']['tmp_name'];
         		  $fp      = fopen($tmpName, 'r');
         		  $data = fread($fp, filesize($tmpName));
         		  $data = addslashes($data);
         		  fclose($fp);
         		  $model->photo_data = $data;
         		}*/
         if ($model->save()) {
             //adding user for current student
             $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('student', $user->id);
                 //profile
                 $profile->firstname = $model->first_name;
                 $profile->lastname = $model->last_name;
                 $profile->user_id = $user->id;
                 $profile->save();
                 //saving user id to students table.
                 $model->saveAttributes(array('uid' => $user->id));
                 // 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->phone1) {
                         $to = $model->phone1;
                     } elseif ($model->phone2) {
                         $to = $model->phone2;
                     }
                     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 are registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please login to your account with your email id as username and password {password}", array('{password}' => $password)));
             }
             // for saving in fee table
             $fee_collection = FinanceFeeCollections::model()->findAll('batch_id=:x', array(':x' => $model->batch_id));
             if ($fee_collection != NULL) {
                 for ($i = 0; $i < count($fee_collection); $i++) {
                     $fee = new FinanceFees();
                     $fee->fee_collection_id = $fee_collection[$i]['id'];
                     $fee->student_id = $model->id;
                     $fee->is_paid = '0';
                     $fee->save();
                 }
             }
             $this->redirect(array('guardians/create', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 30
0
 public static function sendwarnemail($params)
 {
     $organID = $params['organID'];
     $UserID = $params['UserID'];
     $subject = $params['subject'];
     $remind = $params['remind'];
     $warn = $params['warn'];
     $time = $_SERVER['REQUEST_TIME'];
     //获取提醒邮箱和警告邮箱地址
     $emailsql = ' select * from jpd_admin_settings where Category="system" and (`Key`="safe_warn_email" or `Key`="safe_remind_email")';
     $emailres = Yii::app()->jpdb->createCommand($emailsql)->queryAll();
     $reminds = array();
     $warns = array();
     foreach ($emailres as $v) {
         $email = @unserialize($v['Value']);
         if ($v['Key'] == 'safe_remind_email') {
             //提醒邮箱列表
             if ($email != '') {
                 $remindemails = $email;
                 $reminds = explode(';', $email);
             }
         } else {
             //警告邮箱
             if ($email != '') {
                 $warnsemails = $email;
                 $warns = explode(';', $email);
             }
         }
     }
     $res = array();
     foreach ($reminds as $r) {
         if ($r == '') {
             continue;
         }
         $res[] = UserModule::sendMail($r, $subject, $remind);
         Yii::app()->mailer->ClearAddresses();
     }
     foreach ($warns as $w) {
         if ($w == '') {
             continue;
         }
         $res[] = UserModule::sendMail($w, $subject, $warn);
         Yii::app()->mailer->ClearAddresses();
     }
     $insert = 'insert into jpd_login_remind (OrganID,UserID,RemindContent,WarnContent,RemindEmail,WarnEmail,CreateTime) values(' . $organID . ',' . $UserID . ',"' . $remind . '","' . $warn . '","' . $remindemails . '","' . $warnsemails . '",' . $time . ')';
     Yii::app()->jpdb->createCommand($insert)->execute();
     //Yii::log($insert, 'info', 'order');
     //Yii::log(date('Y-m-d H:i:s') . '   email_result:' . json_encode($res), 'info', 'order');
 }