Merge pull request #5 from forkbb/delete_guest
Delete guest from users table
This commit is contained in:
commit
bc2d56df2d
31 changed files with 218 additions and 1377 deletions
|
@ -37,7 +37,7 @@ class Install
|
|||
}
|
||||
$uri = \rawurldecode($uri);
|
||||
|
||||
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => FORK_GROUP_ADMIN]);
|
||||
$this->c->user = $this->c->users->create(['id' => 1, 'group_id' => FORK_GROUP_ADMIN]);
|
||||
$this->c->Lang->load('common');
|
||||
|
||||
$r = $this->c->Router;
|
||||
|
|
|
@ -42,7 +42,7 @@ class Primary
|
|||
|| ! isset($this->c->admins->list[$this->c->user->id])
|
||||
) {
|
||||
if (! $this->c->isInit('user')) {
|
||||
$this->c->user = $this->c->users->create(['id' => 1, 'group_id' => FORK_GROUP_GUEST]);
|
||||
$this->c->user = $this->c->users->create(['id' => 0, 'group_id' => FORK_GROUP_GUEST]);
|
||||
}
|
||||
|
||||
return $this->c->Maintenance;
|
||||
|
|
|
@ -54,7 +54,7 @@ class Routing
|
|||
// смена кодовой фразы
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/login/{id|i:[2-9]|[1-9]\d+}/{key}/{hash}',
|
||||
'/login/{id|i:[1-9]\d*}/{key}/{hash}',
|
||||
'Auth:changePass',
|
||||
'ChangePassword'
|
||||
);
|
||||
|
@ -75,7 +75,7 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/registration/activate/{id|i:[2-9]|[1-9]\d+}/{key}/{hash}',
|
||||
'/registration/activate/{id|i:[1-9]\d*}/{key}/{hash}',
|
||||
'Register:activate',
|
||||
'RegActivate'
|
||||
);
|
||||
|
@ -163,7 +163,7 @@ class Routing
|
|||
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/search[/user/{uid|i:[2-9]|[1-9]\d+}]/{action:(?!search)[a-z_]+}[/in_forum/{forum|i:[1-9]\d*}][/{page|i:[1-9]\d*}]',
|
||||
'/search[/user/{uid|i:[1-9]\d*}]/{action:(?!search)[a-z_]+}[/in_forum/{forum|i:[1-9]\d*}][/{page|i:[1-9]\d*}]',
|
||||
'Search:action',
|
||||
'SearchAction'
|
||||
);
|
||||
|
@ -185,37 +185,37 @@ class Routing
|
|||
// юзеры
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/{name}',
|
||||
'/user/{id|i:[1-9]\d*}/{name}',
|
||||
'ProfileView:view',
|
||||
'User'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/edit/profile',
|
||||
'/user/{id|i:[1-9]\d*}/edit/profile',
|
||||
'ProfileEdit:edit',
|
||||
'EditUserProfile'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/edit/config',
|
||||
'/user/{id|i:[1-9]\d*}/edit/config',
|
||||
'ProfileConfig:config',
|
||||
'EditUserBoardConfig'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/edit/email',
|
||||
'/user/{id|i:[1-9]\d*}/edit/email',
|
||||
'ProfileEmail:email',
|
||||
'EditUserEmail'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/edit/passphrase',
|
||||
'/user/{id|i:[1-9]\d*}/edit/passphrase',
|
||||
'ProfilePass:pass',
|
||||
'EditUserPass'
|
||||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/user/{id|i:[2-9]|[1-9]\d+}/edit/moderation',
|
||||
'/user/{id|i:[1-9]\d*}/edit/moderation',
|
||||
'ProfileMod:moderation',
|
||||
'EditUserModeration'
|
||||
);
|
||||
|
@ -358,7 +358,7 @@ class Routing
|
|||
) {
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/send_email/{id|i:[2-9]|[1-9]\d+}/{hash}',
|
||||
'/send_email/{id|i:[1-9]\d*}/{hash}',
|
||||
'Email:email',
|
||||
'SendEmail'
|
||||
);
|
||||
|
@ -437,7 +437,7 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/admin/users/user/{id|i:[2-9]|[1-9]\d+}[/{page|i:[1-9]\d*}]',
|
||||
'/admin/users/user/{id|i:[1-9]\d*}[/{page|i:[1-9]\d*}]',
|
||||
'AdminUsersStat:view',
|
||||
'AdminUserStat'
|
||||
);
|
||||
|
@ -464,7 +464,7 @@ class Routing
|
|||
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/admin/users/promote/{uid|i:[2-9]|[1-9]\d+}/{pid|i:[1-9]\d*}/{token}',
|
||||
'/admin/users/promote/{uid|i:[1-9]\d*}/{pid|i:[1-9]\d*}/{token}',
|
||||
'AdminUsersPromote:promote',
|
||||
'AdminUserPromote'
|
||||
);
|
||||
|
@ -493,7 +493,7 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::DUO,
|
||||
'/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid|i:[2-9]|[1-9]\d+}]]',
|
||||
'/admin/bans/new[/{ids:\d+(?:-\d+)*}[/{uid|i:[1-9]\d*}]]',
|
||||
'AdminBans:add',
|
||||
'AdminBansNew'
|
||||
);
|
||||
|
@ -511,7 +511,7 @@ class Routing
|
|||
);
|
||||
$r->add(
|
||||
$r::GET,
|
||||
'/admin/bans/delete/{id|i:[1-9]\d*}/{token}[/{uid|i:[2-9]|[1-9]\d+}]',
|
||||
'/admin/bans/delete/{id|i:[1-9]\d*}/{token}[/{uid|i:[1-9]\d*}]',
|
||||
'AdminBans:delete',
|
||||
'AdminBansDelete'
|
||||
);
|
||||
|
|
|
@ -37,7 +37,7 @@ class Update
|
|||
}
|
||||
$uri = \rawurldecode($uri);
|
||||
|
||||
$this->c->user = $this->c->users->create(['id' => 2, 'group_id' => FORK_GROUP_ADMIN]); //???? id?
|
||||
$this->c->user = $this->c->users->create(['id' => 1, 'group_id' => FORK_GROUP_ADMIN]); //???? id?
|
||||
$this->c->Lang->load('common');
|
||||
|
||||
$r = $this->c->Router;
|
||||
|
|
|
@ -117,14 +117,13 @@ class Cookie extends Model
|
|||
|
||||
if (
|
||||
! \is_string($ckUser)
|
||||
|| ! \preg_match('%^(\-)?(\d{1,10})_(\d{10})_([a-f\d]{32,128})_([a-f\d]{32,128})$%Di', $ckUser, $ms)
|
||||
|| ! \preg_match('%^(\-)?([1-9]\d{0,9})_(\d{10})_([a-f\d]{32,128})_([a-f\d]{32,128})$%Di', $ckUser, $ms)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
2 > $ms[2]
|
||||
|| \time() > $ms[3]
|
||||
\time() > $ms[3]
|
||||
|| ! \hash_equals(
|
||||
$this->c->Secury->hmac($ms[1] . $ms[2] . $ms[3] . $ms[4], $this->key1),
|
||||
$ms[5]
|
||||
|
|
|
@ -80,7 +80,7 @@ class Delete extends Action
|
|||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::forums
|
||||
SET last_poster_id=1
|
||||
SET last_poster_id=0
|
||||
WHERE last_poster_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
|
|
@ -51,6 +51,11 @@ class Save extends Action
|
|||
$this->c->DB->exec($query, $vars);
|
||||
$group->resModified();
|
||||
|
||||
// сбросить кеш для гостя
|
||||
if ($group->groupGuest) {
|
||||
$this->c->users->resetGuest();
|
||||
}
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ class Online extends Model
|
|||
if ($cur['logged'] < $tVisit) {
|
||||
$needClean = true;
|
||||
|
||||
if ($cur['user_id'] > 1) {
|
||||
if ($cur['user_id'] > 0) {
|
||||
$vars = [
|
||||
':last' => $cur['logged'],
|
||||
':id' => $cur['user_id'],
|
||||
|
@ -124,7 +124,7 @@ class Online extends Model
|
|||
}
|
||||
|
||||
// пользователь
|
||||
if ($cur['user_id'] > 1) {
|
||||
if ($cur['user_id'] > 0) {
|
||||
$users[$cur['user_id']] = $cur['ident'];
|
||||
// гость
|
||||
} elseif ('' == $cur['o_name']) {
|
||||
|
@ -158,7 +158,7 @@ class Online extends Model
|
|||
$this->all = $all;
|
||||
$this->detail = $detail;
|
||||
|
||||
unset($this->online[1]);
|
||||
unset($this->online[0]);
|
||||
|
||||
if ($detail) {
|
||||
$this->users = $users;
|
||||
|
@ -186,15 +186,15 @@ class Online extends Model
|
|||
if ($this->c->user->logged > 0) {
|
||||
$query = 'UPDATE ::online
|
||||
SET logged=?i:logged, o_position=?s:pos, o_name=?s:name
|
||||
WHERE user_id=1 AND ident=?s:ip';
|
||||
WHERE user_id=0 AND ident=?s:ip';
|
||||
} else {
|
||||
$query = 'INSERT INTO ::online (user_id, ident, logged, o_position, o_name)
|
||||
SELECT 1, ?s:ip, ?i:logged, ?s:pos, ?s:name
|
||||
SELECT 0, ?s:ip, ?i:logged, ?s:pos, ?s:name
|
||||
FROM ::groups
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM ::online
|
||||
WHERE user_id=1 AND ident=?s:ip
|
||||
WHERE user_id=0 AND ident=?s:ip
|
||||
)
|
||||
LIMIT 1';
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ class Online extends Model
|
|||
];
|
||||
$query = 'DELETE
|
||||
FROM ::online
|
||||
WHERE user_id=1 AND ident=?s:ip';
|
||||
WHERE user_id=0 AND ident=?s:ip';
|
||||
} else {
|
||||
$vars = [
|
||||
':id' => $user->id,
|
||||
|
|
|
@ -146,19 +146,19 @@ class Delete extends Method
|
|||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::pm_topics
|
||||
SET poster_id=1, poster_status=?i:status
|
||||
SET poster_id=0, poster_status=?i:status
|
||||
WHERE poster_id IN (?ai:ids)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::pm_topics
|
||||
SET target_id=1, target_status=?i:status
|
||||
SET target_id=0, target_status=?i:status
|
||||
WHERE target_id IN (?ai:ids)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::pm_posts
|
||||
SET poster_id=1
|
||||
SET poster_id=0
|
||||
WHERE poster_id IN (?ai:ids)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
|
|
@ -64,21 +64,15 @@ class PPost extends DataModel
|
|||
|
||||
protected function getuser(): User
|
||||
{
|
||||
$user = $this->c->users->load($this->poster_id);
|
||||
|
||||
if (
|
||||
! $user instanceof User
|
||||
&& 1 !== $this->poster_id // ???? может сменить id гостя?
|
||||
$this->poster_id < 1
|
||||
|| ! ($user = $this->c->users->load($this->poster_id)) instanceof User
|
||||
) {
|
||||
$user = $this->c->users->load(1);
|
||||
$user = $this->c->users->guest(['username' => $this->poster]);
|
||||
}
|
||||
|
||||
if (! $user instanceof User) {
|
||||
throw new RuntimeException("No user data in ppost number {$this->id}");
|
||||
} elseif ($user->isGuest) {
|
||||
$user = clone $user;
|
||||
|
||||
$user->__username = $this->poster;
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
|
|
@ -1127,7 +1127,6 @@ class Install extends Admin
|
|||
$this->c->DB->exec('UPDATE ::groups SET g_pm=0, g_sig_length=0, g_sig_lines=0 WHERE g_id=?i', [FORK_GROUP_GUEST]);
|
||||
|
||||
$ip = \filter_var($_SERVER['REMOTE_ADDR'], \FILTER_VALIDATE_IP) ?: '0.0.0.0';
|
||||
$this->c->DB->exec('INSERT INTO ::users (group_id, username, username_normal, password, signature, u_pm) VALUES (?i, ?s, ?s, ?s, \'\', ?i)', [FORK_GROUP_GUEST, __('Guest '), $this->c->users->normUsername(__('Guest ')), __('Guest '), 0]);
|
||||
$this->c->DB->exec('INSERT INTO ::users (group_id, username, username_normal, password, email, email_normal, language, style, num_posts, last_post, registered, registration_ip, last_visit, signature, num_topics) VALUES (?i, ?s, ?s, ?s, ?s, ?s, ?s, ?s, 1, ?i, ?i, ?s, ?i, \'\', 1)', [FORK_GROUP_ADMIN, $v->username, $this->c->users->normUsername($v->username), password_hash($v->password, \PASSWORD_DEFAULT), $v->email, $this->c->NormEmail->normalize($v->email), $v->defaultlang, $v->defaultstyle, $now, $now, $ip, $now]);
|
||||
|
||||
$pun_config = [
|
||||
|
@ -1212,9 +1211,9 @@ class Install extends Admin
|
|||
}
|
||||
|
||||
$this->c->DB->exec('INSERT INTO ::categories (cat_name, disp_position) VALUES (?s, ?i)', [__('Test category'), 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, last_poster_id, last_topic, disp_position, cat_id, moderators) VALUES (?s, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?s, ?i, ?i, \'\')', [__('Test forum'), __('This is just a test forum'), 1, 1, $now, 1, $v->username, 2, __('Test post'), 1, 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::topics (poster, poster_id, subject, posted, first_post_id, last_post, last_post_id, last_poster, last_poster_id, forum_id) VALUES(?s, ?i, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?i)', [$v->username, 2, __('Test post'), $now, 1, $now, 1, $v->username, 2, 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(?s, ?i, ?s, ?s, ?i, ?i)', [$v->username, 2, $ip, __('Test message'), $now, 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, last_poster_id, last_topic, disp_position, cat_id, moderators) VALUES (?s, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?s, ?i, ?i, \'\')', [__('Test forum'), __('This is just a test forum'), 1, 1, $now, 1, $v->username, 1, __('Test post'), 1, 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::topics (poster, poster_id, subject, posted, first_post_id, last_post, last_post_id, last_poster, last_poster_id, forum_id) VALUES(?s, ?i, ?s, ?i, ?i, ?i, ?i, ?s, ?i, ?i)', [$v->username, 1, __('Test post'), $now, 1, $now, 1, $v->username, 1, 1]);
|
||||
$this->c->DB->exec('INSERT INTO ::posts (poster, poster_id, poster_ip, message, posted, topic_id) VALUES(?s, ?i, ?s, ?s, ?i, ?i)', [$v->username, 1, $ip, __('Test message'), $now, 1]);
|
||||
|
||||
$smilies = [
|
||||
':)' => 'smile.png',
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -83,7 +83,7 @@ abstract class Users extends Admin
|
|||
return (int) $value;
|
||||
}, $selected);
|
||||
$bad = \array_filter($selected, function ($value) {
|
||||
return $value < 2;
|
||||
return $value < 1;
|
||||
});
|
||||
|
||||
if (! empty($bad)) {
|
||||
|
|
|
@ -61,7 +61,7 @@ class Result extends Users
|
|||
])->addRules([
|
||||
'token' => 'token:AdminUsersResult',
|
||||
'users' => 'required|array',
|
||||
'users.*' => 'required|integer|min:2|max:9999999999',
|
||||
'users.*' => 'required|integer|min:1|max:9999999999',
|
||||
'ban' => $this->c->userRules->banUsers ? 'checkbox' : 'absent',
|
||||
'delete' => $this->c->userRules->deleteUsers ? 'checkbox' : 'absent',
|
||||
'change_group' => $this->c->userRules->changeGroup ? 'checkbox' : 'absent',
|
||||
|
|
|
@ -12,7 +12,6 @@ namespace ForkBB\Models\Pages;
|
|||
|
||||
use ForkBB\Models\Page;
|
||||
use ForkBB\Models\PM\Cnst;
|
||||
use function \ForkBB\__;
|
||||
|
||||
class PM extends Page
|
||||
{
|
||||
|
@ -29,7 +28,7 @@ class PM extends Page
|
|||
if ('' === \trim($second, '1234567890')) {
|
||||
$second = (int) $second;
|
||||
|
||||
if ($second < 2) { // ???? вынести все в роутер?
|
||||
if ($second < 1) { // ???? вынести все в роутер?
|
||||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
} elseif (
|
||||
|
|
|
@ -100,13 +100,13 @@ class Delete extends Action
|
|||
':users' => $uidsToGuest,
|
||||
];
|
||||
$query = 'UPDATE ::posts
|
||||
SET poster_id=1
|
||||
SET poster_id=0
|
||||
WHERE poster_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::posts
|
||||
SET editor_id=1
|
||||
SET editor_id=0
|
||||
WHERE editor_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
@ -134,7 +134,7 @@ class Delete extends Action
|
|||
$parents = $this->c->topics->loadByIds($tids, false);
|
||||
|
||||
$query = 'UPDATE ::posts
|
||||
SET editor_id=1
|
||||
SET editor_id=0
|
||||
WHERE editor_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
|
|
@ -64,22 +64,18 @@ class Post extends DataModel
|
|||
*/
|
||||
protected function getuser(): User
|
||||
{
|
||||
$user = $this->c->users->load($this->poster_id);
|
||||
|
||||
if (
|
||||
! $user instanceof User
|
||||
&& 1 !== $this->poster_id // ???? может сменить id гостя?
|
||||
$this->poster_id < 1
|
||||
|| ! ($user = $this->c->users->load($this->poster_id)) instanceof User
|
||||
) {
|
||||
$user = $this->c->users->load(1);
|
||||
$user = $this->c->users->guest([
|
||||
'username' => $this->poster,
|
||||
'email' => $this->poster_email,
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $user instanceof User) {
|
||||
throw new RuntimeException("No user data in post number {$this->id}");
|
||||
} elseif ($user->isGuest) {
|
||||
$user = clone $user;
|
||||
|
||||
$user->__email = $this->poster_email;
|
||||
$user->__username = $this->poster;
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
|
|
@ -34,7 +34,7 @@ class UserInfoFromIP extends Action
|
|||
$ids = [];
|
||||
|
||||
while ($row = $stmt->fetch()) {
|
||||
if (1 === $row['poster_id']) {
|
||||
if ($row['poster_id'] < 1) {
|
||||
$result[] = $row['poster'];
|
||||
} elseif (empty($ids[$row['poster_id']])) {
|
||||
$result[] = $row['poster_id'];
|
||||
|
|
|
@ -62,6 +62,7 @@ class View extends Action
|
|||
}
|
||||
}
|
||||
|
||||
unset($userIds[0]); // гостя загружать не надо
|
||||
$this->c->users->loadByIds($userIds);
|
||||
|
||||
$offset = ($arg->page - 1) * $this->c->user->disp_posts;
|
||||
|
|
|
@ -40,20 +40,17 @@ class Report extends DataModel
|
|||
*/
|
||||
protected function getauthor(): User
|
||||
{
|
||||
if ($this->reported_by < 1) {
|
||||
throw new RuntimeException('No author data');
|
||||
if (
|
||||
$this->reported_by < 1
|
||||
|| ! ($user = $this->c->users->load($this->reported_by)) instanceof User
|
||||
) {
|
||||
$user = $this->c->users->guest([
|
||||
'username' => '{User #' . $this->reported_by .'}',
|
||||
]);
|
||||
}
|
||||
|
||||
$user = $this->c->users->load($this->reported_by);
|
||||
|
||||
if (
|
||||
! $user instanceof User
|
||||
|| $user->isGuest
|
||||
) {
|
||||
$user = $this->c->users->create();
|
||||
|
||||
$user->__id = $this->reported_by;
|
||||
$user->__username = '{User #' . $this->reported_by .'}';
|
||||
if (! $user instanceof User) {
|
||||
throw new RuntimeException('No author data');
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
@ -79,20 +76,17 @@ class Report extends DataModel
|
|||
*/
|
||||
protected function getmarker(): User
|
||||
{
|
||||
if ($this->zapped_by < 1) {
|
||||
throw new RuntimeException('No marker data');
|
||||
if (
|
||||
$this->zapped_by < 1
|
||||
|| ! ($user = $this->c->users->load($this->zapped_by)) instanceof User
|
||||
) {
|
||||
$user = $this->c->users->guest([
|
||||
'username' => '{User #' . $this->zapped_by .'}',
|
||||
]);
|
||||
}
|
||||
|
||||
$user = $this->c->users->load($this->zapped_by);
|
||||
|
||||
if (
|
||||
! $user instanceof User
|
||||
|| $user->isGuest
|
||||
) {
|
||||
$user = $this->c->users->create();
|
||||
|
||||
$user->__id = $this->zapped_by;
|
||||
$user->__username = '{User #' . $this->zapped_by .'}';
|
||||
if (! $user instanceof User) {
|
||||
throw new RuntimeException('No marker data');
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
|
|
@ -130,13 +130,13 @@ class Delete extends Action
|
|||
':users' => $uidsToGuest,
|
||||
];
|
||||
$query = 'UPDATE ::topics
|
||||
SET poster_id=1
|
||||
SET poster_id=0
|
||||
WHERE poster_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::topics
|
||||
SET last_poster_id=1
|
||||
SET last_poster_id=0
|
||||
WHERE last_poster_id IN (?ai:users)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
|
|
@ -28,12 +28,12 @@ class Current extends Action
|
|||
|
||||
if (! $user->isGuest) {
|
||||
if (! $cookie->verifyUser($user)) {
|
||||
$user = $this->load(1, $ip);
|
||||
$user = $this->load(0, $ip);
|
||||
} elseif ($user->ip_check_type > 0) {
|
||||
$hexIp = \bin2hex(\inet_pton($ip));
|
||||
|
||||
if (false === \strpos("|{$user->login_ip_cache}|", "|{$hexIp}|")) {
|
||||
$user = $this->load(1, $ip);
|
||||
$user = $this->load(0, $ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ class Current extends Action
|
|||
{
|
||||
$data = null;
|
||||
|
||||
if ($id > 1) {
|
||||
if ($id > 0) {
|
||||
$vars = [
|
||||
':id' => $id,
|
||||
];
|
||||
|
@ -88,20 +88,16 @@ class Current extends Action
|
|||
$vars = [
|
||||
':ip' => $ip,
|
||||
];
|
||||
$query = 'SELECT u.*, g.*, o.logged, o.last_post, o.last_search
|
||||
FROM ::users AS u
|
||||
INNER JOIN ::groups AS g ON u.group_id=g.g_id
|
||||
LEFT JOIN ::online AS o ON (o.user_id=1 AND o.ident=?s:ip)
|
||||
WHERE u.id=1';
|
||||
$query = 'SELECT o.logged, o.last_post, o.last_search
|
||||
FROM ::online AS o
|
||||
WHERE o.user_id=0 AND o.ident=?s:ip';
|
||||
|
||||
$data = $this->c->DB->query($query, $vars)->fetch();
|
||||
|
||||
if (empty($data['id'])) {
|
||||
throw new RuntimeException('Unable to fetch guest information. Your database must contain both a guest user and a guest user group');
|
||||
}
|
||||
return $this->manager->guest($data ?: []);
|
||||
} else {
|
||||
return $this->manager->create($data);
|
||||
}
|
||||
|
||||
return $this->manager->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ class Filter extends Action
|
|||
{
|
||||
$fields = $this->c->dbMap->users;
|
||||
$orderBy = [];
|
||||
$where = ['u.id>1'];
|
||||
$where = [];
|
||||
|
||||
foreach ($order as $field => $dir) {
|
||||
if (! isset($fields[$field])) {
|
||||
|
@ -98,11 +98,17 @@ class Filter extends Action
|
|||
}
|
||||
}
|
||||
|
||||
$where = \implode(' AND ', $where);
|
||||
$query = "SELECT u.id
|
||||
FROM ::users AS u
|
||||
WHERE {$where}
|
||||
ORDER BY {$orderBy}";
|
||||
if (empty($where)) {
|
||||
$query = "SELECT u.id
|
||||
FROM ::users AS u
|
||||
ORDER BY {$orderBy}";
|
||||
} else {
|
||||
$where = \implode(' AND ', $where);
|
||||
$query = "SELECT u.id
|
||||
FROM ::users AS u
|
||||
WHERE {$where}
|
||||
ORDER BY {$orderBy}";
|
||||
}
|
||||
|
||||
return $this->c->DB->query($query, $vars)->fetchAll(PDO::FETCH_COLUMN);
|
||||
}
|
||||
|
|
|
@ -21,24 +21,25 @@ class Save extends Action
|
|||
*/
|
||||
public function update(User $user): User
|
||||
{
|
||||
if ($user->id < 1) {
|
||||
throw new RuntimeException('The model does not have ID');
|
||||
if (
|
||||
(! $user->isGuest && $user->id < 1)
|
||||
|| ($user->isGuest && 0 !== $user->id)
|
||||
) {
|
||||
throw new RuntimeException('Bad ID');
|
||||
}
|
||||
|
||||
$modified = $user->getModified();
|
||||
|
||||
if (empty($modified)) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
$values = $user->getAttrs();
|
||||
|
||||
if (
|
||||
$user->isGuest
|
||||
&& ! $user->isUnverified
|
||||
) {
|
||||
if ($user->isGuest) {
|
||||
$fileds = $this->c->dbMap->online;
|
||||
$table = 'online';
|
||||
$where = 'user_id=1 AND ident=?s';
|
||||
$where = 'user_id=0 AND ident=?s';
|
||||
} else {
|
||||
$fileds = $this->c->dbMap->users;
|
||||
$table = 'users';
|
||||
|
@ -113,6 +114,8 @@ class Save extends Action
|
|||
{
|
||||
if (null !== $user->id) {
|
||||
throw new RuntimeException('The model has ID');
|
||||
} elseif ($user->isGuest) {
|
||||
throw new RuntimeException('Unexpected guest');
|
||||
}
|
||||
|
||||
// вычисление username_normal для нового пользователя
|
||||
|
|
|
@ -35,10 +35,10 @@ class UpdateCountPosts extends Action
|
|||
}
|
||||
}
|
||||
// сообщения гостя не считаем
|
||||
unset($ids[1]);
|
||||
unset($ids[0]); // ????
|
||||
|
||||
if (empty($ids)) {
|
||||
$where = 'u.id != 1';
|
||||
$where = 'u.id > 0';
|
||||
$vars = [];
|
||||
} else {
|
||||
$where = 'u.id IN (?ai:ids)';
|
||||
|
|
|
@ -35,10 +35,10 @@ class UpdateCountTopics extends Action
|
|||
}
|
||||
}
|
||||
// темы гостя не считаем
|
||||
unset($ids[1]);
|
||||
unset($ids[0]); // ????
|
||||
|
||||
if (empty($ids)) {
|
||||
$where = 'u.id != 1';
|
||||
$where = 'u.id > 0';
|
||||
$vars = [];
|
||||
} else {
|
||||
$where = 'u.id IN (?ai:ids)';
|
||||
|
|
|
@ -47,7 +47,7 @@ class User extends DataModel
|
|||
*/
|
||||
protected function getisUnverified(): bool
|
||||
{
|
||||
return $this->group_id === FORK_GROUP_UNVERIFIED;
|
||||
return FORK_GROUP_UNVERIFIED === $this->group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,9 +55,9 @@ class User extends DataModel
|
|||
*/
|
||||
protected function getisGuest(): bool
|
||||
{
|
||||
return $this->group_id === FORK_GROUP_GUEST
|
||||
|| $this->id < 2
|
||||
|| null === $this->group_id;
|
||||
return FORK_GROUP_GUEST === $this->group_id
|
||||
|| null === $this->group_id
|
||||
|| $this->id < 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,7 @@ class User extends DataModel
|
|||
*/
|
||||
protected function getisAdmin(): bool
|
||||
{
|
||||
return $this->group_id === FORK_GROUP_ADMIN;
|
||||
return FORK_GROUP_ADMIN === $this->group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,8 +73,7 @@ class User extends DataModel
|
|||
*/
|
||||
protected function getisAdmMod(): bool
|
||||
{
|
||||
return $this->group_id === FORK_GROUP_ADMIN
|
||||
|| 1 == $this->g_moderator;
|
||||
return $this->isAdmin || 1 == $this->g_moderator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,7 +90,7 @@ class User extends DataModel
|
|||
*/
|
||||
public function isModerator(Model $model): bool
|
||||
{
|
||||
if (1 != $this->g_moderator) {
|
||||
if (1 !== $this->g_moderator) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,12 @@ namespace ForkBB\Models\User;
|
|||
|
||||
use ForkBB\Models\Manager;
|
||||
use ForkBB\Models\User\User;
|
||||
use RuntimeException;
|
||||
|
||||
class Users extends Manager
|
||||
{
|
||||
const CACHE_NAME = 'guest';
|
||||
|
||||
/**
|
||||
* Ключ модели для контейнера
|
||||
* @var string
|
||||
|
@ -129,4 +132,43 @@ class Users extends Manager
|
|||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создает гостя
|
||||
*/
|
||||
public function guest(array $attrs = []): User
|
||||
{
|
||||
$cache = $this->c->Cache->get(self::CACHE_NAME);
|
||||
|
||||
if (! \is_array($cache)) {
|
||||
$cache = $this->c->groups->get(FORK_GROUP_GUEST)->getAttrs();
|
||||
|
||||
if (true !== $this->c->Cache->set(self::CACHE_NAME, $cache)) {
|
||||
throw new RuntimeException('Unable to write value to cache - ' . self::CACHE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->create(
|
||||
[
|
||||
'id' => 0,
|
||||
'group_id' => FORK_GROUP_GUEST,
|
||||
'time_format' => 0,
|
||||
'date_format' => 0,
|
||||
]
|
||||
+ $attrs
|
||||
+ $cache
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Сбрасывает кеш гостя
|
||||
*/
|
||||
public function resetGuest(): Users
|
||||
{
|
||||
if (true !== $this->c->Cache->delete(self::CACHE_NAME)) {
|
||||
throw new RuntimeException('Unable to remove key from cache - ' . self::CACHE_NAME);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ if (
|
|||
}
|
||||
$c->PUBLIC_URL = $c->BASE_URL . $forkPublicPrefix;
|
||||
|
||||
$c->FORK_REVISION = 42;
|
||||
$c->FORK_REVISION = 43;
|
||||
$c->START = $forkStart;
|
||||
$c->DIR_APP = __DIR__;
|
||||
$c->DIR_PUBLIC = \realpath(__DIR__ . '/../public');
|
||||
|
|
|
@ -64,14 +64,10 @@ return [
|
|||
'class' => \ForkBB\Core\Secury::class,
|
||||
'hmac' => '%HMAC%',
|
||||
],
|
||||
'FileCache' => [
|
||||
'Cache' => [
|
||||
'class' => \ForkBB\Core\Cache\FileCache::class,
|
||||
'cache_dir' => '%DIR_CACHE%',
|
||||
],
|
||||
'Cache' => [
|
||||
'class' => \ForkBB\Core\Cache::class,
|
||||
'provider' => '@FileCache',
|
||||
],
|
||||
'Validator' => \ForkBB\Core\Validator::class,
|
||||
'View' => [
|
||||
'class' => \ForkBB\Core\View::class,
|
||||
|
|
|
@ -223,9 +223,9 @@ return [
|
|||
'Forums/save' => \ForkBB\Models\Forum\Save::class,
|
||||
'Forums/updateUsername' => \ForkBB\Models\Forum\UpdateUsername::class,
|
||||
|
||||
'Group/delete' => \ForkBB\Models\Group\Delete::class,
|
||||
'Group/perm' => \ForkBB\Models\Group\Perm::class,
|
||||
'Group/save' => \ForkBB\Models\Group\Save::class,
|
||||
'Groups/delete' => \ForkBB\Models\Group\Delete::class,
|
||||
'Groups/perm' => \ForkBB\Models\Group\Perm::class,
|
||||
'Groups/save' => \ForkBB\Models\Group\Save::class,
|
||||
|
||||
'Online/info' => \ForkBB\Models\Online\Info::class,
|
||||
'Online/updateUsername' => \ForkBB\Models\Online\UpdateUsername::class,
|
||||
|
|
Loading…
Add table
Reference in a new issue