diff --git a/public/include/bootstrap.php b/public/include/bootstrap.php index fe6a9d02..241fccca 100644 --- a/public/include/bootstrap.php +++ b/public/include/bootstrap.php @@ -29,6 +29,14 @@ if (!$session_start) { } @setcookie(session_name(), session_id(), time()+$config['cookie']['duration'], $config['cookie']['path'], $config['cookie']['domain'], $config['cookie']['secure'], $config['cookie']['httponly']); +// Set the timezone if a user has it set, default UTC +if (isset($_SESSION['USERDATA']['timezone'])) { + $aTimezones = DateTimeZone::listIdentifiers(); + date_default_timezone_set($aTimezones[$_SESSION['USERDATA']['timezone']]); +} else { + date_default_timezone_set('UTC'); +} + // Our default template to load, pages can overwrite this later $master_template = 'master.tpl'; @@ -36,4 +44,4 @@ $master_template = 'master.tpl'; // We include all needed files here, even though our templates could load them themself require_once(INCLUDE_DIR . '/autoloader.inc.php'); -?> \ No newline at end of file +?> diff --git a/public/include/classes/user.class.php b/public/include/classes/user.class.php index 5748beda..11c2b20f 100644 --- a/public/include/classes/user.class.php +++ b/public/include/classes/user.class.php @@ -489,7 +489,7 @@ class User extends Base { * @param strToken string Token for confirmation * @return bool **/ - public function updateAccount($userID, $address, $threshold, $donate, $email, $is_anonymous, $strToken) { + public function updateAccount($userID, $address, $threshold, $donate, $email, $timezone, $is_anonymous, $strToken) { $this->debug->append("STA " . __METHOD__, 4); $bUser = false; $donate = round($donate, 2); @@ -559,8 +559,8 @@ class User extends Base { } // We passed all validation checks so update the account - $stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ?"); - if ($this->checkStmt($stmt) && $stmt->bind_param('sddsii', $address, $threshold, $donate, $email, $is_anonymous, $userID) && $stmt->execute()) { + $stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, timezone = ?, is_anonymous = ? WHERE id = ?"); + if ($this->checkStmt($stmt) && $stmt->bind_param('sddssii', $address, $threshold, $donate, $email, $timezone, $is_anonymous, $userID) && $stmt->execute()) { $this->log->log("info", $this->getUserName($userID)." updated their account details"); return true; } @@ -596,14 +596,14 @@ class User extends Base { private function checkUserPassword($username, $password) { $this->debug->append("STA " . __METHOD__, 4); $user = array(); - $stmt = $this->mysqli->prepare("SELECT username, pass, id, is_admin FROM $this->table WHERE LOWER(username) = LOWER(?) LIMIT 1"); - if ($this->checkStmt($stmt) && $stmt->bind_param('s', $username) && $stmt->execute() && $stmt->bind_result($row_username, $row_password, $row_id, $row_admin)) { + $stmt = $this->mysqli->prepare("SELECT username, pass, id, timezone, is_admin FROM $this->table WHERE LOWER(username) = LOWER(?) LIMIT 1"); + if ($this->checkStmt($stmt) && $stmt->bind_param('s', $username) && $stmt->execute() && $stmt->bind_result($row_username, $row_password, $row_id, $row_timezone, $row_admin)) { $stmt->fetch(); $stmt->close(); $aPassword = explode('$', $row_password); count($aPassword) == 1 ? $password_hash = $this->getHash($password, 0) : $password_hash = $this->getHash($password, $aPassword[1], $aPassword[2]); // Store the basic login information - $this->user = array('username' => $row_username, 'id' => $row_id, 'is_admin' => $row_admin); + $this->user = array('username' => $row_username, 'id' => $row_id, 'timezone' => $row_timezone, 'is_admin' => $row_admin); return $password_hash === $row_password && strtolower($username) === strtolower($row_username); } return $this->sqlError(); @@ -703,7 +703,7 @@ class User extends Base { $this->debug->append("Fetching user information for user id: $userID"); $stmt = $this->mysqli->prepare(" SELECT - id, username, pin, api_key, is_admin, is_anonymous, email, no_fees, + id, username, pin, api_key, is_admin, is_anonymous, email, timezone, no_fees, IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold FROM $this->table WHERE id = ? LIMIT 0,1"); diff --git a/public/include/pages/account/edit.inc.php b/public/include/pages/account/edit.inc.php index 95aff459..78782ad4 100644 --- a/public/include/pages/account/edit.inc.php +++ b/public/include/pages/account/edit.inc.php @@ -132,10 +132,11 @@ if ($user->isAuthenticated()) { if ($config['twofactor']['enabled'] && $config['twofactor']['options']['details'] && !$ea_editable) { $_SESSION['POPUP'][] = array('CONTENT' => 'You have not yet unlocked account updates.', 'TYPE' => 'alert alert-danger'); } else if (!$config['csrf']['enabled'] || $config['csrf']['enabled'] && $csrftoken->valid) { - if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'], $_POST['is_anonymous'], $oldtoken_ea)) { - $_SESSION['POPUP'][] = array('CONTENT' => 'Account details updated', 'TYPE' => 'alert alert-success'); + if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'], $_POST['timezone'], $_POST['is_anonymous'], $oldtoken_ea)) { + $_SESSION['USERDATA']['timezone'] = $_POST['timezone']; + $_SESSION['POPUP'][] = array('CONTENT' => 'Account details updated', 'TYPE' => 'alert alert-success'); } else { - $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update your account: ' . $user->getError(), 'TYPE' => 'alert alert-danger'); + $_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update your account: ' . $user->getError(), 'TYPE' => 'alert alert-danger'); } } else { $_SESSION['POPUP'][] = array('CONTENT' => $csrftoken->getErrorWithDescriptionHTML(), 'TYPE' => 'alert alert-warning'); @@ -197,6 +198,10 @@ if ($config['twofactor']['enabled'] && $user->isAuthenticated()) { $smarty->assign("DETAILSSENT", $ea_sent); } +// Grab our timezones +$smarty->assign('TIMEZONES', DateTimeZone::listIdentifiers()); + +// Fetch donation threshold $smarty->assign("DONATE_THRESHOLD", $config['donate_threshold']); // Tempalte specifics diff --git a/public/include/version.inc.php b/public/include/version.inc.php index 2e801e8a..a94bf193 100644 --- a/public/include/version.inc.php +++ b/public/include/version.inc.php @@ -2,7 +2,7 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; define('MPOS_VERSION', '0.0.4'); -define('DB_VERSION', '0.0.8'); +define('DB_VERSION', '0.0.9'); define('CONFIG_VERSION', '0.0.8'); define('HASH_VERSION', 1); diff --git a/public/templates/bootstrap/account/edit/detail.tpl b/public/templates/bootstrap/account/edit/detail.tpl index a98251c5..9b40dc67 100644 --- a/public/templates/bootstrap/account/edit/detail.tpl +++ b/public/templates/bootstrap/account/edit/detail.tpl @@ -30,6 +30,14 @@ {nocache}{/nocache} +