Skip to content

Commit 78e7ecc

Browse files
committed
Merge pull request #2131 from MPOS/timezone-support
[ADDED] Timezone support
2 parents 8f36c18 + 0a502b2 commit 78e7ecc

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed

public/include/bootstrap.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,19 @@
2929
}
3030
@setcookie(session_name(), session_id(), time()+$config['cookie']['duration'], $config['cookie']['path'], $config['cookie']['domain'], $config['cookie']['secure'], $config['cookie']['httponly']);
3131

32+
// Set the timezone if a user has it set, default UTC
33+
if (isset($_SESSION['USERDATA']['timezone'])) {
34+
$aTimezones = DateTimeZone::listIdentifiers();
35+
date_default_timezone_set($aTimezones[$_SESSION['USERDATA']['timezone']]);
36+
} else {
37+
date_default_timezone_set('UTC');
38+
}
39+
3240
// Our default template to load, pages can overwrite this later
3341
$master_template = 'master.tpl';
3442

3543
// Load Classes, they name defines the $ variable used
3644
// We include all needed files here, even though our templates could load them themself
3745
require_once(INCLUDE_DIR . '/autoloader.inc.php');
3846

39-
?>
47+
?>

public/include/classes/user.class.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public function updatePassword($userID, $current, $new1, $new2, $strToken) {
489489
* @param strToken string Token for confirmation
490490
* @return bool
491491
**/
492-
public function updateAccount($userID, $address, $threshold, $donate, $email, $is_anonymous, $strToken) {
492+
public function updateAccount($userID, $address, $threshold, $donate, $email, $timezone, $is_anonymous, $strToken) {
493493
$this->debug->append("STA " . __METHOD__, 4);
494494
$bUser = false;
495495
$donate = round($donate, 2);
@@ -559,8 +559,8 @@ public function updateAccount($userID, $address, $threshold, $donate, $email, $i
559559
}
560560

561561
// We passed all validation checks so update the account
562-
$stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, is_anonymous = ? WHERE id = ?");
563-
if ($this->checkStmt($stmt) && $stmt->bind_param('sddsii', $address, $threshold, $donate, $email, $is_anonymous, $userID) && $stmt->execute()) {
562+
$stmt = $this->mysqli->prepare("UPDATE $this->table SET coin_address = ?, ap_threshold = ?, donate_percent = ?, email = ?, timezone = ?, is_anonymous = ? WHERE id = ?");
563+
if ($this->checkStmt($stmt) && $stmt->bind_param('sddssii', $address, $threshold, $donate, $email, $timezone, $is_anonymous, $userID) && $stmt->execute()) {
564564
$this->log->log("info", $this->getUserName($userID)." updated their account details");
565565
return true;
566566
}
@@ -596,14 +596,14 @@ public function checkApiKey($key) {
596596
private function checkUserPassword($username, $password) {
597597
$this->debug->append("STA " . __METHOD__, 4);
598598
$user = array();
599-
$stmt = $this->mysqli->prepare("SELECT username, pass, id, is_admin FROM $this->table WHERE LOWER(username) = LOWER(?) LIMIT 1");
600-
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $username) && $stmt->execute() && $stmt->bind_result($row_username, $row_password, $row_id, $row_admin)) {
599+
$stmt = $this->mysqli->prepare("SELECT username, pass, id, timezone, is_admin FROM $this->table WHERE LOWER(username) = LOWER(?) LIMIT 1");
600+
if ($this->checkStmt($stmt) && $stmt->bind_param('s', $username) && $stmt->execute() && $stmt->bind_result($row_username, $row_password, $row_id, $row_timezone, $row_admin)) {
601601
$stmt->fetch();
602602
$stmt->close();
603603
$aPassword = explode('$', $row_password);
604604
count($aPassword) == 1 ? $password_hash = $this->getHash($password, 0) : $password_hash = $this->getHash($password, $aPassword[1], $aPassword[2]);
605605
// Store the basic login information
606-
$this->user = array('username' => $row_username, 'id' => $row_id, 'is_admin' => $row_admin);
606+
$this->user = array('username' => $row_username, 'id' => $row_id, 'timezone' => $row_timezone, 'is_admin' => $row_admin);
607607
return $password_hash === $row_password && strtolower($username) === strtolower($row_username);
608608
}
609609
return $this->sqlError();
@@ -703,7 +703,7 @@ public function getUserData($userID) {
703703
$this->debug->append("Fetching user information for user id: $userID");
704704
$stmt = $this->mysqli->prepare("
705705
SELECT
706-
id, username, pin, api_key, is_admin, is_anonymous, email, no_fees,
706+
id, username, pin, api_key, is_admin, is_anonymous, email, timezone, no_fees,
707707
IFNULL(donate_percent, '0') as donate_percent, coin_address, ap_threshold
708708
FROM $this->table
709709
WHERE id = ? LIMIT 0,1");

public/include/pages/account/edit.inc.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@
132132
if ($config['twofactor']['enabled'] && $config['twofactor']['options']['details'] && !$ea_editable) {
133133
$_SESSION['POPUP'][] = array('CONTENT' => 'You have not yet unlocked account updates.', 'TYPE' => 'alert alert-danger');
134134
} else if (!$config['csrf']['enabled'] || $config['csrf']['enabled'] && $csrftoken->valid) {
135-
if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'], $_POST['is_anonymous'], $oldtoken_ea)) {
136-
$_SESSION['POPUP'][] = array('CONTENT' => 'Account details updated', 'TYPE' => 'alert alert-success');
135+
if ($user->updateAccount($_SESSION['USERDATA']['id'], $_POST['paymentAddress'], $_POST['payoutThreshold'], $_POST['donatePercent'], $_POST['email'], $_POST['timezone'], $_POST['is_anonymous'], $oldtoken_ea)) {
136+
$_SESSION['USERDATA']['timezone'] = $_POST['timezone'];
137+
$_SESSION['POPUP'][] = array('CONTENT' => 'Account details updated', 'TYPE' => 'alert alert-success');
137138
} else {
138-
$_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update your account: ' . $user->getError(), 'TYPE' => 'alert alert-danger');
139+
$_SESSION['POPUP'][] = array('CONTENT' => 'Failed to update your account: ' . $user->getError(), 'TYPE' => 'alert alert-danger');
139140
}
140141
} else {
141142
$_SESSION['POPUP'][] = array('CONTENT' => $csrftoken->getErrorWithDescriptionHTML(), 'TYPE' => 'alert alert-warning');
@@ -197,6 +198,10 @@
197198
$smarty->assign("DETAILSSENT", $ea_sent);
198199
}
199200

201+
// Grab our timezones
202+
$smarty->assign('TIMEZONES', DateTimeZone::listIdentifiers());
203+
204+
// Fetch donation threshold
200205
$smarty->assign("DONATE_THRESHOLD", $config['donate_threshold']);
201206

202207
// Tempalte specifics

public/include/version.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

44
define('MPOS_VERSION', '0.0.4');
5-
define('DB_VERSION', '0.0.8');
5+
define('DB_VERSION', '0.0.9');
66
define('CONFIG_VERSION', '0.0.8');
77
define('HASH_VERSION', 1);
88

public/templates/bootstrap/account/edit/detail.tpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
<label>E-Mail</label>
3131
{nocache}<input class="form-control" type="text" name="email" value="{$GLOBAL.userdata.email|escape}" size="20" {if $GLOBAL.twofactor.enabled && $GLOBAL.twofactor.options.details && !$DETAILSUNLOCKED}id="disabledInput" disabled{/if}/>{/nocache}
3232
</div>
33+
<div class="form-group">
34+
<label>Timezone</label>
35+
{nocache}
36+
<select class="form-control" name="timezone">
37+
{html_options options=$TIMEZONES selected=$GLOBAL.userdata.timezone}
38+
</select>
39+
{/nocache}
40+
</div>
3341
<div class="form-group">
3442
<label>Payment Address</label>
3543
{nocache}<input class="form-control" type="text" name="paymentAddress" value="{$smarty.request.paymentAddress|default:$GLOBAL.userdata.coin_address|escape}" size="40" {if $GLOBAL.twofactor.enabled && $GLOBAL.twofactor.options.details && !$DETAILSUNLOCKED}id="disabledInput" disabled{/if}/>{/nocache}

sql/000_base_structure.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CREATE TABLE IF NOT EXISTS `accounts` (
1515
`username` varchar(40) NOT NULL,
1616
`pass` varchar(255) NOT NULL,
1717
`email` varchar(255) DEFAULT NULL COMMENT 'Assocaited email: used for validating users, and re-setting passwords',
18+
`timezone` varchar(35) NOT NULL DEFAULT '415',
1819
`notify_email` VARCHAR( 255 ) NULL DEFAULT NULL,
1920
`loggedIp` varchar(255) DEFAULT NULL,
2021
`is_locked` tinyint(1) NOT NULL DEFAULT '0',
@@ -133,7 +134,7 @@ CREATE TABLE IF NOT EXISTS `settings` (
133134
UNIQUE KEY `setting` (`name`)
134135
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
135136

136-
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.8');
137+
INSERT INTO `settings` (`name`, `value`) VALUES ('DB_VERSION', '0.0.9');
137138

138139
CREATE TABLE IF NOT EXISTS `shares` (
139140
`id` bigint(30) NOT NULL AUTO_INCREMENT,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
function run_009() {
3+
// Ugly but haven't found a better way
4+
global $setting, $config, $user, $mysqli;
5+
6+
// Version information
7+
$db_version_old = '0.0.8'; // What version do we expect
8+
$db_version_new = '0.0.9'; // What is the new version we wish to upgrade to
9+
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
10+
11+
// Upgrade specific variables
12+
$aSql[] = "ALTER TABLE " . $user->getTableName() . " ADD `timezone` VARCHAR(35) NOT NULL DEFAULT '415' AFTER `email`";
13+
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.9' WHERE name = 'DB_VERSION'";
14+
15+
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {
16+
// Run the upgrade
17+
echo '- Starting database migration to version ' . $db_version_new . PHP_EOL;
18+
foreach ($aSql as $sql) {
19+
echo '- Preparing: ' . $sql . PHP_EOL;
20+
$stmt = $mysqli->prepare($sql);
21+
if ($stmt && $stmt->execute()) {
22+
echo '- success' . PHP_EOL;
23+
} else {
24+
echo '- failed: ' . $mysqli->error . PHP_EOL;
25+
exit(1);
26+
}
27+
}
28+
}
29+
}
30+
?>

0 commit comments

Comments
 (0)