public function executeProfile(sfWebRequest $request) { $user = $this->getUser(); $i18n = $this->getContext()->getI18N(); $form = new ProfileForm($user->getProfile(), array('user' => $user)); if ($request->isMethod('post')) { $config = $request->getParameter('config'); $form->bind($config); if ($form->isValid()) { $form->save(); $culture = $config['language']; if (isset($config['country'])) { $country = $config['country']; } else { $country = null; } if ($country) { $culture .= '_' . $country; } $user->setCulture($culture); $user->info($i18n->__('Your settings were successfully saved.')); $this->redirect('@profile'); } else { $user->error($i18n->__('Settings could not be saved. Please, check entered values and try to correct them.'), false); } } $this->form = $form; }
public function testUserEmailChange() { $newEmail = '*****@*****.**'; $model = $this->user; $profileForm = new ProfileForm(); $this->assertTrue($model !== NULL); $profileForm->load($model->id, true); $profileForm->email = $newEmail; // Verify that the profile form saves $this->assertTrue($profileForm->save()); // Verify that the base user model didn't change $model = $this->getUserModel(); $this->assertTrue($model->email == '*****@*****.**'); $newEmailModel = UserMetadata::model()->findByAttributes(array('user_id' => $this->user->id, 'key' => 'newEmailAddress')); // Verify that the new email is stored in the database $this->assertTrue($newEmailModel !== NULL); $this->assertTrue($newEmailModel->value == $newEmail); $key = UserMetadata::model()->findByAttributes(array('user_id' => $this->user->id, 'key' => 'newEmailAddressChangeKey')); $this->assertTrue($key !== NULL); $emailChangeForm = new EmailChangeForm(); $emailChangeForm->setUser($this->getUserModel()); $emailChangeForm->verificationKey = $key->value; $emailChangeForm->password = '******'; // Verify that the verification key works $this->assertTrue($emailChangeForm->validateVerificationKey()); // Veirfy that the email address changes $this->assertTrue($emailChangeForm->validate()); $this->assertTrue($emailChangeForm->save()); // Verify that the email has changed for the model now $model = Users::model()->findByAttributes(array('email' => '*****@*****.**')); $this->assertTrue($model->email == $newEmail); }
public function save($con = null) { $values = $this->getValues(); $presetList = opToolkit::getPresetProfileList(); $presetName = $values['preset']; $preset = $presetList[$presetName]; $values = $this->mergePresetAndValues($preset, $values); $values['name'] = 'op_preset_' . $values['name']; unset($values['preset'], $values['choices'], $values['caption']); $this->values = $values; parent::save($con); }
public function actionIndex() { $user = User::model()->findByPk(Yii::app()->user->id); $form = new ProfileForm(); if (isset($_POST['ProfileForm'])) { $form->attributes = $_POST['ProfileForm']; $form->newpassword_repeat = $_POST['ProfileForm']['newpassword_repeat']; if ($form->save()) { Yii::app()->user->setFlash('success', 'Your information has been successfully changed'); } else { Yii::app()->user->setFlash('danger', 'There was an error updating your information'); } } $this->render('index', array('user' => $user, 'profileform' => $form)); }
/** * Provides functionality for a user to edit their profile */ public function actionEdit() { $model = new ProfileForm(); $model->load(Yii::app()->user->id); if (Cii::get($_POST, 'ProfileForm', NULL) !== NULL) { $model->attributes = $_POST['ProfileForm']; $model->password_repeat = $_POST['ProfileForm']['password_repeat']; if ($model->save()) { Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'Your profile has been updated!')); $this->redirect($this->createUrl('profile/index', array('id' => $model->id, 'username' => $model->username))); } else { Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There were errors saving your profile. Please correct them before trying to save again.')); } } $this->render('edit', array('model' => $model)); }
protected function registerLocalProfile(ProfileForm $localProfile, HybridauthForm $remoteLogin, $localIdentity = false) { if (!isset($_POST['ProfileForm']) && $localIdentity === false) { $userIdentityClass = $localProfile->userIdentityClass; $remoteProfile = $remoteLogin->getHybridAuthAdapter()->getUserProfile(); $localProfile->setAttributes($userIdentityClass::getRemoteAttributes($remoteProfile)); $localProfile->validate(); return $localProfile; } if ($localIdentity !== false) { $userIdentityClass = $localProfile->userIdentityClass; $remoteProfile = $remoteLogin->getHybridAuthAdapter()->getUserProfile(); $localProfile->setAttributes($userIdentityClass::getRemoteAttributes($remoteProfile)); } if (isset($_POST['ProfileForm']) && is_array($_POST['ProfileForm'])) { $localProfile->setAttributes($_POST['ProfileForm']); } if (!$localProfile->validate()) { return $localProfile; } $trx = Yii::app()->db->beginTransaction(); if (!$localProfile->save($this->module->requireVerifiedEmail)) { $trx->rollback(); Yii::app()->user->setFlash('error', Yii::t('UsrModule.usr', 'Failed to register a new user.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.')); return $localProfile; } $trx->commit(); if ($this->module->requireVerifiedEmail) { if ($this->sendEmail($localProfile, 'verify')) { Yii::app()->user->setFlash('success', Yii::t('UsrModule.usr', 'An email containing further instructions has been sent to the provided email address.')); } else { Yii::app()->user->setFlash('error', Yii::t('UsrModule.usr', 'Failed to send an email.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.')); } } // don't forget to associate the new profile with remote provider if (!$remoteLogin->associate($localProfile->getIdentity()->getId())) { Yii::app()->user->setFlash('error', Yii::t('UsrModule.usr', 'Failed to associate current user with {provider}.', array('{provider}' => $remoteLogin->provider))); $this->redirect(array('login', 'provider' => $remoteLogin->provider)); } if ($localProfile->getIdentity()->isActive()) { // don't use the $localProfile->login() method because there is no password set so we can't authenticate this identity if (Yii::app()->user->login($localProfile->getIdentity(), 0)) { $this->afterLogin(); } else { Yii::app()->user->setFlash('error', Yii::t('UsrModule.usr', 'Failed to log in.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.')); } } else { if (!Yii::app()->user->hasFlash('success')) { Yii::app()->user->setFlash('success', Yii::t('UsrModule.usr', 'Please wait for the account to be activated. A notification will be send to provided email address.')); } $this->redirect(array('login', 'provider' => $remoteLogin->provider)); } return $localProfile; }
public function actionProfile($update = false) { if (Yii::app()->user->isGuest) { $this->redirect(array('login')); } $model = new ProfileForm(); $model->setAttributes($model->getIdentity()->getAttributes()); $passwordForm = new PasswordForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') { $models = array($model); if (isset($_POST['PasswordForm']) && trim($_POST['PasswordForm']['newPassword']) !== '') { $models[] = $passwordForm; } echo CActiveForm::validate($models); Yii::app()->end(); } $flashes = array('success' => array(), 'error' => array()); if (isset($_POST['PasswordForm']) && trim($_POST['PasswordForm']['newPassword']) !== '') { $passwordForm->setAttributes($_POST['PasswordForm']); if ($passwordForm->validate()) { if ($passwordForm->resetPassword($model->getIdentity())) { $flashes['success'][] = Yii::t('UsrModule.usr', 'Changes have been saved successfully.'); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to change password.'); } } } if (isset($_POST['ProfileForm']) && empty($flashes['error'])) { $model->setAttributes($_POST['ProfileForm']); if ($model->validate()) { $oldEmail = $model->getIdentity()->getEmail(); if ($model->save()) { if ($this->module->requireVerifiedEmail && $oldEmail != $model->email) { if ($this->sendEmail($model, 'verify')) { $flashes['success'][] = Yii::t('UsrModule.usr', 'An email containing further instructions has been sent to provided email address.'); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to send an email.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.'); } } $flashes['success'][] = Yii::t('UsrModule.usr', 'Changes have been saved successfully.'); if (!empty($flashes['success'])) { Yii::app()->user->setFlash('success', implode('<br/>', $flashes['success'])); } if (!empty($flashes['error'])) { Yii::app()->user->setFlash('error', implode('<br/>', $flashes['error'])); } $this->redirect(array('profile')); } else { $flashes['error'][] = Yii::t('UsrModule.usr', 'Failed to update profile.') . ' ' . Yii::t('UsrModule.usr', 'Try again or contact the site administrator.'); } } } if (!empty($flashes['success'])) { Yii::app()->user->setFlash('success', implode('<br/>', $flashes['success'])); } if (!empty($flashes['error'])) { Yii::app()->user->setFlash('error', implode('<br/>', $flashes['error'])); } if ($update) { $this->render('updateProfile', array('model' => $model, 'passwordForm' => $passwordForm)); } else { $this->render('viewProfile', array('model' => $model)); } }