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;
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));
72 $message = $this->renderMail(
'/mail_templates/approve_email', $subject, array(
'activation_url' => $activation_url));
73 $notification =
new Notification($subject, $message, array(
new EmailRecipient($newEmail, Yii::app()->getModule(
'user')->activationEmail,
'',
true)));
74 Yii::app()->notificationManager->notifyAbout($notification);
75 Yii::app()->user->setFlash(
77 UserModule::t(
"Changes is saved. To activate your new email please confirm it in mail which was sent to {email}", array(
'{email}' => $newEmail))
80 Yii::app()->user->setFlash(
'profileMessage',
UserModule::t(
"Changes is saved."));
82 $user->update(array(
'status',
'username',
'activkey'));
84 Yii::app()->user->setState(
'User', array(
'attributes' => $user->attributes,
'errors' => $user->getErrors()));
85 Yii::app()->user->setState(
'Profile', array(
'attributes' => $profile->attributes,
'errors' => $profile->getErrors()));
89 if (isset($_REQUEST[
'return_url'])) {
90 $this->redirect($_REQUEST[
'return_url']);
92 $this->render(
'edit');
101 if (Yii::app()->user->id) {
104 if (isset($_POST[
'ajax']) && $_POST[
'ajax'] ===
'changepassword-form') {
109 if (isset($_POST[
'UserChangePassword'])) {
110 $model->attributes = $_POST[
'UserChangePassword'];
111 if ($model->validate()) {
112 $new_password =
User::model()->notsafe()->findbyPk(Yii::app()->user->id);
115 $new_password->save();
116 Yii::app()->user->setFlash(
'passwordChangeMessage',
UserModule::t(
"New password is saved."));
117 if (isset($_GET[
'return_url'])) {
118 $this->redirect($_GET[
'return_url']);
120 $this->redirect(array(
"profile"));
123 $this->render(
'changepassword', array(
'model' => $model));
127 public function actionApproveEmail($email, $key)
129 if (!
User::model()->exists(
"email=:email", array(
'email' => $email))) {
130 $user =
User::model()->findByAttributes(array(
'activkey' => $key));
132 $user->email = $email;
134 $this->render(
'email_approved', array(
'email' => $email));
139 $this->render(
'email_not_approved', array(
'email' => $email));
149 if ($this->_model === null) {
150 if (Yii::app()->user->id) {
153 if ($this->_model === null) {
154 $this->redirect(Yii::app()->controller->module->loginUrl);
157 return $this->_model;