2018-03-24
This commit is contained in:
parent
e8ed06f7e0
commit
c7d666fa61
4 changed files with 125 additions and 20 deletions
|
@ -39,14 +39,10 @@ class Profile extends Page
|
|||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
|
||||
$myProf = $curUser->id === $this->user->id;
|
||||
$isAdmin = $this->user->isAdmin && ($myProf || ! $curUser->isAdmin);
|
||||
$isModer = $this->user->isAdmMod && ($myProf || ! $curUser->isAdmMod);
|
||||
$canEditProf = $myProf || $isAdmin || ($isModer && '1' == $this->user->g_mod_edit_users);
|
||||
$canEditConf = $myProf || $isAdmin || ($isModer && '1' == $this->user->g_mod_edit_users); // ????
|
||||
$rules = $this->c->ProfileRules->setUser($curUser);
|
||||
|
||||
if ($isEdit) {
|
||||
if (! $canEditProf) {
|
||||
if (! $rules->editProfile) {
|
||||
return $this->c->Message->message('Bad request');
|
||||
}
|
||||
|
||||
|
@ -55,6 +51,10 @@ class Profile extends Page
|
|||
|
||||
$this->c->Lang->load('profile');
|
||||
|
||||
if ($isEdit && 'POST' === $method) {
|
||||
|
||||
}
|
||||
|
||||
$clSuffix = $isEdit ? '-edit' : '';
|
||||
|
||||
if ($isEdit) {
|
||||
|
@ -82,7 +82,7 @@ class Profile extends Page
|
|||
'class' => 'usertitle',
|
||||
'type' => 'wrap',
|
||||
];
|
||||
if ($isEdit && ($isAdmin || $isModer && '1' == $this->user->g_mod_rename_users)) {
|
||||
if ($isEdit && $rules->rename) {
|
||||
$fieldset['username'] = [
|
||||
'id' => 'username',
|
||||
'type' => 'text',
|
||||
|
@ -101,7 +101,7 @@ class Profile extends Page
|
|||
'value' => $curUser->username,
|
||||
];
|
||||
}
|
||||
if ($isEdit && ($isAdmin || $isModer || '1' == $this->user->g_set_title)) {
|
||||
if ($isEdit && $rules->setTitle) {
|
||||
$fieldset['title'] = [
|
||||
'id' => 'title',
|
||||
'type' => 'text',
|
||||
|
@ -247,7 +247,7 @@ class Profile extends Page
|
|||
|
||||
// контактная информация
|
||||
$fieldset = [];
|
||||
if ($myProf || $this->user->isAdmMod) {
|
||||
if ($rules->openEmail) {
|
||||
$fieldset['open-email'] = [
|
||||
'id' => 'open-email',
|
||||
'class' => 'pline',
|
||||
|
@ -257,11 +257,7 @@ class Profile extends Page
|
|||
'href' => 'mailto:' . $curUser->email,
|
||||
];
|
||||
}
|
||||
if (! $myProf
|
||||
&& (($this->user->isAdmMod && 1 === $curUser->email_setting)
|
||||
|| (! $this->user->isGuest && '1' == $this->user->g_send_email)
|
||||
)
|
||||
) {
|
||||
if ($rules->email) {
|
||||
if (0 === $curUser->email_setting) {
|
||||
$fieldset['email'] = [
|
||||
'id' => 'email',
|
||||
|
@ -371,7 +367,7 @@ class Profile extends Page
|
|||
'title' => 'IP',
|
||||
];
|
||||
}
|
||||
if ($myProf || $this->user->isAdmMod) { // ????
|
||||
if ($rules->lastvisit) {
|
||||
$fieldset['lastvisit'] = [
|
||||
'id' => 'lastvisit',
|
||||
'class' => 'pline',
|
||||
|
@ -446,7 +442,7 @@ class Profile extends Page
|
|||
);
|
||||
}
|
||||
|
||||
$this->fIndex = $myProf ? 'profile' : 'userlist';
|
||||
$this->fIndex = $rules->my ? 'profile' : 'userlist';
|
||||
$this->nameTpl = 'profile';
|
||||
$this->onlinePos = 'profile-' . $curUser->id; // ????
|
||||
$this->title = \ForkBB\__('%s\'s profile', $curUser->username);
|
||||
|
@ -454,19 +450,19 @@ class Profile extends Page
|
|||
$this->curUser = $curUser;
|
||||
|
||||
$btns = [];
|
||||
if (! $myProf && ($isAdmin || ($isModer && '1' == $this->user->g_mod_ban_users))) {
|
||||
if ($rules->banUser) {
|
||||
$btns['ban-user'] = [
|
||||
$this->c->Router->link('', ['id' => $curUser->id]),
|
||||
\ForkBB\__('Ban user'),
|
||||
];
|
||||
}
|
||||
if (! $myProf && ($isAdmin || $isModer)) { // ????
|
||||
if ($rules->deleteUser) {
|
||||
$btns['delete-user'] = [
|
||||
$this->c->Router->link('', ['id' => $curUser->id]),
|
||||
\ForkBB\__('Delete user'),
|
||||
];
|
||||
}
|
||||
if (!$isEdit && $canEditProf) {
|
||||
if (! $isEdit && $rules->editProfile) {
|
||||
$btns['edit-profile'] = [
|
||||
$this->c->Router->link('EditUserProfile', ['id' => $curUser->id]),
|
||||
\ForkBB\__('Edit '),
|
||||
|
@ -478,7 +474,7 @@ class Profile extends Page
|
|||
\ForkBB\__('View '),
|
||||
];
|
||||
}
|
||||
if ($canEditConf) {
|
||||
if ($rules->editConfig) {
|
||||
$btns['edit-settings'] = [
|
||||
$this->c->Router->link('EditBoardConfig', ['id' => $curUser->id]),
|
||||
\ForkBB\__('Configure '),
|
||||
|
|
32
app/Models/Rules.php
Normal file
32
app/Models/Rules.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace ForkBB\Models;
|
||||
|
||||
use ForkBB\Core\Container;
|
||||
use ForkBB\Models\Model;
|
||||
use RuntimeException;
|
||||
|
||||
class Rules extends Model
|
||||
{
|
||||
/**
|
||||
* Флаг готовности
|
||||
* @var bool
|
||||
*/
|
||||
protected $ready = false;
|
||||
|
||||
/**
|
||||
* Возвращает значение свойства
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
if (true === $this->ready) {
|
||||
return parent::__get($name);
|
||||
} else {
|
||||
throw new RuntimeException('The model of rules isn\'t ready');
|
||||
}
|
||||
}
|
||||
}
|
75
app/Models/Rules/Profile.php
Normal file
75
app/Models/Rules/Profile.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace ForkBB\Models\Rules;
|
||||
|
||||
use ForkBB\Models\Model;
|
||||
use ForkBB\Models\Rules;
|
||||
use ForkBB\Models\User\Model as User;
|
||||
use RuntimeException;
|
||||
|
||||
class Profile extends Rules
|
||||
{
|
||||
protected $curUser;
|
||||
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Задает профиль пользователя для применения правил
|
||||
*
|
||||
* @param User $curUser
|
||||
*
|
||||
* @return ProfileRules
|
||||
*/
|
||||
public function setUser(User $curUser)
|
||||
{
|
||||
$this->ready = true;
|
||||
|
||||
$this->user = $this->c->user;
|
||||
$this->curUser = $curUser;
|
||||
$this->my = $curUser->id === $this->user->id;
|
||||
$this->admin = $this->user->isAdmin && ($this->my || ! $curUser->isAdmin);
|
||||
$this->moderator = $this->user->isAdmMod && ($this->my || ! $curUser->isAdmMod);
|
||||
$this->editProfile = $this->my || $this->admin || ($this->moderator && '1' == $this->user->g_mod_edit_users);
|
||||
$this->editConfig = $this->my || $this->admin || ($this->moderator && '1' == $this->user->g_mod_edit_users); // ????
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getrename()
|
||||
{
|
||||
return $this->admin || ($this->moderator && '1' == $this->user->g_mod_rename_users);
|
||||
}
|
||||
|
||||
public function getsetTitle()
|
||||
{
|
||||
return $this->admin || $this->moderator || '1' == $this->user->g_set_title;
|
||||
}
|
||||
|
||||
public function getopenEmail()
|
||||
{
|
||||
return $this->my || $this->user->isAdmMod;
|
||||
}
|
||||
|
||||
public function getemail() // ?????
|
||||
{
|
||||
return ! $this->my
|
||||
&& (($this->user->isAdmMod && 1 === $this->curUser->email_setting)
|
||||
|| (! $this->user->isGuest && '1' == $this->user->g_send_email)
|
||||
);
|
||||
}
|
||||
|
||||
public function getlastvisit()
|
||||
{
|
||||
return $this->my || $this->user->isAdmMod;
|
||||
}
|
||||
|
||||
public function getbanUser()
|
||||
{
|
||||
return ! $this->my && ($this->admin || ($this->moderator && '1' == $this->user->g_mod_ban_users));
|
||||
}
|
||||
|
||||
public function getdeleteUser()
|
||||
{
|
||||
return ! $this->my && ($this->admin || $this->moderator); // ????
|
||||
}
|
||||
}
|
|
@ -227,5 +227,7 @@ return [
|
|||
'SearchModelTruncateIndex' => \ForkBB\Models\Search\TruncateIndex::class,
|
||||
'SearchModelPrepare' => \ForkBB\Models\Search\Prepare::class,
|
||||
'SearchModelExecute' => \ForkBB\Models\Search\Execute::class,
|
||||
|
||||
'ProfileRules' => \ForkBB\Models\Rules\Profile::class,
|
||||
],
|
||||
];
|
||||
|
|
Loading…
Add table
Reference in a new issue