HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
ProfileController.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  public $defaultAction = 'profile';
6  public $layout = '//layouts/column2';
7 
11  private $_model;
12 
19  public function accessRules()
20  {
21  return array(
22  array('allow', // allow all users to perform 'index' and 'view' actions
23  'actions' => array(),
24  'users' => array('*'),
25  ),
26  array('deny', // deny all users
27  'users' => array('*'),
28  ),
29  );
30  }
31 
32  protected function beforeAction($event)
33  {
34  if (UserModule::isUserTemp()) {
35  $this->redirect('/');
36  }
37 
38  return true;
39  }
40 
44  public function actionProfile()
45  {
46  $model = $this->loadUser();
47  $this->render('profile', array(
48  'model' => $model,
49  'profile' => $model->profile,
50  ));
51  }
52 
57  public function actionEdit()
58  {
59  $model = $this->loadUser();
60  $profile = $model->profile;
61 
62  // ajax validator
63  if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') {
64  echo UActiveForm::validate(array($model, $profile));
65  Yii::app()->end();
66  }
67 
68  if (isset($_POST['User'])) {
69  $model->attributes = $_POST['User'];
70  $profile->attributes = $_POST['Profile'];
71 
72  if ($model->validate() && $profile->validate()) {
73  $model->save();
74  $profile->save();
75  Yii::app()->user->updateSession();
76  Yii::app()->user->setFlash('profileMessage', UserModule::t("Changes is saved."));
77  $this->redirect(array('/user/profile'));
78  } else {
79  $profile->validate();
80  }
81  }
82 
83  $this->render('edit', array(
84  'model' => $model,
85  'profile' => $profile,
86  ));
87  }
88 
92  public function actionChangepassword()
93  {
94  $model = new UserChangePassword();
95  if (Yii::app()->user->id) {
96 
97  // ajax validator
98  if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
99  echo UActiveForm::validate($model);
100  Yii::app()->end();
101  }
102 
103  if (isset($_POST['UserChangePassword'])) {
104  $model->attributes = $_POST['UserChangePassword'];
105  if ($model->validate()) {
106  $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id);
107  $new_password->password = UserModule::encrypting($model->password);
108  $new_password->activkey = UserModule::encrypting(microtime().$model->password);
109  $new_password->save();
110  Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved."));
111  $this->redirect(array("profile"));
112  }
113  }
114  $this->render('changepassword', array('model' => $model));
115  }
116  }
117 
124  public function loadUser()
125  {
126  if ($this->_model === null) {
127  if (Yii::app()->user->id) {
128  $this->_model = Yii::app()->controller->module->user();
129  }
130  if ($this->_model === null) {
131  $this->redirect(Yii::app()->controller->module->loginUrl);
132  }
133  }
134 
135  return $this->_model;
136  }
137 }