コード例 #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);
         }
     }
 }
コード例 #2
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * 
  * @param integer $id
  *        	the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $request = Yii::app()->request;
     $formData = $request->getPost(get_class($model), false);
     /* TODO
     		 * Display a lint to s3 URL
     		 *
     		$s3_dirname = sprintf('userid_%s', $model->id);
     		$s3 = new S3(Yii::app()->params['s3d']['access_key'], Yii::app()->params['s3d']['secret_key']);
     		
     		$s3url = $s3->getBucketLocation('mbtx');
     			*/
     $s3url = '#';
     if ($formData) {
         $model->attributes = $formData;
         if (array_key_exists('save', $formData)) {
             if ($model->save()) {
                 $this->redirect(array('index'));
             }
         } elseif (array_key_exists('verify', $formData)) {
             if ($model->verify) {
                 $model->verify->delete();
             } else {
                 $newv = new UserVerify();
                 $newv->id_user = $model->id;
                 if (!$newv->save()) {
                     Yii::app()->user->setFlash('error', Yii::t('translation', 'Unable to verify user'));
                 }
             }
             $this->redirect(array('index'));
         } elseif (array_key_exists('activate', $formData)) {
             if ($model->activation_time) {
                 $model->activation_time = 0;
             } else {
                 $model->activation_time = time();
             }
             if ($model->save()) {
                 $this->redirect(array('index'));
             }
         }
     }
     $this->render('update', compact('model', 's3url'));
 }