Exemplo n.º 1
0
 /**
  * After save attributes
  */
 protected function afterSave()
 {
     parent::afterSave();
     $controller = strtolower(Yii::app()->controller->id);
     $currentAction = strtolower(Yii::app()->controller->id . '/' . Yii::app()->controller->action->id);
     // Generate Verification Code
     if ($this->verified == 0) {
         $verify = new UserVerify();
         $verify->user_id = $this->user_id;
         $verify->save();
     }
     if ($this->isNewRecord) {
         $setting = OmmuSettings::model()->findByPk(1, array('select' => 'site_type, signup_welcome, signup_adminemail'));
         if ($setting->site_type == 1) {
             $invite = UserInviteQueue::model()->findByAttributes(array('email' => strtolower($this->email)), array('select' => 'queue_id, member_id, reference_id'));
             if ($invite != null && $invite->member_id == 0) {
                 $invite->member_id = $this->user_id;
                 if ($this->referenceId != '') {
                     $invite->reference_id = $this->referenceId;
                 }
                 $invite->update();
             }
         }
         // Send Welcome Email
         if ($setting->signup_welcome == 1) {
             $welcome_search = array('{$baseURL}', '{$index}', '{$displayname}');
             $welcome_replace = array(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->request->baseUrl, Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('site/index'), $this->displayname);
             $welcome_template = 'user_welcome';
             $welcome_title = 'Welcome to SSO-GTP by BPAD Yogyakarta';
             $welcome_message = file_get_contents(YiiBase::getPathOfAlias('webroot.externals.users.template') . '/' . $welcome_template . '.php');
             $welcome_ireplace = str_ireplace($welcome_search, $welcome_replace, $welcome_message);
             SupportMailSetting::sendEmail($this->email, $this->displayname, $welcome_title, $welcome_ireplace, 1);
         }
         // Send Account Information
         $account_search = array('{$baseURL}', '{$login}', '{$displayname}', '{$email}', '{$password}');
         $account_replace = array(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->request->baseUrl, Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('site/login'), $this->displayname, $this->email, $this->newPassword);
         $account_template = 'user_welcome_account';
         $account_title = 'SSO-GTP Account (' . $this->displayname . ')';
         $account_message = file_get_contents(YiiBase::getPathOfAlias('webroot.externals.users.template') . '/' . $account_template . '.php');
         $account_ireplace = str_ireplace($account_search, $account_replace, $account_message);
         SupportMailSetting::sendEmail($this->email, $this->displayname, $account_title, $account_ireplace, 1);
         // Send New Account to Email Administrator
         if ($setting->signup_adminemail == 1) {
             SupportMailSetting::sendEmail($this->email, $this->displayname, 'New Member', 'informasi member terbaru', 0);
         }
     } else {
         // Send Account Information
         //if($this->enabled == 1) {}
         if ($controller == 'password') {
             $account_search = array('{$baseURL}', '{$login}', '{$displayname}', '{$email}', '{$password}');
             $account_replace = array(Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->request->baseUrl, Utility::getProtocol() . '://' . Yii::app()->request->serverName . Yii::app()->createUrl('site/login'), $this->displayname, $this->email, $this->newPassword);
             $account_template = 'user_forgot_new_password';
             $account_title = 'Your password changed';
             $account_message = file_get_contents(YiiBase::getPathOfAlias('webroot.externals.users.template') . '/' . $account_template . '.php');
             $account_ireplace = str_ireplace($account_search, $account_replace, $account_message);
             SupportMailSetting::sendEmail($this->email, $this->displayname, $account_title, $account_ireplace, 1);
         }
         if ($controller == 'verify') {
             SupportMailSetting::sendEmail($this->email, $this->displayname, 'Verify Email Success', 'Verify Email Success', 1);
         }
     }
 }
 /**
  * before validate attributes
  */
 protected function beforeValidate()
 {
     $module = strtolower(Yii::app()->controller->module->id);
     $controller = strtolower(Yii::app()->controller->id);
     if (parent::beforeValidate()) {
         if ($this->email != '') {
             $model = UserInviteQueue::model()->findByAttributes(array('email' => strtolower($this->email)), array('select' => 'queue_id, member_id, invite'));
             if ($model == null) {
                 // email belum masuk daftar invite
                 $invite = new UserInviteQueue();
                 $invite->email = $this->email;
                 if ($invite->save()) {
                     $this->queue_id = $invite->queue_id;
                 }
             } else {
                 // email sudah dalam daftar invite
                 if ($module != null && $module == 'users' && $controller == 'invite') {
                     if ($model->member_id != 0) {
                         // email sudah menjadi member
                         $this->addError('email', Phrase::trans(16213, 1));
                     } else {
                         // email belum menjadi member
                         $invite = self::model()->with('queue')->find(array('select' => 'invite_id', 'condition' => 'queue.email = :email AND t.user_id = :user', 'params' => array(':email' => strtolower($this->email), ':user' => Yii::app()->user->id)));
                         if ($invite == null) {
                             $this->queue_id = $model->queue_id;
                         } else {
                             // email sudah invite sebelumnya
                             $this->addError('email', Phrase::trans(16212, 1));
                         }
                     }
                 }
             }
         }
         if ($this->isNewRecord) {
             $this->user_id = Yii::app()->user->id;
             $this->code = self::getUniqueCode();
             $this->invite_ip = $_SERVER['REMOTE_ADDR'];
         }
     }
     return true;
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionQueuedelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         if (isset($id)) {
             UserInviteQueue::model()->findByPk($id)->delete();
             echo CJSON::encode(array('type' => 5, 'get' => Yii::app()->controller->createUrl('queuemanage'), 'id' => 'partial-user-invite-queue', 'msg' => '<div class="errorSummary success"><strong>' . Phrase::trans(16219, 1) . '</strong></div>'));
         }
     } else {
         $this->dialogDetail = true;
         $this->dialogGroundUrl = Yii::app()->controller->createUrl('queuemanage');
         $this->dialogWidth = 350;
         $this->pageTitle = Phrase::trans(16218, 1);
         $this->pageDescription = '';
         $this->pageMeta = '';
         $this->render('admin_queue_delete');
     }
 }