bunch of fuck

This commit is contained in:
flash 2015-08-10 21:09:47 +02:00
parent 88256b32fb
commit b1391f3d4d
9 changed files with 143 additions and 129 deletions

View file

@ -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"
}
]

View file

@ -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) {

View file

@ -18,7 +18,7 @@
<div>Aesthetics</div>
<a href="/settings/avatar">Avatar</a>
<a href="/settings/background">Background</a>
<a href="/settings/userpage">Profile Page</a>
<a href="/settings/userpage">Userpage</a>
<div>Account</div>
<a href="/settings/email">E-mail Address</a>
<a href="/settings/username">Username</a>

View file

@ -13,7 +13,7 @@
{% else %}
<div id="userBackground"></div>
<div class="content profile">
<div class="{% if profile.profilePage|length > 1 %}content-right {% endif %}content-column">
<div class="{% if profile.userPage|length > 1 %}content-right {% endif %}content-column">
<div style="text-align: center;">
<img src="/a/{{ profile.user.id }}" alt="{{ profile.user.username }}'s Avatar" class="default-avatar-setting" style="box-shadow: 0 3px 7px #{% if profile.online %}484{% else %}844{% endif %};" /><br />
{% if profile.user.rank_main > 1 and profile.ban_check|length < 1 %}
@ -87,8 +87,8 @@
{% endif %}
</div>
</div>
<div class="content-left content-column markdown{% if profile.profilePage|length < 1 %} hidden{% endif %}">
{{ profile.profilePage|raw }}
<div class="content-left content-column markdown{% if profile.userPage|length < 1 %} hidden{% endif %}">
{{ profile.userPage|raw }}
</div>
<div class="clear"></div>
</div>

View file

@ -9,9 +9,25 @@
</div>
<div class="settings-explanation">
<div>The background that is displayed on your profile.</div>
<div>Maximum image size is 2560x1440, minimum image size is 20x20, maximum file size is 10 MB.</div>
<div>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 }}.</div>
</div>
<form enctype="multipart/form-data" method="post" action="{{ setting.action }}">
<input type="hidden" name="sessid" value="{{ php.sessionid }}" />
<input type="hidden" name="timestamp" value="{{ php.time }}" />
<input type="hidden" name="mode" value="background" />
<input type="hidden" name="MAX_FILE_SIZE" value="{{ background.max_size }}" />
<div style="text-align: center;">
<div>
<img src="/bg/{{ user.data.id }}" alt="Your Background" class="default-avatar-setting" style="max-width: 90%; max-height: 90%;" />
</div>
<div>
<input type="file" name="background" />
</div>
<div>
<input type="submit" value="Submit" name="submit" class="inputStyling" />
</div>
</div>
</form>
</div>
<div class="clear"></div>
</div>

View file

@ -9,9 +9,34 @@
</div>
<div class="settings-explanation">
<div>The custom text that is displayed on your profile.</div>
<div><a href="/r/typography" class="default">Click here if you don't know how to markdown!</a></div>
<div><a href="/r/markdown" class="default">Click here if you don't know how to markdown!</a></div>
</div>
{#
{% if preview %}
<div class="markdown" style="max-height: 600px;overflow-y:auto;">
{{ preview|raw }}
</div>
<hr class="default" />
{% endif %}
<form enctype="multipart/form-data" method="post" action="{{ sakura.currentpage }}">
<input type="hidden" name="sessid" value="{{ php.sessionid }}" />
<input type="hidden" name="timestamp" value="{{ php.time }}" />
<input type="hidden" name="mode" value="userpage" />
<div><textarea name="userpage" placeholder="# Welcome to my profile page!" class="inputStyling" style="width: calc(100% - 12px); height: 500px;" />{{ userPage.content }}</textarea></div>
<div>
<h2>Parse mode</h2>
<input type="radio" name="parse" value="bbcode" id="bbcode"{% if userPage.parse == 1 %} checked="checked"{% endif %} /> <label for="bbcode">BBCodes</label>
<input type="radio" name="parse" value="markdown" id="markdown"{% if userPage.parse == 2 %} checked="checked"{% endif %} /> <label for="markdown">Markdown</label>
<input type="radio" name="parse" value="plain" id="plain"{% if userPage.parse == 0 %} checked="checked"{% endif %} /> <label for="plain">Plain Text</label>
</div>
<div class="profile-save">
<input type="submit" value="Save" name="submit" class="inputStyling" />
<input type="submit" value="Preview" name="preview" class="inputStyling" />
<input type="reset" value="Reset" name="reset" class="inputStyling" />
</div>
</form>
#}
<h1 class="stylised">Redoing this bc garbage.</h1>
</div>
<div class="clear"></div>
</div>

View file

@ -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;

View file

@ -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']),

View file

@ -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'] = [