/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionEdit()
 {
     $model = $this->loadUser();
     $profile = $model->profile;
     //add this code:
     UWprofilepic::handleProfilePic($model, $profile);
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $model->save();
             $profile->save();
             Yii::app()->user->updateSession();
             Yii::app()->user->setFlash('profileMessage', UserModule::t("Changes is saved."));
             $this->redirect(array('profile'));
         } else {
             $profile->validate();
         }
     }
     $this->render('edit', array('model' => $model, 'profile' => $profile));
 }
Пример #2
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionEdit()
 {
     $model = $this->loadUser();
     $social = Social::model()->find("provider='facebook' AND yiiuser=" . Yii::app()->user->id);
     $profile = $model->profile;
     UWprofilepic::handleProfilePic($model, $profile);
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (isset($_POST['Profile'])) {
         $model->attributes = $_POST['User'];
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $model->save();
             $profile->save();
             Yii::app()->user->setFlash('success', 'Your changes have been saved successfully.');
             $this->redirect('/user/profile/edit/');
         } else {
             $profile->validate();
         }
     }
     $this->render('edit', array('model' => $model, 'social' => $social, 'profile' => $profile));
 }
 /**
  * Registration user
  */
 public function actionRegistration()
 {
     Profile::$regMode = true;
     $model = new RegistrationForm();
     $profile = new Profile();
     UWprofilepic::handleProfilePic($model, $profile);
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = UserModule::encrypting(microtime() . $model->password);
                 $model->password = UserModule::encrypting($model->password);
                 $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel();
     $profile = $model->profile;
     $auth = $model->auth;
     //profile pic
     UWprofilepic::handleProfilePic($model, $profile);
     $this->performAjaxValidation(array($model, $profile));
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         $profile->attributes = $_POST['Profile'];
         if ($model->validate() && $profile->validate()) {
             $old_password = User::model()->notsafe()->findByPk($model->id);
             if ($old_password->password != $model->password) {
                 $model->password = Yii::app()->controller->module->encrypting($model->password);
                 $model->activkey = Yii::app()->controller->module->encrypting(microtime() . $model->password);
             }
             if ($model->save()) {
                 // roles
                 $auth->itemname = $_POST['User']['auth'];
                 $auth->save();
                 $profile->save();
                 $this->redirect(array('view', 'id' => $model->id));
             }
         } else {
             $profile->validate();
         }
     }
     $this->render('update', array('model' => $model, 'profile' => $profile));
 }