Author: Tuan Nguyen (nganhtuan63@gmail.com)
Inheritance: extends CWidget
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         //Set Params from Block Params
         $params = unserialize($this->block->params);
         $this->setParams($params);
         $post_id = (int) $_GET['id'];
         if ($post_id) {
             $post = Object::model()->findByPk($post_id);
             if ($post) {
                 Yii::app()->controller->pageTitle = CHtml::encode($post->object_name);
                 Yii::app()->controller->description = CHtml::encode($post->object_description);
                 Yii::app()->controller->keywords = CHtml::encode($post->object_keywords);
                 Yii::app()->controller->change_title = true;
                 $this->render(BlockRenderWidget::setRenderOutput($this), array('post' => $post));
             } else {
                 throw new CHttpException('404', t('Page not found'));
             }
         } else {
             throw new CHttpException('404', t('Page not found'));
         }
     } else {
         echo '';
     }
 }
Example #2
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UploadImageForm();
         $img = false;
         if (isset($_POST['UploadImageForm'])) {
             $model->attributes = $_POST['UploadImageForm'];
             $model->image = CUploadedFile::getInstance($model, 'image');
             if ($model->validate()) {
                 if (!$model->image) {
                     if (!$model->image_url) {
                         $model->addError('image', 'Bạn cần chọn File để upload');
                     } else {
                         $this->sendToImgUr($img, $model, $model->image_url, 'url');
                     }
                 } else {
                     $filename = $model->image->tempName;
                     $handle = fopen($filename, "r");
                     $data = fread($handle, filesize($filename));
                     $this->sendToImgUr($img, $model, $data);
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model, 'img' => $img));
     } else {
         echo '';
     }
 }
Example #3
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         if (isset($_GET['required'])) {
             user()->setFlash('error', t('You need to sign in before continue'));
         }
         $model = new UserLoginForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserLoginForm'])) {
             $model->attributes = $_POST['UserLoginForm'];
             // validate user input and redirect to the previous page if valid
             if ($model->validate() && $model->login()) {
                 user()->setFlash('error', null, null);
                 Yii::app()->controller->redirect(user()->returnUrl);
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $this->render(BlockRenderWidget::setRenderOutput($this), array());
     } else {
         echo '';
     }
 }
Example #5
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserAvatarForm();
         if (isset($_POST['UserAvatarForm'])) {
             $model->attributes = $_POST['UserAvatarForm'];
             $model->image = CUploadedFile::getInstance($model, 'image');
             if ($model->validate()) {
                 //Get the User Id to determine the folder
                 $folder = user()->id >= 1000 ? (string) (round(user()->id / 1000) * 1000) : '1000';
                 $filename = user()->id . '_' . gen_uuid();
                 if (!(file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder) && AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder)) {
                     mkdir(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder, 0777, true);
                 }
                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name)))) {
                     $filename .= '_' . time();
                 }
                 $filename = $filename . '.' . strtolower(CFileHelper::getExtension($model->image->name));
                 $path = $folder . DIRECTORY_SEPARATOR . $filename;
                 if ($model->image->saveAs(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $path)) {
                     //Generate thumbs
                     //
                     GxcHelpers::generateAvatarThumb($filename, $folder, $filename);
                     //So we will start to check the info from the user
                     $current_user = User::model()->findByPk(user()->id);
                     if ($current_user) {
                         if ($current_user->avatar != null && $current_user->avatar != '') {
                             //We will delete the old avatar here
                             $old_avatar_path = $current_user->avatar;
                             $current_user->avatar = $path;
                             if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                 @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR . $old_avatar_path);
                             }
                             //Delete old file Sizes
                             $sizes = AvatarSize::getSizes();
                             foreach ($sizes as $size) {
                                 if (file_exists(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path)) {
                                     @unlink(AVATAR_FOLDER . DIRECTORY_SEPARATOR . $size['id'] . DIRECTORY_SEPARATOR . $old_avatar_path);
                                 }
                             }
                         } else {
                             //$current_user
                             $current_user->avatar = $path;
                         }
                         $current_user->save();
                     }
                 } else {
                     throw new CHttpException('503', 'Error while uploading!');
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
Example #6
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserRegisterForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'userregister-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserRegisterForm'])) {
             $model->attributes = $_POST['UserRegisterForm'];
             // validate user input password
             if ($model->validate()) {
                 $new_user = new User();
                 $new_user->scenario = 'create';
                 //$new_user->username=$model->username;
                 $new_user->username = $new_user->email = $model->email;
                 $new_user->display_name = $model->username;
                 $old_password = $new_user->password = $model->password;
                 //Create hash activation key
                 $new_user->user_activation_key = md5(time() . $new_user->username . USER_SALT);
                 if ($new_user->save()) {
                     //We will send mail for the user
                     $ses = new SimpleEmailService(ConstantDefine::AMAZON_SES_ACCESS_KEY, ConstantDefine::AMAZON_SES_SECRET_KEY);
                     $ses->enableVerifyHost(false);
                     $m = new SimpleEmailServiceMessage();
                     $m->addTo($new_user->email);
                     $m->setFrom(ConstantDefine::AMAZON_SES_EMAIL);
                     $m->setSubject('[' . SITE_NAME . '] Confirm your email at ' . SITE_NAME_URL);
                     $m_content = 'Hi ' . $new_user->display_name . '<br /><br />';
                     $m_content .= 'Welcome to ' . SITE_NAME . '! Please take a second to confirm ' . $new_user->email . ' as your email address by clicking this link: <br /><br />';
                     $link_content = FRONT_SITE_URL . '/user-activation/?key=' . $new_user->user_activation_key . '&user_id=' . $new_user->user_id;
                     $m_content .= '<a href="' . $link_content . '">' . $link_content . '</a><br /><br />';
                     $m_content .= 'Thank you for being with us!<br /><br />';
                     $m_content .= SITE_NAME . ' Team';
                     $m->setMessageFromString($m_content, $m_content);
                     $ses->sendEmail($m);
                     //Redirect to the Dashboard Page
                     $login_form = new UserLoginForm();
                     $login_form->username = $new_user->username;
                     $login_form->password = $old_password;
                     if ($login_form->login()) {
                         Yii::app()->controller->redirect(bu());
                     } else {
                         throw new CHttpException(503, t('Error while setting up your Account. Please try again later'));
                     }
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
Example #7
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         //Set Params from Block Params
         $params = b64_unserialize($this->block['params']);
         $this->setParams($params);
         $this->render(BlockRenderWidget::setRenderOutput($this), array());
     } else {
         echo '';
     }
 }
Example #8
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $params = unserialize($this->block->params);
         $this->setParams($params);
         $menu_r0_items = self::getMenuItems(0, $this->menu_id);
         $this->render(BlockRenderWidget::setRenderOutput($this), array('menu_r0_items' => $menu_r0_items));
     } else {
         echo '';
     }
 }
Example #9
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserChangePassForm();
         $model_notify = new UserNotifyForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepass-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'notify-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         $u = User::model()->findbyPk(user()->id);
         if ($u !== null) {
             //Set Email Notify from User
             $model_notify->email_site_news = $u->email_site_news;
             $model_notify->email_search_alert = $u->email_search_alert;
             // collect user input data
             if (isset($_POST['UserChangePassForm'])) {
                 $model->attributes = $_POST['UserChangePassForm'];
                 // validate user input password
                 if ($model->validate()) {
                     $u->password = $u->hashPassword($model->new_password_1, USER_SALT);
                     $u->salt = USER_SALT;
                     if ($u->save()) {
                         user()->setFlash('success', t('Change Password Successfully!'));
                     }
                     $model = new UserChangePassForm();
                 }
             }
             // collect user input data
             if (isset($_POST['UserNotifyForm'])) {
                 $model_notify->attributes = $_POST['UserNotifyForm'];
                 // validate user input password
                 if ($model_notify->validate()) {
                     $u->email_site_news = $model_notify->email_site_news;
                     $u->email_search_alert = $model_notify->email_search_alert;
                     if ($u->save()) {
                         user()->setFlash('success', t('Update Notification Successfully!'));
                     }
                 }
             }
         } else {
             throw new CHttpException('403', 'User is not existed');
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model, 'model_notify' => $model_notify));
     } else {
         echo '';
     }
 }
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserRecoverPassForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'recoverpassword-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserRecoverPassForm'])) {
             $model->attributes = $_POST['UserRecoverPassForm'];
             // validate user input and redirect to the previous page if valid
             if ($model->validate()) {
                 //Find the user with the email
                 $user = User::model()->find('email=:email', array(':email' => $model->email));
                 if ($user) {
                     //Create a new password recover key
                     $key = md5(USER_RECOVER_PASS_SALT . time() . $user->username . $user->email);
                     $user->email_recover_key = $key;
                     if ($user->save()) {
                         $ses = new SimpleEmailService(ConstantDefine::AMAZON_SES_ACCESS_KEY, ConstantDefine::AMAZON_SES_SECRET_KEY);
                         $ses->enableVerifyHost(false);
                         $m = new SimpleEmailServiceMessage();
                         $m->addTo($user->email);
                         $m->setFrom(ConstantDefine::AMAZON_SES_EMAIL);
                         $m->setSubject('[' . SITE_NAME . '] Password reset instructions');
                         $m_content = 'Hi ' . $user->display_name . '<br /><br />';
                         $m_content .= 'A request to reset your ' . SITE_NAME . ' password has been made. If you did not make this request, simply ignore this email. If you did make this request, just click the link below:<br /><br />';
                         $link_content = FRONT_SITE_URL . '/reset-password/?key=' . $user->email_recover_key . '&user_id=' . $user->user_id;
                         $m_content .= '<a href="' . $link_content . '">' . $link_content . '</a><br /><br />';
                         $m_content .= 'If the URL above does not work, try copying and pasting it into your browser.<br /><br />';
                         $m_content .= 'If you continue to have problems, please feel free to contact us: <a href="mailto:' . ConstantDefine::SUPPORT_EMAIL . '">' . ConstantDefine::SUPPORT_EMAIL . '</a><br /><br />';
                         $m_content .= 'Thank you for being with us!<br /><br />';
                         $m_content .= SITE_NAME . ' Team';
                         $m->setMessageFromString($m_content, $m_content);
                         $ses->sendEmail($m);
                         user()->setFlash('success', 'Instructions to reset your password have been sent to you. Please check your email.');
                         Yii::app()->controller->redirect(bu() . '/sign-in');
                     }
                 } else {
                     user()->setFlash('error', 'Email is not existed');
                 }
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
Example #11
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $params = unserialize($this->block->params);
         $this->setParams($params);
         $menu_r0_items = Yii::app()->cache->get('menu_r0_' . $this->menu_id);
         if ($menu_r0_items === false) {
             $menu_r0_items = self::getMenuItems(0, $this->menu_id);
             Yii::app()->cache->set('menu_r0_' . $this->menu_id, $menu_r0_items, 7200);
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('menus' => $menu_r0_items));
     } else {
         echo '';
     }
 }
Example #12
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserProfileForm();
         //Set basic info for Current user
         //Get the user by current Id
         $user_info = User::model()->findByPk(user()->id);
         if ($user_info) {
             $model->display_name = $user_info->display_name;
             $model->email = $user_info->email;
             $model->bio = $user_info->bio;
             $model->gender = $user_info->gender;
             $model->location = $user_info->location;
             $model->birthday_day = $user_info->birthday_day;
             $model->birthday_month = $user_info->birthday_month;
             $model->birthday_year = $user_info->birthday_year;
         } else {
             throw new CHttpException('503', 'User is not valid');
         }
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserProfileForm'])) {
             $model->attributes = $_POST['UserProfileForm'];
             // validate user input and redirect to the previous page if valid
             if ($model->validate()) {
                 $user_info->scenario = 'update';
                 $user_info->display_name = $model->display_name;
                 $user_info->gender = $model->gender;
                 $user_info->location = $model->location;
                 $user_info->bio = $model->bio;
                 $user_info->birthday_day = $model->birthday_day;
                 $user_info->birthday_month = $model->birthday_month;
                 $user_info->birthday_year = $model->birthday_year;
                 $user_info->save();
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         //Set Params from Block Params
         $params = unserialize($this->block->params);
         $this->setParams($params);
         $post_id = (int) $_GET['id'];
         if ($post_id) {
             $post = Object::model()->findByPk($post_id);
             if ($post) {
                 $this->render(BlockRenderWidget::setRenderOutput($this), array('post' => $post));
             } else {
                 throw new CHttpException('404', t('Page not found'));
             }
         } else {
             throw new CHttpException('404', t('Page not found'));
         }
     } else {
         echo '';
     }
 }
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         if (isset($_GET['key']) && $_GET['user_id']) {
             $key = $_GET['key'];
             $user_id = (int) $_GET['user_id'];
             //Find the user
             $user = User::model()->findByPk($user_id);
             if ($user && $user->email_recover_key != '') {
                 $model = new UserResetPasswordForm();
                 // if it is ajax validation request
                 if (isset($_POST['ajax']) && $_POST['ajax'] === 'resetpassword-form') {
                     echo CActiveForm::validate($model);
                     Yii::app()->end();
                 }
                 // collect user input data
                 if (isset($_POST['UserResetPasswordForm'])) {
                     $model->attributes = $_POST['UserResetPasswordForm'];
                     // validate user input and redirect to the previous page if valid
                     if ($model->validate()) {
                         $user->email_recover_key = '';
                         $user->salt = USER_SALT;
                         $user->password = User::model()->hashPassword($model->password, USER_SALT);
                         if ($user->save()) {
                             user()->setFlash('success', 'Your password has been reset.');
                             Yii::app()->controller->redirect(bu() . '/sign-in');
                         }
                     }
                 }
                 $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
             } else {
                 Yii::app()->controller->redirect(bu() . '/sign-in');
             }
         } else {
             Yii::app()->controller->redirect(bu() . '/sign-in');
         }
     } else {
         echo '';
     }
 }
Example #15
0
 protected function renderContent()
 {
     if (isset($this->block) && $this->block != null) {
         $model = new UserLoginForm();
         // if it is ajax validation request
         if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         // collect user input data
         if (isset($_POST['UserLoginForm'])) {
             $model->attributes = $_POST['UserLoginForm'];
             // validate user input and redirect to the previous page if valid
             if ($model->validate() && $model->login()) {
                 Yii::app()->controller->redirect(bu() . '/dashboard');
             }
         }
         $this->render(BlockRenderWidget::setRenderOutput($this), array('model' => $model));
     } else {
         echo '';
     }
 }