From b1391f3d4dc658ed6d33c95f8f19dc960ebda746 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 10 Aug 2015 21:09:47 +0200 Subject: [PATCH] bunch of fuck --- _sakura/changelog.json | 15 +++ _sakura/components/Users.php | 88 -------------- .../templates/yuuno/elements/settingsNav.tpl | 2 +- _sakura/templates/yuuno/main/profile.tpl | 6 +- .../templates/yuuno/settings/background.tpl | 20 +++- _sakura/templates/yuuno/settings/userpage.tpl | 29 ++++- main/imageserve.php | 2 +- main/profile.php | 2 +- main/settings.php | 108 +++++++++++++----- 9 files changed, 143 insertions(+), 129 deletions(-) diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 27c2049..54d1aee 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -1941,6 +1941,21 @@ "type": "FIX", "change": "Fixed user actions showing up for deleted users.", "user": "Flashwave" + }, + { + "type": "ADD", + "change": "Added background uploading.", + "user": "Flashwave" + }, + { + "type": "REM", + "change": "Removed the function for changing password using a legacy pass.", + "user": "Flashwave" + }, + { + "type": "REM", + "change": "Removed old userpages code.", + "user": "Flashwave" } ] diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index fda8fed..23ea466 100644 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -340,61 +340,6 @@ class Users { } - // [Flashwave 2015-04-25] Prepare for 5 million password changing functions - - // Change legacy passwords after logging in - public static function changeLegacy($oldpass, $newpass, $verpass) { - - // Check if user is logged in because I just know someone is going to meme around it - if(!self::checkLogin()) - return [0, 'USER_NOT_LOGIN']; - - // Get user data - $user = Users::getUser(Session::$userId); - - // Check if the user has the required privs to log in - if(Permissions::check('SITE', 'DEACTIVATED', $user['id'], 1)) - return [0, 'NOT_ALLOWED']; - - // Check if the account is disabled - if('nologin' == $user['password_algo']) - return [0, 'NO_LOGIN']; - - // Check if old pass is correct - if(Main::legacyPasswordHash($oldpass) != $user['password_hash']) - return [0, 'INCORRECT_PASSWORD']; - - // Check password entropy - if(Main::pwdEntropy($newpass) < Configuration::getConfig('min_entropy')) - return [0, 'PASS_TOO_SHIT']; - - // Passwords do not match - if($newpass != $verpass) - return [0, 'PASS_NOT_MATCH']; - - // Hash the password - $password = Hashing::create_hash($newpass); - $time = time(); - - // Update the user - Database::update('users', [ - [ - 'password_hash' => $password[3], - 'password_salt' => $password[2], - 'password_algo' => $password[0], - 'password_iter' => $password[1], - 'password_chan' => $time - ], - [ - 'id' => [Session::$userId, '='] - ] - ]); - - // Return success - return [1, 'SUCCESS']; - - } - // Reset password with key public static function resetPassword($verk, $uid, $newpass, $verpass) { @@ -917,39 +862,6 @@ class Users { } - // Getting the profile page of a user - public static function getProfilePage($id, $inputIsData = false) { - - // Check if the input is the data - if($inputIsData) { - - // Reassign data - $data = $id; - - } else { - - // Get user data - $user = self::getUser($id); - - // Decode the userData json - $data = json_decode($user['userData'], true); - - } - - // Check if the profilePage key exists - if(!array_key_exists('profilePage', $data)) - return false; - - // TODO: implement BBcodes - - // Parse the markdown - $profilePage = Main::mdParse(base64_decode($data['profilePage'][0])); - - // Return the parsed profile page - return $profilePage; - - } - // Check if a user is online public static function checkUserOnline($id) { diff --git a/_sakura/templates/yuuno/elements/settingsNav.tpl b/_sakura/templates/yuuno/elements/settingsNav.tpl index e011d0f..3c616ec 100644 --- a/_sakura/templates/yuuno/elements/settingsNav.tpl +++ b/_sakura/templates/yuuno/elements/settingsNav.tpl @@ -18,7 +18,7 @@
Aesthetics
Avatar Background - Profile Page + Userpage
Account
E-mail Address Username diff --git a/_sakura/templates/yuuno/main/profile.tpl b/_sakura/templates/yuuno/main/profile.tpl index 4da1ffe..99b0448 100644 --- a/_sakura/templates/yuuno/main/profile.tpl +++ b/_sakura/templates/yuuno/main/profile.tpl @@ -13,7 +13,7 @@ {% else %}
-
+
{{ profile.user.username }}'s Avatar
{% if profile.user.rank_main > 1 and profile.ban_check|length < 1 %} @@ -87,8 +87,8 @@ {% endif %}
-
- {{ profile.profilePage|raw }} +
+ {{ profile.userPage|raw }}
diff --git a/_sakura/templates/yuuno/settings/background.tpl b/_sakura/templates/yuuno/settings/background.tpl index 5793039..b8ccf19 100644 --- a/_sakura/templates/yuuno/settings/background.tpl +++ b/_sakura/templates/yuuno/settings/background.tpl @@ -9,9 +9,25 @@
The background that is displayed on your profile.
-
Maximum image size is 2560x1440, minimum image size is 20x20, maximum file size is 10 MB.
+
Maximum image size is {{ background.max_width }}x{{ background.max_height }}, minimum image size is {{ background.min_width }}x{{ background.min_height }}, maximum file size is {{ background.max_size_view }}.
- +
+ + + + +
+
+ Your Background +
+
+ +
+
+ +
+
+
diff --git a/_sakura/templates/yuuno/settings/userpage.tpl b/_sakura/templates/yuuno/settings/userpage.tpl index 6e75b4d..a84d881 100644 --- a/_sakura/templates/yuuno/settings/userpage.tpl +++ b/_sakura/templates/yuuno/settings/userpage.tpl @@ -9,9 +9,34 @@
The custom text that is displayed on your profile.
-
Click here if you don't know how to markdown!
+
Click here if you don't know how to markdown!
- + {# + {% if preview %} +
+ {{ preview|raw }} +
+
+ {% endif %} +
+ + + +
+
+

Parse mode

+ + + +
+
+ + + +
+
+ #} +

Redoing this bc garbage.

diff --git a/main/imageserve.php b/main/imageserve.php index f148e63..37181ac 100644 --- a/main/imageserve.php +++ b/main/imageserve.php @@ -140,6 +140,6 @@ if(isset($_GET['m'])) { $serveImage = file_get_contents($serveImage); -header('Content-Type: ' .getimagesizefromstring($serveImage)['mime']); +header('Content-Type: '. getimagesizefromstring($serveImage)['mime']); print $serveImage; diff --git a/main/profile.php b/main/profile.php index f53d819..809f3cb 100644 --- a/main/profile.php +++ b/main/profile.php @@ -21,7 +21,7 @@ if(isset($_GET['u'])) { 'country' => Main::getCountryName($_PROFILE_USER_DATA['country']), 'is_premium' => Users::checkUserPremium($_PROFILE_USER_DATA['id'])[0], 'is_online' => Users::checkUserOnline($_PROFILE_USER_DATA['id']), - 'profilePage' => Users::getProfilePage($_PROFILE_USER_DATA['userData'], true), + 'userPage' => null, 'fields' => Users::getUserProfileFields($_PROFILE_USER_DATA['userData'], true), 'warnings' => Users::getWarnings($_PROFILE_USER_DATA['id']), 'friend' => Users::checkFriend($_PROFILE_USER_DATA['id']), diff --git a/main/settings.php b/main/settings.php index be4c442..5befd32 100644 --- a/main/settings.php +++ b/main/settings.php @@ -239,21 +239,40 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Switch to the correct mode switch($_POST['mode']) { - // Avatar + // Avatar & Background case 'avatar': + case 'background': + + // Assign $_POST['mode'] to a $mode variable because I ain't typin that more than once + $mode = $_POST['mode']; + + // Assign the correct userData key to a variable and correct title + switch($mode) { + + case 'background': + $userDataKey = 'profileBackground'; + $msgTitle = 'Background'; + break; + + case 'avatar': + default: + $userDataKey = 'userAvatar'; + $msgTitle = 'Avatar'; + + } // Set path variables $filepath = ROOT . Configuration::getConfig('user_uploads') .'/'; - $filename = $filepath .'avatar_'. Session::$userId; - $currfile = isset(Users::getUser(Session::$userId)['userData']['userAvatar']) && !empty($_AVA = Users::getUser(Session::$userId)['userData']['userAvatar']) ? $_AVA : null; + $filename = $filepath . $mode .'_'. Session::$userId; + $currfile = isset(Users::getUser(Session::$userId)['userData'][$userDataKey]) && !empty($_OLDFILE = Users::getUser(Session::$userId)['userData'][$userDataKey]) ? $_OLDFILE : null; // Check if $_FILES is set - if(!isset($_FILES['avatar']) && empty($_FILES['avatar'])) { + if(!isset($_FILES[$mode]) && empty($_FILES[$mode])) { // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'No file was uploaded.', 'success' => 0 @@ -265,10 +284,10 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Check if the upload went properly - if($_FILES['avatar']['error'] !== UPLOAD_ERR_OK) { + if($_FILES[$mode]['error'] !== UPLOAD_ERR_OK) { // Get the error in text - switch($_FILES['avatar']['error']) { + switch($_FILES[$mode]['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: @@ -295,7 +314,7 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => $msg, 'success' => 0 @@ -307,7 +326,7 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Get the meta data - $metadata = getimagesize($_FILES['avatar']['tmp_name']); + $metadata = getimagesize($_FILES[$mode]['tmp_name']); // Check if the image is actually an image if($metadata == false) { @@ -315,7 +334,7 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'Uploaded file is not an image.', 'success' => 0 @@ -332,7 +351,7 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'This filetype is not allowed.', 'success' => 0 @@ -344,12 +363,12 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Check if the image is too large - if(($metadata[0] > Configuration::getConfig('avatar_max_width') || $metadata[1] > Configuration::getConfig('avatar_max_height'))) { + if(($metadata[0] > Configuration::getConfig($mode .'_max_width') || $metadata[1] > Configuration::getConfig($mode .'_max_height'))) { // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'The resolution of this picture is too big.', 'success' => 0 @@ -361,12 +380,12 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Check if the image is too small - if(($metadata[0] < Configuration::getConfig('avatar_min_width') || $metadata[1] < Configuration::getConfig('avatar_min_height'))) { + if(($metadata[0] < Configuration::getConfig($mode .'_min_width') || $metadata[1] < Configuration::getConfig($mode .'_min_height'))) { // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'The resolution of this picture is too small.', 'success' => 0 @@ -378,14 +397,14 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Check if the file is too large - if((filesize($_FILES['avatar']['tmp_name']) > Configuration::getConfig('avatar_max_fsize'))) { + if((filesize($_FILES[$mode]['tmp_name']) > Configuration::getConfig($mode .'_max_fsize'))) { // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', - 'message' => 'The filesize of this picture is too large.', + 'message' => 'The filesize of this file is too large.', 'success' => 0 ]; @@ -404,13 +423,13 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications // Append extension to filename $filename .= image_type_to_extension($metadata[2]); - if(!move_uploaded_file($_FILES['avatar']['tmp_name'], $filename)) { + if(!move_uploaded_file($_FILES[$mode]['tmp_name'], $filename)) { // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', 'message' => 'Something went wrong, please try again.', 'success' => 0 @@ -420,14 +439,14 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications } // Update database - Users::updateUserDataField(Session::$userId, ['userAvatar' => basename($filename)]); + Users::updateUserDataField(Session::$userId, [$userDataKey => basename($filename)]); // Set render data $renderData['page'] = [ - 'title' => 'Avatar', + 'title' => $msgTitle, 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', - 'message' => 'Updated your avatar!', + 'message' => 'Updated your '. strtolower($msgTitle) .'!', 'success' => 1 ]; @@ -488,6 +507,27 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications break; + // Userpage + case 'userpage': + + // Base64 encode the userpage + $userPage = base64_encode($_POST['userpage']); + + // Update database + Users::updateUserDataField(Session::$userId, ['userPage' => [$userPage, 0]]); + + // Set render data + $renderData['page'] = [ + + 'title' => 'Userpage', + 'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings', + 'message' => 'Your userpage has been updated!', + 'success' => 1 + + ]; + + break; + // Fallback default: @@ -567,18 +607,24 @@ if(Users::checkLogin()) { ]; break; - // Avatar sizes + // Avatar and background sizes case 'avatar': - $renderData['avatar'] = [ - 'max_width' => Configuration::getConfig('avatar_max_width'), - 'max_height' => Configuration::getConfig('avatar_max_height'), - 'min_width' => Configuration::getConfig('avatar_min_width'), - 'min_height' => Configuration::getConfig('avatar_min_height'), - 'max_size' => Configuration::getConfig('avatar_max_fsize'), - 'max_size_view' => Main::getByteSymbol(Configuration::getConfig('avatar_max_fsize')) + case 'background': + $renderData[$currentPage] = [ + 'max_width' => Configuration::getConfig($currentPage .'_max_width'), + 'max_height' => Configuration::getConfig($currentPage .'_max_height'), + 'min_width' => Configuration::getConfig($currentPage .'_min_width'), + 'min_height' => Configuration::getConfig($currentPage .'_min_height'), + 'max_size' => Configuration::getConfig($currentPage .'_max_fsize'), + 'max_size_view' => Main::getByteSymbol(Configuration::getConfig($currentPage .'_max_fsize')) ]; break; + // Profile + case 'userpage': + + break; + // Profile case 'profile': $renderData['profile'] = [