Added per user colours, removed old chat key stuff and fixed a permissions editor error.
This commit is contained in:
parent
340032f054
commit
af8cc763bf
17 changed files with 102 additions and 53 deletions
22
database/2018_07_18_151413_add_user_colour_column.php
Normal file
22
database/2018_07_18_151413_add_user_colour_column.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
namespace Misuzu\DatabaseMigrations\AddUserColourColumn;
|
||||
|
||||
use PDO;
|
||||
|
||||
function migrate_up(PDO $conn): void
|
||||
{
|
||||
$conn->exec('
|
||||
ALTER TABLE `msz_users`
|
||||
ADD COLUMN `user_colour` INT(11) NULL DEFAULT NULL AFTER `user_country`,
|
||||
DROP COLUMN `user_chat_key`;
|
||||
');
|
||||
}
|
||||
|
||||
function migrate_down(PDO $conn): void
|
||||
{
|
||||
$conn->exec('
|
||||
ALTER TABLE `msz_users`
|
||||
DROP COLUMN `user_colour`,
|
||||
ADD COLUMN `user_chat_key` VARCHAR(32) NULL DEFAULT NULL AFTER `user_country`;
|
||||
');
|
||||
}
|
|
@ -221,7 +221,7 @@ MIG;
|
|||
$getUserDisplayInfo = Database::prepare('
|
||||
SELECT
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `colour`
|
||||
FROM `msz_users` as u
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON u.`display_role` = r.`role_id`
|
||||
|
|
|
@ -117,15 +117,6 @@ switch ($authMode) {
|
|||
set_cookie_m('uid', $userId, $cookieLife);
|
||||
set_cookie_m('sid', $sessionKey, $cookieLife);
|
||||
|
||||
if (strpos($_SERVER['HTTP_HOST'], 'flashii.net') !== false) {
|
||||
$chatKey = user_generate_chat_key($userId);
|
||||
|
||||
if ($chatKey !== '') {
|
||||
setcookie('msz_tmp_id', $userId, $cookieLife, '/', '.flashii.net');
|
||||
setcookie('msz_tmp_key', $chatKey, $cookieLife, '/', '.flashii.net');
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: /');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ if ($changelogChange > 0) {
|
|||
u.`user_id`, u.`username`,
|
||||
DATE(`change_created`) as `change_date`,
|
||||
COALESCE(u.`user_title`, r.`role_title`) as `user_title`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_changelog_changes` as c
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = c.`user_id`
|
||||
|
|
|
@ -5,14 +5,6 @@ use Misuzu\Database;
|
|||
|
||||
require_once __DIR__ . '/../misuzu.php';
|
||||
|
||||
/*if ($app->getUserId() === 1) {
|
||||
$sMessage = new Swift_Message('Test e-mail!');
|
||||
$sMessage->setFrom(['sys@flashii.net' => 'Flashii.net']);
|
||||
$sMessage->setTo(['julianvdg@gmail.com' => 'flash']);
|
||||
$sMessage->setBody('Misuzu and SwiftMailer are cool and cute.');
|
||||
var_dump(Application::mailer()->send($sMessage));
|
||||
}*/
|
||||
|
||||
$config = $app->getConfig();
|
||||
$tpl = $app->getTemplating();
|
||||
|
||||
|
@ -30,7 +22,7 @@ $news = Database::query('
|
|||
SELECT
|
||||
p.`post_id`, p.`post_title`, p.`post_text`, p.`created_at`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_news_posts` as p
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON p.`user_id` = u.`user_id`
|
||||
|
@ -50,7 +42,7 @@ $statistics = Cache::instance()->get('index:stats:v1', function () {
|
|||
'lastUser' => Database::query('
|
||||
SELECT
|
||||
u.`user_id`, u.`username`, u.`created_at`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_users` as u
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
|
|
|
@ -28,7 +28,7 @@ switch ($_GET['v'] ?? null) {
|
|||
c.`change_id`, c.`change_log`, c.`change_created`,
|
||||
a.`action_name`, a.`action_colour`, a.`action_class`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_changelog_changes` as c
|
||||
LEFT JOIN `msz_changelog_actions` as a
|
||||
ON a.`action_id` = c.`action_id`
|
||||
|
|
|
@ -33,7 +33,7 @@ switch ($_GET['v'] ?? null) {
|
|||
$getManageUsers = Database::prepare('
|
||||
SELECT
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `colour`
|
||||
FROM `msz_users` as u
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON u.`display_role` = r.`role_id`
|
||||
|
@ -70,7 +70,7 @@ switch ($_GET['v'] ?? null) {
|
|||
u.*,
|
||||
INET6_NTOA(u.`register_ip`) as `register_ip_decoded`,
|
||||
INET6_NTOA(u.`last_ip`) as `last_ip_decoded`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `colour`
|
||||
FROM `msz_users` as u
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON u.`display_role` = r.`role_id`
|
||||
|
@ -151,6 +151,35 @@ switch ($_GET['v'] ?? null) {
|
|||
user_avatar_set_from_path($manageUser['user_id'], $_FILES['avatar']['tmp_name']['file']);
|
||||
}
|
||||
|
||||
if (!empty($_POST['colour']) && is_array($_POST['colour'])) {
|
||||
$userColour = null;
|
||||
|
||||
if (!empty($_POST['colour']['enable'])) {
|
||||
$userColour = colour_create();
|
||||
|
||||
foreach (['red', 'green', 'blue'] as $key) {
|
||||
$value = (int)($_POST['colour'][$key] ?? -1);
|
||||
$func = 'colour_set_' . ucfirst($key);
|
||||
|
||||
if ($value < 0 || $value > 0xFF) {
|
||||
echo 'invalid colour value';
|
||||
break 2;
|
||||
}
|
||||
|
||||
$func($userColour, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$updateUserColour = Database::prepare('
|
||||
UPDATE `msz_users`
|
||||
SET `user_colour` = :colour
|
||||
WHERE `user_id` = :user_id
|
||||
');
|
||||
$updateUserColour->bindValue('colour', $userColour);
|
||||
$updateUserColour->bindValue('user_id', $userId);
|
||||
$updateUserColour->execute();
|
||||
}
|
||||
|
||||
if (!empty($_POST['password'])
|
||||
&& is_array($_POST['password'])
|
||||
&& !empty($_POST['password']['new'])
|
||||
|
@ -276,7 +305,7 @@ switch ($_GET['v'] ?? null) {
|
|||
$roleId = $_GET['r'] ?? null;
|
||||
|
||||
if ($canManagePerms) {
|
||||
$tpl->var('permissions', $permissions = manage_perms_list(perms_get_role_raw($roleId)));
|
||||
$tpl->var('permissions', $permissions = manage_perms_list(perms_get_role_raw($roleId ?? 0)));
|
||||
}
|
||||
|
||||
if ($isPostRequest) {
|
||||
|
|
|
@ -91,7 +91,7 @@ $getUsers = Database::prepare("
|
|||
u.`user_id`, u.`username`, u.`user_country`,
|
||||
u.`created_at` as `user_joined`, u.`last_seen` as `user_last_seen`,
|
||||
COALESCE(u.`user_title`, r.`role_title`) as `user_title`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
|
|
|
@ -21,7 +21,7 @@ if ($postId !== null) {
|
|||
p.`post_id`, p.`post_title`, p.`post_text`, p.`created_at`,
|
||||
c.`category_id`, c.`category_name`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_news_posts` as p
|
||||
LEFT JOIN `msz_news_categories` as c
|
||||
ON p.`category_id` = c.`category_id`
|
||||
|
@ -67,7 +67,7 @@ if ($categoryId !== null) {
|
|||
p.`post_id`, p.`post_title`, p.`post_text`, p.`created_at`,
|
||||
c.`category_id`, c.`category_name`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_news_posts` as p
|
||||
LEFT JOIN `msz_news_categories` as c
|
||||
ON p.`category_id` = c.`category_id`
|
||||
|
@ -133,7 +133,7 @@ $getPosts = Database::prepare('
|
|||
p.`post_id`, p.`post_title`, p.`post_text`, p.`created_at`,
|
||||
c.`category_id`, c.`category_name`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_news_posts` as p
|
||||
LEFT JOIN `msz_news_categories` as c
|
||||
ON p.`category_id` = c.`category_id`
|
||||
|
|
|
@ -46,7 +46,7 @@ switch ($mode) {
|
|||
SELECT
|
||||
u.*,
|
||||
COALESCE(u.`user_title`, r.`role_title`) as `user_title`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
|
|
|
@ -178,7 +178,7 @@ define('MSZ_FORUM_GET_CHILDREN_QUERY_STANDARD', '
|
|||
p.`post_created` as `recent_post_created`,
|
||||
u.`user_id` as `recent_post_user_id`,
|
||||
u.`username` as `recent_post_username`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `recent_post_user_colour`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `recent_post_user_colour`,
|
||||
(
|
||||
SELECT COUNT(`topic_id`)
|
||||
FROM `msz_forum_topics`
|
||||
|
|
|
@ -69,7 +69,7 @@ define('MSZ_FORUM_POST_LISTING_QUERY_STANDARD', '
|
|||
u.`user_id` as `poster_id`,
|
||||
u.`username` as `poster_name`,
|
||||
u.`created_at` as `poster_joined`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `poster_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `poster_colour`
|
||||
FROM `msz_forum_posts` as p
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = p.`user_id`
|
||||
|
|
|
@ -88,12 +88,12 @@ define('MSZ_TOPIC_LISTING_QUERY_STANDARD', '
|
|||
:user_id as `target_user_id`,
|
||||
t.`topic_id`, t.`topic_title`, t.`topic_locked`, t.`topic_type`, t.`topic_created`,
|
||||
au.`user_id` as `author_id`, au.`username` as `author_name`,
|
||||
COALESCE(ar.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `author_colour`,
|
||||
COALESCE(au.`user_colour`, ar.`role_colour`) as `author_colour`,
|
||||
lp.`post_id` as `response_id`,
|
||||
lp.`post_created` as `response_created`,
|
||||
lu.`user_id` as `respondent_id`,
|
||||
lu.`username` as `respondent_name`,
|
||||
COALESCE(lr.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `respondent_colour`,
|
||||
COALESCE(lu.`user_colour`, lr.`role_colour`) as `respondent_colour`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
|
|
|
@ -48,23 +48,6 @@ function user_password_hash(string $password): string
|
|||
return password_hash($password, MSZ_USERS_PASSWORD_HASH_ALGO);
|
||||
}
|
||||
|
||||
// Temporary key generation for chat login.
|
||||
// Should eventually be replaced with a callback login system.
|
||||
function user_generate_chat_key(int $userId): string
|
||||
{
|
||||
$chatKey = bin2hex(random_bytes(16));
|
||||
|
||||
$setChatKey = Database::prepare('
|
||||
UPDATE `msz_users`
|
||||
SET `user_chat_key` = :user_chat_key
|
||||
WHERE `user_id` = :user_id
|
||||
');
|
||||
$setChatKey->bindValue('user_chat_key', $chatKey);
|
||||
$setChatKey->bindValue('user_id', $userId);
|
||||
|
||||
return $setChatKey->execute() ? $chatKey : '';
|
||||
}
|
||||
|
||||
define('MSZ_USER_AVATAR_FORMAT', '%d.msz');
|
||||
|
||||
function user_avatar_delete(int $userId): void
|
||||
|
|
|
@ -39,7 +39,7 @@ function audit_log_list(int $offset, int $take, int $userId = 0): array
|
|||
l.`log_id`, l.`log_action`, l.`log_params`, l.`log_created`,
|
||||
u.`user_id`, u.`username`,
|
||||
INET6_NTOA(l.`log_ip`) as `log_ip`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_audit_log` as l
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = l.`user_id`
|
||||
|
|
|
@ -49,7 +49,7 @@ define('MSZ_CHANGELOG_GET_QUERY', '
|
|||
u.`user_id`, u.`username`,
|
||||
DATE(`change_created`) as `change_date`,
|
||||
!ISNULL(c.`change_text`) as `change_has_text`,
|
||||
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `user_colour`
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`
|
||||
FROM `msz_changelog_changes` as c
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON u.`user_id` = c.`user_id`
|
||||
|
|
|
@ -115,6 +115,38 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<h2 class="container__subtitle">Colour</h2>
|
||||
|
||||
{% set colour_is_defined = view_user is defined and view_user.user_colour is not null and not view_user.user_colour|colour_get_inherit %}
|
||||
|
||||
<label class="form__label">
|
||||
<div class="form__label__text">Custom Colour</div>
|
||||
<div class="form__label__input">
|
||||
<input class="input" type="checkbox" name="colour[enable]"{% if colour_is_defined %} checked{% endif %}>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="form__label">
|
||||
<div class="form__label__text">Red</div>
|
||||
<div class="form__label__input">
|
||||
<input class="input input--number" type="number" value="{{ colour_is_defined ? view_user.user_colour|colour_get_red : '0' }}" min="0" max="255" name="colour[red]">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="form__label">
|
||||
<div class="form__label__text">Green</div>
|
||||
<div class="form__label__input">
|
||||
<input class="input input--number" type="number" value="{{ colour_is_defined ? view_user.user_colour|colour_get_green : '0' }}" min="0" max="255" name="colour[green]">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label class="form__label">
|
||||
<div class="form__label__text">Blue</div>
|
||||
<div class="form__label__input">
|
||||
<input class="input input--number" type="number" value="{{ colour_is_defined ? view_user.user_colour|colour_get_blue : '0' }}" min="0" max="255" name="colour[blue]">
|
||||
</div>
|
||||
</label>
|
||||
|
||||
{% if can_manage_perms %}
|
||||
<div class="container">
|
||||
<h2 class="container__subtitle">Permissions</h2>
|
||||
|
|
Loading…
Add table
Reference in a new issue