Example #1
0
 /**
  * Displays the contact page
  */
 public function actionContact()
 {
     $model = new ContactForm();
     if (isset($_POST['ContactForm'])) {
         $model->attributes = $_POST['ContactForm'];
         if ($model->validate()) {
             Yii::import('application.extensions.phpmailer.HMailHelper');
             $headers = "From: {$model->email}\r\nReply-To: {$model->email}\n\n";
             //mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
             HMailHelper::Send("Contact", $headers . $model->body, array(array("*****@*****.**", "HuyTBT")));
             Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
             $this->refresh();
         }
     }
     $this->render('contact', array('model' => $model));
 }
 /**
  * Action ChangePassword dùng để đổi mật khẩu cho user khi user quên mật khẩu với điều kiện user click url được gửi trong email
  */
 public function actionChangePassword()
 {
     // Validate Code forgot password
     if (isset($_GET['code']) && isset($_GET['email'])) {
         $strForgotPasswordCode = $_GET['code'];
         $strEmail = $_GET['email'];
         $user = User::model()->notsafe()->findByAttributes(array('email' => $strEmail));
         if (isset($user)) {
             // Check Code
             if ($strForgotPasswordCode == $user->activkey) {
                 $model = new ChangePasswordForm();
                 // Submit form
                 if (isset($_POST['ChangePasswordForm'])) {
                     $model->attributes = $_POST['ChangePasswordForm'];
                     // Validate new password
                     if ($model->validate()) {
                         // Create new Pasword
                         $user->encryptPassword($model->password);
                         // Delete forgot code in DB
                         $user->activkey = $user->createCodeActivation();
                         // Save new password to DB
                         if ($user->save()) {
                         }
                         /**
                          * @todo Change message email
                          */
                         $strMsgHTML = "Recovery Password Success";
                         Yii::import('application.extensions.phpmailer.HMailHelper');
                         HMailHelper::Send('Recovery Password', $strMsgHTML, array(array($user->email, $user->username)));
                         // Notice Recovery Password success
                         $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Success'), "message" => UserModule::t('The recovery password was successful!')));
                         $this->redirect(Yii::app()->user->loginUrl);
                     }
                 }
                 $this->render('changepassword', array('model' => $model));
                 Yii::app()->end();
             } else {
                 // Notice recovery password failure
                 $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Failure'), "message" => UserModule::t('Incorrect recovery URL or Recovery period has expired!')));
                 $this->redirect("/");
             }
         }
     }
     // Notice recovery password failure
     $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Failure'), "message" => UserModule::t('Incorrect recovery URL!')));
     $this->redirect("/");
 }
 public function actionIndex()
 {
     // Kiểm tra nếu đăng nhập rồi chuyển trang
     if (!Yii::app()->user->isGuest) {
         $this->redirect("/user/profile");
     }
     $model = new RegistrationForm();
     /*
      * Nếu dữ liệu được post lên để validate (thông thường khi ta lost focus một input nào đó thì hệ thống
      * sẽ sử dụng ajax), khi đó ta tiến hành kiểm tra dữ liệu và nếu có lỗi thì gửi thông báo lỗi về
      * 
      */
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     // Submit form
     if (isset($_POST['RegistrationForm'])) {
         $model->attributes = $_POST['RegistrationForm'];
         // Create password
         $model->encryptPassword($model->textPassword);
         // Validate Form
         if ($model->validate()) {
             // Create code activation
             $codeActivation = $model->createCodeActivation();
             // Create user
             if ($model->save()) {
                 // Assign user to Awaiting role
                 //Rights::assign(Yii::app()->params['roles']['AWAITING'], $model->id);
                 if ($codeActivation != '') {
                     /**
                      * @todo Change message email
                      */
                     $strActivationUrl = $this->createAbsoluteUrl('/user/activation/activate', array("activekey" => $codeActivation, "email" => $model->email));
                     $strMsgHTML = "<a href='{$strActivationUrl}'>{$strActivationUrl}</a>";
                     Yii::import('application.extensions.phpmailer.HMailHelper');
                     HMailHelper::Send('Activation Account', $strMsgHTML, array(array($model->email, $model->firstname)));
                 } else {
                     //BUG: Không thể tạo code
                 }
                 $this->setRedirectOptions(array("title" => UserModule::t('Registration Success'), "message" => UserModule::t('The registration was successful!')));
                 $this->redirect('/user/login');
             }
         }
     }
     $this->render('index', array('model' => $model));
 }
 public function actionActivate()
 {
     // Validate Code activation
     if (isset($_GET['activekey']) && isset($_GET['email'])) {
         $strActivateCode = $_GET['activekey'];
         $strEmail = $_GET['email'];
         $user = User::model()->notsafe()->findByAttributes(array('email' => $strEmail));
         if (isset($user)) {
             if ($user->status == User::STATUS_ACTIVE) {
                 $this->setRedirectOptions(array("title" => UserModule::t('Activation Was Successful'), "message" => UserModule::t('This account has been activated!')));
                 $this->redirect("/user/profile");
             }
             // Check Code
             if ($user->activkey == $strActivateCode) {
                 // Active user
                 $user->status = User::STATUS_ACTIVE;
                 // Delete active code
                 $user->activkey = $user->createCodeActivation();
                 $user->save();
                 // Change role to Member
                 //Rights::revoke(Yii::app()->params['roles']['AWAITING'], $user->id);
                 //Rights::assign(Yii::app()->params['roles']['MEMBER'], $user->id);
                 /**
                  * @todo Change message email
                  */
                 $strMsgHTML = "Activation success";
                 Yii::import('application.extensions.phpmailer.HMailHelper');
                 HMailHelper::Send('Activation Account', $strMsgHTML, array(array($user->email, $user->username)));
                 // Notice activation success
                 $this->setRedirectOptions(array("title" => UserModule::t('Activation Success'), "message" => UserModule::t('You account is activated!')));
                 $this->redirect("/user/profile");
             } else {
                 // Notice activation failure
                 $this->setRedirectOptions(array("title" => UserModule::t('Activation Email Failure'), "message" => UserModule::t('Incorrect activation URL or Activation period has expired!')));
                 $this->redirect("/user/profile");
             }
         }
     }
     // Notice activation failure
     $this->setRedirectOptions(array("title" => UserModule::t('Activation Email Failure'), "message" => UserModule::t('Incorrect activation URL!')));
     $this->redirect("/user/profile");
 }
 /**
  * Action ChangeEmail dùng để đổi email của user
  */
 public function actionChangeEmail()
 {
     // Bước 1: Người dùng yêu cầu change email
     if (empty($_GET['code'])) {
         // Submit form
         if (isset($_POST['changepassword'])) {
             $user = User::model()->notsafe()->findByPk(Yii::app()->user->id);
             $user->activkey = $user->createCodeActivation();
             $user->save();
             // Create Code change email
             $codeChangeEmail = $user->activkey;
             if ($codeChangeEmail != '') {
                 /**
                  * @todo Change message email
                  */
                 $strChangeEmailUrl = $this->createAbsoluteUrl('/user/profile/changeemail', array("code" => $codeChangeEmail));
                 $strMsgHTML = "<a href='{$strChangeEmailUrl}'>{$strChangeEmailUrl}</a>";
                 Yii::import('application.extensions.phpmailer.HMailHelper');
                 HMailHelper::Send('Change Email', $strMsgHTML, array(array($user->email, $user->username)));
                 // Notice Sent mail validate for change password
                 $this->setRedirectOptions(array("timeout" => 5, "title" => UserModule::t('Change Email - Step 1'), "message" => UserModule::t('We have sent you a confirmation email to the email change. Please check and verify it!')));
                 $this->redirect('/user/profile');
             }
         }
         // Render form requirement change email
         $this->render('changeemailstep1');
     } else {
         // Bước 2: Đổi email
         // Validate code change email
         $strChangeEmailCode = $_GET['code'];
         $user = User::model()->notsafe()->findByPk(Yii::app()->user->id);
         // Check Code
         if ($strChangeEmailCode == $user->activkey) {
             $model = new ChangeEmailForm();
             // Submit form
             if (isset($_POST['ChangeEmailForm'])) {
                 $model->attributes = $_POST['ChangeEmailForm'];
                 $user = User::model()->notsafe()->findByPk(Yii::app()->user->id);
                 //$model->user = $user;
                 // Validate info
                 if ($model->validate()) {
                     // Change email
                     $user->email = $model->email;
                     // Delete old Code change email
                     $user->activkey = $user->createCodeActivation();
                     // Save new email to DB
                     if ($user->save()) {
                         /**
                          * @todo Change message email
                          */
                         $strMsgHTML = "Change Email Success";
                         Yii::import('application.extensions.phpmailer.HMailHelper');
                         HMailHelper::Send('Change Email', $strMsgHTML, array(array($user->email, $user->username)));
                         // Notice Change Email success
                         $this->setRedirectOptions(array("title" => UserModule::t('Change Email Success'), "message" => UserModule::t('The change email was successful!')));
                         $this->redirect('/user/profile');
                     }
                 }
             }
             // Render form change email
             $this->render('changeemailstep2', array('model' => $model));
             Yii::app()->end();
         }
         // Notice activation failure
         $this->setRedirectOptions(array("title" => UserModule::t('Change Email Failure'), "message" => UserModule::t('Incorrect change email URL!')));
         $this->redirect("/");
     }
 }