Example #1
0
 public function actionRegister()
 {
     $model = new RegisterForm();
     if ($model->load(\Yii::$app->request->post())) {
         $data = new TAccount();
         $data->name = $model->account;
         $data->email = $model->email;
         $data->sc = md5($model->sc);
         $data->pwd = md5($model->password);
         $data->pw2 = md5($model->pwd2);
         if ($data->save()) {
             Yii::$app->session->setFlash('success', 'Tạo tài khoản thành công');
             return $this->redirect('dang-nhap.html');
         } else {
             $error = '';
             foreach ($data->errors as $val) {
                 foreach ($val as $value) {
                     $error .= $value . '<br/>';
                 }
             }
             Yii::$app->session->setFlash('error', $error);
         }
     }
     return $this->render('register', ['model' => $model]);
 }
Example #2
0
 public function actionChangepass()
 {
     $model = new ChangeForm();
     if ($model->load(Yii::$app->request->post())) {
         $user = TAccount::findOne(\Yii::$app->user->getId());
         $user->pwd = md5($model->password);
         $save = $user->save(false);
         if ($save) {
             \Yii::$app->session->setFlash('success', 'Thay đổi mật khẩu thành công');
         }
         return $this->refresh();
     }
     return $this->render('changepass', ['model' => $model]);
 }
Example #3
0
 public function actionUpdate($id = null)
 {
     $model = TAccount::findOne($id);
     $oldPwd = $model->pwd;
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->pwd != $oldPwd) {
             $model->pwd = md5($model->pwd);
         }
         $save = $model->save(false);
         if ($save) {
             return $this->redirect('index');
         }
     }
     return $this->render('update', ['model' => $model]);
 }