Example #1
0
 public function init()
 {
     parent::init();
     $this->params['formButtons'] = array('login' => array('type' => 'submit', 'label' => Yii::t('UnitLogin.main', 'Login'), 'title' => Yii::t('UnitLogin.main', 'Login')));
     $this->params['doRemember'] = Yii::app()->request->getPost('RememberForm') !== null;
     if ($this->proccessRequest()) {
         if ($this->params['doRemember']) {
             $this->params['doneRemember'] = true;
         } else {
             Yii::app()->controller->refresh();
         }
     }
     if (Yii::app()->request->getParam('authcode') !== null) {
         $user = User::model()->find('`authcode`=:authcode', array('authcode' => Yii::app()->request->getParam('authcode')));
         if ($user) {
             $identity = new AuthCodeIdentity(Yii::app()->request->getParam('authcode'));
             $identity->authenticate();
             if ($identity->errorCode === UserIdentity::ERROR_NONE) {
                 Yii::app()->user->login($identity);
             }
             $user->saveAttributes(array('authcode' => '', 'askfill' => true));
             Yii::app()->controller->refresh();
         }
     }
 }
Example #2
0
 public function init()
 {
     parent::init();
     if (Yii::app()->request->getQuery($this->urlParam('do')) !== null) {
         $this->params['doParam'] = Yii::app()->request->getQuery($this->urlParam('do'));
     }
     if (($this->params['isGuest'] || $this->params['editMode']) && $this->params['doParam'] != 'edit') {
         $model = new User('register');
         $makeForm = $model->makeForm('register', $this->params['content']->fields, $this->params['content']->fields_req);
         $this->params['formElements'] = $makeForm['elements'];
         $this->params['formRules'] = $makeForm['rules'];
         if (Yii::app()->request->getParam('ajax-validate') !== null) {
             echo CActiveForm::validate($model);
             Yii::app()->end();
         }
         if ($this->proccessRequest()) {
             if ($this->params['content']->is_emailauth_req) {
                 $this->params['waitingAuthCode'] = true;
             } else {
                 $this->params['justRegistered'] = true;
             }
         }
         if (Yii::app()->request->getParam('authocode')) {
             $user = User::model()->find('`authcode`=:authcode', array('authcode' => Yii::app()->request->getParam('authocode')));
             if ($user) {
                 $identity = new AuthCodeIdentity(Yii::app()->request->getParam('authocode'));
                 $identity->authenticate();
                 if ($identity->errorCode === UserIdentity::ERROR_NONE) {
                     Yii::app()->user->login($identity);
                 }
                 $user->saveAttributes(array('active' => true, 'authcode' => ''));
                 $cfg = ContentUnit::loadConfig();
                 $viewFileDir = $cfg['UnitRegister'] . '.register.templates.mail.';
                 $tpldata = array('model' => $user, 'settings' => Yii::app()->settings->model->getAttributes(), 'page' => $this->params['content']->getWidgetPageArray());
                 if ($this->params['content']->notify_user) {
                     // send 'to_user_notify' mail
                     Yii::app()->messenger->send('email', $user->email, Yii::t('UnitRegister.main', 'Registration completed'), Yii::app()->controller->renderPartial($viewFileDir . 'to_user_notify', $tpldata, true));
                 }
                 $this->params['confirmedAuthCode'] = true;
                 unset($_REQUEST['authcode']);
             } else {
                 $this->params['faultAuthCode'] = true;
             }
         }
     } else {
         if ($this->params['isGuest']) {
             $this->params['accessDenied'] = true;
         } else {
             $makeForm = $this->params['user']->makeForm('update', $this->params['content']->profile_fields, $this->params['content']->profile_fields_req);
             $this->params['formElements'] = $makeForm['elements'];
             $this->params['formRules'] = $makeForm['rules'];
             $profileModel = ModelProfiles::model()->find('widget_id > 0');
             $profileWidget = new WidgetProfiles();
             if ($profileModel) {
                 $this->params['profileWidgetUrl'] = $profileModel->getWidgetUrl();
             }
             $this->params['profileWidgetUrlParams'] = $profileWidget->urlParam('view') . '=' . $this->params['user']->id;
             if (Yii::app()->request->getParam('ajax-validate') !== null) {
                 echo CActiveForm::validate($this->params['user']);
                 Yii::app()->end();
             }
             if (Yii::app()->request->getPost('User') !== null) {
                 $this->params['user']->attributes = Yii::app()->request->getPost('User');
                 if ($this->params['user']->save()) {
                     Yii::app()->user->setFlash('save-permanent', Yii::t('UnitRegister.main', 'Profile edited successfully'));
                     Yii::app()->controller->refresh();
                 }
             }
         }
     }
 }