Skip to content

Commit

Permalink
fix(other): save settings displaying wrong message
Browse files Browse the repository at this point in the history
  • Loading branch information
IrAlfred committed Feb 13, 2025
1 parent 70559b1 commit 9eae5d9
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
9 changes: 8 additions & 1 deletion lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 7 additions & 3 deletions lib/dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion modules/account/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
23 changes: 14 additions & 9 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

}}

/**
Expand Down
10 changes: 7 additions & 3 deletions modules/core/handler_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion modules/recover_settings/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand Down

0 comments on commit 9eae5d9

Please sign in to comment.