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 12, 2025
1 parent 18965ef commit d863cb9
Show file tree
Hide file tree
Showing 2 changed files with 29 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("Permission denied for the \"Users\" folder.\nPlease contact your site administrator.");
}
$this->restore_servers($removed);
}

Expand Down
38 changes: 21 additions & 17 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,27 +357,31 @@ function max_source_setting_callback($val) {
*/
if (!hm_exists('save_user_settings')) {
function save_user_settings($handler, $form, $logout) {
$user = $handler->session->get('username', false);
$path = $handler->config->get('user_settings_dir', false);
try {
$user = $handler->session->get('username', false);
$path = $handler->config->get('user_settings_dir', false);

if ($handler->session->auth($user, $form['password'])) {
$pass = $form['password'];
}
else {
Hm_Msgs::add('ERRIncorrect password, could not save settings to the server');
$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');
Hm_Msgs::add('Session destroyed on logout');
if ($handler->session->auth($user, $form['password'])) {
$pass = $form['password'];
}
else {
Hm_Msgs::add('Settings saved');
Hm_Msgs::add('ERRIncorrect password, could not save settings to the server');
$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');
Hm_Msgs::add('Session destroyed on logout');
}
else {
Hm_Msgs::add('Settings saved');
}
}
} catch (Exception $e) {
Hm_Msgs::add('ERRCould not save settings: ' . $e->getMessage());
}
}}

Expand Down

0 comments on commit d863cb9

Please sign in to comment.