diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 614f3e8..62d0e6e 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -2836,6 +2836,43 @@ "user": "Flashwave" } + ], + + "20150919": [ + + "eminence", + { + "type": "REM", + "change": "Removed Main::jsonPretty in favour of the built in PHP version.", + "user": "Flashwave" + } + + ], + + "20150923": [ + + "eminence", + { + "type": "ADD", + "change": "Added a JavaScript error reporter.", + "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Redirect a new user to /p/welcome on first login.", + "user": "Flashwave" + }, + { + "type": "UPD", + "change": "Changed sakura_sessions to a MEMORY table.", + "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Implement username changing.", + "user": "Flashwave" + } + ] } diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 97a3717..5b0eae7 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -708,81 +708,6 @@ class Main } - // Indent JSON - public static function jsonPretty($json) - { - - // Defines - $tab = ' '; - $out = ''; - $lvl = 0; - $str = false; - $obj = json_decode($json); - - // Validate the object - if ($obj === false) { - return false; - } - - // Re-encode the json and get the length - $json = json_encode($obj); - $len = strlen($json); - - // Go over the entries - for ($c = 0; $c < $len; $c++) { - // Get the current character - $char = $json[$c]; - - switch ($char) { - case '[': - case '{': - if ($str) { - $out .= $char; - } else { - $out .= $char . "\r\n" . str_repeat($tab, $lvl + 1); - $lvl++; - } - break; - - case ']': - case '}': - if ($str) { - $out .= $char; - } else { - $lvl--; - $out .= "\r\n" . str_repeat($tab, $lvl) . $char; - } - break; - - case ',': - if ($str) { - $out .= $char; - } else { - $out .= ",\r\n" . str_repeat($tab, $lvl); - } - break; - - case ':': - if ($str) { - $out .= $char; - } else { - $out .= ": "; - } - break; - - default: - $out .= $char; - break; - - } - - } - - // Return the indented JSON - return $out; - - } - // Time elapsed public static function timeElapsed($timestamp, $append = ' ago', $none = 'Just now') { diff --git a/_sakura/components/User.php b/_sakura/components/User.php index 23405c0..d5fe45f 100644 --- a/_sakura/components/User.php +++ b/_sakura/components/User.php @@ -336,4 +336,82 @@ class User return $warnings; } + + // Get username change history + public function getUsernameHistory() + { + + // Do the database query + $changes = Database::fetch('username_history', true, [ + 'user_id' => [$this->data['id'], '='], + ], ['change_id', true]); + + // Return all the warnings + return $changes; + + } + + // Set a new username + public function setUsername($username) + { + + // Create a cleaned version + $username_clean = Main::cleanString($username, true); + + // Check if the username is too short + if (strlen($username_clean) < Configuration::getConfig('username_min_length')) { + return [0, 'TOO_SHORT']; + } + + // Check if the username is too long + if (strlen($username_clean) > Configuration::getConfig('username_max_length')) { + return [0, 'TOO_LONG']; + } + + // Check if this username hasn't been used in the last amount of days set in the config + $getOld = Database::fetch('username_history', false, [ + 'username_old_clean' => [$username_clean, '='], + 'change_time' => [(Configuration::getConfig('old_username_reserve') * 24 * 60 * 60), '>'], + ], ['change_id', true]); + + // Check if anything was returned + if ($getOld) { + return [0, 'TOO_RECENT', $getOld['change_time']]; + } + + // Check if the username is already in use + $getInUse = Database::fetch('users', false, [ + 'username_clean' => [$username_clean, '='], + ]); + + // Check if anything was returned + if ($getInUse) { + return [0, 'IN_USE', $getInUse['id']]; + } + + // Insert into username_history table + Database::insert('username_history', [ + 'change_time' => time(), + 'user_id' => $this->data['id'], + 'username_new' => $username, + 'username_new_clean' => $username_clean, + 'username_old' => $this->data['username'], + 'username_old_clean' => $this->data['username_clean'], + ]); + + // Update userrow + Database::update('users', [ + [ + 'username' => $username, + 'username_clean' => $username_clean, + ], + [ + 'id' => [$this->data['id'], '='], + ], + ]); + + // Return success + return [1, 'SUCCESS', $username]; + + } } diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index 3329524..563e214 100644 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -196,7 +196,7 @@ class Users } // Successful login! (also has a thing for the legacy password system) - return [1, 'LOGIN_SUCESS']; + return [1, 'LOGIN_SUCCESS', $user['id']]; } @@ -329,7 +329,6 @@ class Users 'last_ip' => Main::getRemoteIP(), 'regdate' => time(), 'lastdate' => 0, - 'lastunamechange' => time(), 'country' => Main::getCountryCode(), 'userData' => '[]', ]); diff --git a/_sakura/sakura.php b/_sakura/sakura.php index c6443a7..bb1562f 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150918'); +define('SAKURA_VERSION', '20150923'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_COLOUR', '#6C3082'); define('SAKURA_STABLE', false); diff --git a/_sakura/templates/mio/elements/newsPost.tpl b/_sakura/templates/mio/elements/newsPost.tpl index 84b4d8a..60c7184 100644 --- a/_sakura/templates/mio/elements/newsPost.tpl +++ b/_sakura/templates/mio/elements/newsPost.tpl @@ -1,5 +1,5 @@ -{% if newsPosts|length > 1 %}