Added profile editing
Signed-off-by: Flashwave <me@flash.moe>
This commit is contained in:
parent
31072687c8
commit
d6648f311c
5 changed files with 206 additions and 7 deletions
|
@ -37,7 +37,8 @@
|
|||
"20150725",
|
||||
"20150728",
|
||||
"20150730",
|
||||
"20150731"
|
||||
"20150731",
|
||||
"20150807"
|
||||
|
||||
]
|
||||
|
||||
|
@ -1619,6 +1620,19 @@
|
|||
"change": "Fixed pending friend requests function returning mutual friends instead of requests."
|
||||
}
|
||||
|
||||
],
|
||||
|
||||
"20150807": [
|
||||
|
||||
{
|
||||
"type": "ADD",
|
||||
"change": "Added profile changing frontend."
|
||||
},
|
||||
{
|
||||
"type": "ADD",
|
||||
"change": "Added profile changing backend."
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
}
|
||||
|
|
|
@ -814,6 +814,7 @@ class Users {
|
|||
|
||||
$fields[$field['id']] = $field;
|
||||
$fields[$field['id']]['ident'] = Main::cleanString($field['name'], true, true);
|
||||
$fields[$field['id']]['addit'] = json_decode($field['additional'], true);
|
||||
|
||||
}
|
||||
|
||||
|
@ -892,6 +893,30 @@ class Users {
|
|||
|
||||
}
|
||||
|
||||
// Updating the profile data of a user
|
||||
public static function updateUserProfileFields($id, $data) {
|
||||
|
||||
// We retrieve the current content from the database
|
||||
$current = self::getUser($id)['userData'];
|
||||
|
||||
// Merge the arrays
|
||||
$data = array_merge($current, ['profileFields' => $data]);
|
||||
|
||||
// Encode the json
|
||||
$data = json_encode($data);
|
||||
|
||||
// Store it in the database
|
||||
Database::update('users', [
|
||||
[
|
||||
'userData' => $data
|
||||
],
|
||||
[
|
||||
'id' => [$id, '=']
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// Getting the profile page of a user
|
||||
public static function getProfilePage($id, $inputIsData = false) {
|
||||
|
||||
|
|
|
@ -10,7 +10,33 @@
|
|||
<div class="settings-explanation">
|
||||
These are the external account links etc. on your profile, shouldn't need any additional explanation for this one.
|
||||
</div>
|
||||
|
||||
<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="profile" />
|
||||
{% for field in profile.fields %}
|
||||
<div class="profile-field">
|
||||
<div>
|
||||
<h2>{{ field.name }}</h2>
|
||||
</div>
|
||||
<div>
|
||||
<input type="{{ field.formtype }}" name="profile_{{ field.ident }}" class="inputStyling" placeholder="{{ field.description }}"{% if profile.user[field.ident].value %} value="{{ profile.user[field.ident].value }}"{% endif %} />
|
||||
</div>
|
||||
{% if field.addit %}
|
||||
{% for id,addit in field.addit %}
|
||||
<div>
|
||||
<input type="{{ addit[0] }}" id="{{ id }}" name="profile_additional_{{ id }}" />
|
||||
<label for="{{ id }}" style="font-size: 10px;">{{ addit[1]|raw }}</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="profile-save">
|
||||
<input type="submit" value="Save" name="submit" class="inputStyling" />
|
||||
<input type="reset" value="Reset" name="reset" class="inputStyling" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
|
|
|
@ -1342,11 +1342,14 @@ a.gotop.exit {
|
|||
margin: 0 2px 40px;
|
||||
float: left;
|
||||
border-radius: 3px;
|
||||
box-shadow: inset 0 0 1px #9475B2;
|
||||
background: #E4CFFF;
|
||||
}
|
||||
|
||||
.settings .friends-list > div:not(:last-child):hover {
|
||||
margin-bottom: 6px;
|
||||
background: #C2AFFE;
|
||||
box-shadow: inset 0 0 2px #9475B2;
|
||||
}
|
||||
|
||||
.settings .friends-list > div > .friends-list-data {
|
||||
|
@ -1541,7 +1544,8 @@ button.inputStyling:active {
|
|||
|
||||
input[type="text"].inputStyling,
|
||||
input[type="password"].inputStyling,
|
||||
input[type="date"].inputStyling {
|
||||
input[type="date"].inputStyling,
|
||||
input[type="url"].inputStyling {
|
||||
padding: 3px 4px;
|
||||
border: 1px solid #CCC;
|
||||
box-shadow: inset #DDD 0 0 5px;
|
||||
|
@ -1550,13 +1554,15 @@ input[type="date"].inputStyling {
|
|||
|
||||
input[type="text"].inputStyling.red,
|
||||
input[type="password"].inputStyling.red,
|
||||
input[type="date"].inputStyling.red {
|
||||
input[type="date"].inputStyling.red,
|
||||
input[type="url"].inputStyling.red {
|
||||
box-shadow: inset 0px 0px 7px #EB5959;
|
||||
}
|
||||
|
||||
input[type="text"].inputStyling.green,
|
||||
input[type="password"].inputStyling.green,
|
||||
input[type="date"].inputStyling.green {
|
||||
input[type="date"].inputStyling.green,
|
||||
input[type="url"].inputStyling.green {
|
||||
box-shadow: inset 0px 0px 7px #A9EC8B;
|
||||
}
|
||||
|
||||
|
|
|
@ -201,6 +201,134 @@ if(isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications
|
|||
Templates::render('errors/information.tpl', $renderData);
|
||||
exit;
|
||||
|
||||
} elseif(isset($_POST['submit']) && isset($_POST['submit'])) {
|
||||
|
||||
// Continue
|
||||
$continue = true;
|
||||
|
||||
// Check if the user is logged in
|
||||
if(!Users::checkLogin() || !$continue) {
|
||||
|
||||
$renderData['page'] = [
|
||||
'title' => 'Settings',
|
||||
'redirect' => '/authenticate',
|
||||
'message' => 'You must be logged in to edit your settings.',
|
||||
'success' => 0
|
||||
];
|
||||
|
||||
// Break
|
||||
$continue = false;
|
||||
|
||||
}
|
||||
|
||||
// Check session variables
|
||||
if(!isset($_REQUEST['timestamp']) || $_REQUEST['timestamp'] < time() - 1000 || !isset($_REQUEST['sessid']) || $_REQUEST['sessid'] != session_id() || !$continue) {
|
||||
|
||||
$renderData['page'] = [
|
||||
'title' => 'Session expired',
|
||||
'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
|
||||
'message' => 'Your session has expired, please refresh the page and try again.',
|
||||
'success' => 0
|
||||
];
|
||||
|
||||
// Break
|
||||
$continue = false;
|
||||
|
||||
}
|
||||
|
||||
// Change settings
|
||||
if($continue) {
|
||||
|
||||
// Switch to the correct mode
|
||||
switch($_POST['mode']) {
|
||||
|
||||
// Profile
|
||||
case 'profile':
|
||||
|
||||
// Get profile fields and create storage var
|
||||
$fields = Users::getProfileFields();
|
||||
$store = [];
|
||||
|
||||
// Go over each field
|
||||
foreach($fields as $field) {
|
||||
|
||||
// Add to the store array
|
||||
if(isset($_POST['profile_'. $field['ident']]) && !empty($_POST['profile_'. $field['ident']])) {
|
||||
|
||||
$store[$field['ident']] = $_POST['profile_'. $field['ident']];
|
||||
|
||||
}
|
||||
|
||||
// Check if there's additional values we should keep in mind
|
||||
if(isset($field['additional']) && !empty($field['additional'])) {
|
||||
|
||||
// Decode the json
|
||||
$field['additional'] = json_decode($field['additional'], true);
|
||||
|
||||
// Go over each additional value
|
||||
foreach($field['additional'] as $addKey => $addVal) {
|
||||
|
||||
// Skip if the value is empty
|
||||
if(!isset($_POST['profile_additional_'. $addKey]) || empty($_POST['profile_additional_'. $addKey]))
|
||||
continue;
|
||||
|
||||
// Add to the array
|
||||
$store[$addKey] = $_POST['profile_additional_'. $addKey];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update database
|
||||
Users::updateUserProfileFields(Session::$userId, $store);
|
||||
|
||||
// Set render data
|
||||
$renderData['page'] = [
|
||||
|
||||
'title' => 'Profile update',
|
||||
'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
|
||||
'message' => 'Your profile has been updated!',
|
||||
'success' => 1
|
||||
|
||||
];
|
||||
|
||||
break;
|
||||
|
||||
// Fallback
|
||||
default:
|
||||
|
||||
// Set render data
|
||||
$renderData['page'] = [
|
||||
|
||||
'title' => 'Unknown action',
|
||||
'redirect' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/settings',
|
||||
'message' => 'The requested method does not exist.',
|
||||
'success' => 0
|
||||
|
||||
];
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Print page contents or if the AJAX request is set only display the render data
|
||||
print isset($_REQUEST['ajax']) ?
|
||||
(
|
||||
$renderData['page']['title']
|
||||
. '|'
|
||||
. $renderData['page']['message']
|
||||
. '|'
|
||||
. $renderData['page']['success']
|
||||
. '|'
|
||||
. $renderData['page']['redirect']
|
||||
) :
|
||||
Templates::render('errors/information.tpl', $renderData);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
if(Users::checkLogin()) {
|
||||
|
@ -242,8 +370,8 @@ if(Users::checkLogin()) {
|
|||
// Profile
|
||||
case 'profile':
|
||||
$renderData['profile'] = [
|
||||
'user' => Users::getUser(Session::$userId),
|
||||
'fields' => Database::fetch('profilefields')
|
||||
'user' => Users::getUserProfileFields(Session::$userId),
|
||||
'fields' => Users::getProfileFields()
|
||||
];
|
||||
break;
|
||||
|
||||
|
|
Reference in a new issue