5 public $defaultAction =
'profile';
18 $this->render(
'profile', array(
20 'profile' => $model->profile,
33 throw new CHttpException(400);
35 $profile = $user->profile;
38 if (isset($_POST[
'ajax']) && $_POST[
'ajax'] ===
'profile-form') {
43 if (isset($_POST[
'User'], $_POST[
'Profile'])) {
45 $oldEmail = $user->email;
46 $user->attributes = $_POST[
'User'];
47 $profile->attributes = $_POST[
'Profile'];
48 $uv = $user->validate();
49 $pv = $profile->validate();
52 if(isset($_POST[
'Profile'][
'firstname'])){
53 Yii::app()->user->firstname = $_POST[
'Profile'][
'firstname'];
55 if(isset($_POST[
'Profile'][
'lastname'])){
56 Yii::app()->user->lastname = $_POST[
'Profile'][
'lastname'];
58 if(isset($_POST[
'User'][
'email'])){
59 Yii::app()->user->email = $_POST[
'User'][
'email'];
61 if ($oldEmail != $user->email) {
62 $newEmail = $user->email;
63 $user->email = $oldEmail;
65 if (Yii::app()->getModule(
'user')->profileEditUrl[Yii::app()->language] !==
false) {
66 $activation_url = Yii::app()->createAbsoluteUrl(Yii::app()->getModule(
'user')->profileEditUrl[Yii::app()->language]).
"?approveEmail=1&email={$newEmail}&key={$user->activkey}";
68 $activation_url = Yii::app()->createAbsoluteUrl(
'/user/profile/approveEmail', array(
'email' => $newEmail,
'key' => $user->activkey));
71 $message = $this->renderMail(
'/mail_templates/approve_email', $subject, array(
'activation_url' => $activation_url));
72 $notification =
new Notification($subject, $message, array(
new EmailRecipient($newEmail, Yii::app()->getModule(
'user')->activationEmail,
'',
true)));
73 Yii::app()->notificationManager->notifyAbout($notification);
74 Yii::app()->user->setFlash(
76 UserModule::t(
"Changes is saved. To activate your new email please confirm it in mail which was sent to {email}", array(
'{email}' => $newEmail))
79 Yii::app()->user->setFlash(
'profileMessage',
UserModule::t(
"Changes is saved."));
81 $user->update(array(
'status',
'username',
'activkey'));
83 $user->password = null;
84 $user->verifyPassword = null;
85 Yii::app()->user->setState(
'User', array(
'attributes' => $user->attributes,
'errors' => $user->getErrors()));
86 Yii::app()->user->setState(
'Profile', array(
'attributes' => $profile->attributes,
'errors' => $profile->getErrors()));
90 if (isset($_REQUEST[
'return_url'])) {
91 $this->redirect($_REQUEST[
'return_url']);
93 $this->render(
'edit');
102 if (Yii::app()->user->id) {
105 if (isset($_POST[
'ajax']) && $_POST[
'ajax'] ===
'changepassword-form') {
110 if (isset($_POST[
'UserChangePassword'])) {
111 $model->attributes = $_POST[
'UserChangePassword'];
112 if ($model->validate()) {
113 $new_password =
User::model()->notsafe()->findbyPk(Yii::app()->user->id);
116 $new_password->save();
117 Yii::app()->user->setFlash(
'passwordChangeMessage',
UserModule::t(
"New password is saved."));
118 if (isset($_GET[
'return_url'])) {
119 $this->redirect($_GET[
'return_url']);
121 $this->redirect(array(
"profile"));
124 $this->render(
'changepassword', array(
'model' => $model));
128 public function actionApproveEmail($email, $key)
130 if (!
User::model()->exists(
"email=:email", array(
'email' => $email))) {
131 $user =
User::model()->findByAttributes(array(
'activkey' => $key));
133 $user->email = $email;
135 $this->render(
'email_approved', array(
'email' => $email));
140 $this->render(
'email_not_approved', array(
'email' => $email));
150 if ($this->_model === null) {
151 if (Yii::app()->user->id) {
154 if ($this->_model === null) {
155 $this->redirect(Yii::app()->controller->module->loginUrl);
158 return $this->_model;