diff --git a/lib/config.php b/lib/config.php index 55c52198f..11441d7b0 100644 --- a/lib/config.php +++ b/lib/config.php @@ -265,13 +265,20 @@ public function reload($data, $username = false) { public function save($username, $key) { $this->shuffle(); $destination = $this->get_path($username); + $folder = dirname($destination); + if (!is_dir($folder)) { + throw new Exception("\"Users\" folder doesn't exist, please contact your site administrator."); + } $removed = $this->filter_servers(); if (!$this->crypt) { $data = json_encode($this->config); } else { $data = Hm_Crypt::ciphertext(json_encode($this->config), $key); } - file_put_contents($destination, $data); + $result = file_put_contents($destination, $data); + if ($result === false) { + throw new Exception("Unable to write user config data - please check Cypht setup."); + } $this->restore_servers($removed); } diff --git a/lib/dispatch.php b/lib/dispatch.php index 43e4f1fca..95f7dd650 100644 --- a/lib/dispatch.php +++ b/lib/dispatch.php @@ -244,9 +244,13 @@ private function save_settings_on_login() { if (!$this->session->loaded) { return; } - if ($this->module_exec->user_config->save_on_login) { - $this->module_exec->user_config->save($this->request->post['username'], $this->request->post['password']); - } + try { + if ($this->module_exec->user_config->save_on_login) { + $this->module_exec->user_config->save($this->request->post['username'], $this->request->post['password']); + } + } catch (Exception $e) { + Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning'); + } } /** diff --git a/modules/account/modules.php b/modules/account/modules.php index 5965dcfed..da9940698 100644 --- a/modules/account/modules.php +++ b/modules/account/modules.php @@ -33,7 +33,11 @@ public function process() { if ($this->session->change_pass($user, $form['new_pass1'])) { Hm_Msgs::add("Password changed"); $user_config->load($user, $form['old_pass']); - $user_config->save($user, $form['new_pass1']); + try { + $user_config->save($user, $form['new_pass1']); + } catch (Exception $e) { + Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning'); + } return; } Hm_Msgs::add("An error Occurred", "danger"); diff --git a/modules/core/functions.php b/modules/core/functions.php index b51841db9..18b85079a 100644 --- a/modules/core/functions.php +++ b/modules/core/functions.php @@ -368,17 +368,22 @@ function save_user_settings($handler, $form, $logout) { $pass = false; } if ($user && $path && $pass) { - $handler->user_config->save($user, $pass); - $handler->session->set('changed_settings', array()); - if ($logout) { - $handler->session->destroy($handler->request); - Hm_Msgs::add('Saved user data on logout', 'info'); - Hm_Msgs::add('Session destroyed on logout', 'info'); - } - else { - Hm_Msgs::add('Settings saved'); + try { + $handler->user_config->save($user, $pass); + $handler->session->set('changed_settings', array()); + if ($logout) { + $handler->session->destroy($handler->request); + Hm_Msgs::add('Saved user data on logout', 'info'); + Hm_Msgs::add('Session destroyed on logout', 'info'); + } + else { + Hm_Msgs::add('Settings saved', 'info'); + } + } catch (Exception $e) { + Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning'); } } + }} /** diff --git a/modules/core/handler_modules.php b/modules/core/handler_modules.php index 2736509ab..51d7f036a 100644 --- a/modules/core/handler_modules.php +++ b/modules/core/handler_modules.php @@ -779,9 +779,13 @@ public function process() { $pass = false; } if ($user && $path && $pass) { - $this->user_config->save($user, $pass); - $this->session->destroy($this->request); - Hm_Msgs::add('Saved user data on logout, Session destroyed on logout', 'info'); + try { + $this->user_config->save($user, $pass); + $this->session->destroy($this->request); + Hm_Msgs::add('Saved user data on logout, Session destroyed on logout', 'info'); + } catch (Exception $e) { + Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning'); + } } } else { diff --git a/modules/recover_settings/modules.php b/modules/recover_settings/modules.php index 61594e90b..65d09881a 100644 --- a/modules/recover_settings/modules.php +++ b/modules/recover_settings/modules.php @@ -32,7 +32,11 @@ public function process() { foreach ($settings as $name => $val) { $this->user_config->set($name, $val); } - $this->user_config->save($user, $form['new_password_recover']); + try { + $this->user_config->save($user, $form['new_password_recover']); + } catch (Exception $e) { + Hm_Msgs::add('Could not save settings: ' . $e->getMessage(), 'warning'); + } Hm_Msgs::add('Settings recovered'); $this->session->set('load_recover_options', false); $this->session->set('old_settings_str', '');