mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-20 09:30:49 +08:00
change user class migrate to admin
This commit is contained in:
@@ -67,6 +67,9 @@ class UserProfile extends ViewRecord
|
||||
$actions[] = $this->buildResetPasswordAction();
|
||||
$actions[] = $this->buildEnableDisableAction();
|
||||
$actions[] = $this->buildEnableDisableDownloadPrivilegesAction();
|
||||
if (user_can('user-change-class')) {
|
||||
$actions[] = $this->buildChangeClassAction();
|
||||
}
|
||||
if (user_can('user-delete')) {
|
||||
$actions[] = $this->buildDeleteAction();
|
||||
}
|
||||
@@ -355,4 +358,32 @@ class UserProfile extends ViewRecord
|
||||
->where('expired_at', '>', Carbon::now())
|
||||
->count();
|
||||
}
|
||||
|
||||
private function buildChangeClassAction(): Actions\Action
|
||||
{
|
||||
return Actions\Action::make('change_class')
|
||||
->label(__('admin.resources.user.actions.change_class_btn'))
|
||||
->form([
|
||||
Forms\Components\Select::make('class')
|
||||
->options(User::listClass())
|
||||
->default($this->record->class)
|
||||
->label(__('user.labels.class'))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\TextInput::make('reason')
|
||||
->label(__('admin.resources.user.actions.enable_disable_reason'))
|
||||
->placeholder(__('admin.resources.user.actions.enable_disable_reason_placeholder'))
|
||||
,
|
||||
])
|
||||
->action(function ($data) {
|
||||
$userRep = $this->getRep();
|
||||
try {
|
||||
$userRep->changeClass(Auth::user(), $this->record, $data['class'], $data['reason']);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,6 +466,39 @@ class UserRepository extends BaseRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public function changeClass($operator, $targetUser, $newClass, $reason = ''): bool
|
||||
{
|
||||
user_can('user-change-class', true);
|
||||
$operator = $this->getUser($operator);
|
||||
$targetUser = $this->getUser($targetUser);
|
||||
if ($targetUser->class == $newClass) {
|
||||
return true;
|
||||
}
|
||||
$locale = $targetUser->locale;
|
||||
$subject = nexus_trans('user.edit_notifications.change_class.subject', [], $locale);
|
||||
$body = nexus_trans('user.edit_notifications.change_class.body', [
|
||||
'action' => nexus_trans( 'user.edit_notifications.change_class.' . ($newClass > $targetUser->class ? 'promote' : 'demote')),
|
||||
'new_class' => User::getClassText($newClass),
|
||||
'operator' => $operator->username ?? '',
|
||||
'reason' => $reason,
|
||||
], $locale);
|
||||
$message = [
|
||||
'sender' => 0,
|
||||
'receiver' => $targetUser->id,
|
||||
'subject' => $subject,
|
||||
'msg' => $body,
|
||||
'added' => Carbon::now(),
|
||||
];
|
||||
|
||||
NexusDB::transaction(function () use ($targetUser, $newClass, $message) {
|
||||
$modComment = date('Y-m-d') . " - " . $message['msg'];
|
||||
$targetUser->updateWithModComment(['class' => $newClass], $modComment);
|
||||
Message::add($message);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function addMeta($user, array $metaData, array $keyExistsUpdates = [], $notify = true)
|
||||
{
|
||||
$user = $this->getUser($user);
|
||||
|
||||
+13
-6
@@ -1730,13 +1730,15 @@ function check_code ($imagehash, $imagestring, $where = 'signup.php',$maxattempt
|
||||
return true;
|
||||
}
|
||||
$query = sprintf("SELECT * FROM regimages WHERE imagehash='%s' AND imagestring='%s'",
|
||||
mysql_real_escape_string($imagehash),
|
||||
mysql_real_escape_string($imagestring));
|
||||
mysql_real_escape_string((string)$imagehash),
|
||||
mysql_real_escape_string((string)$imagestring)
|
||||
);
|
||||
$sql = sql_query($query);
|
||||
$imgcheck = mysql_fetch_array($sql);
|
||||
if(!$imgcheck['dateline']) {
|
||||
$delete = sprintf("DELETE FROM regimages WHERE imagehash='%s'",
|
||||
mysql_real_escape_string($imagehash));
|
||||
mysql_real_escape_string((string)$imagehash)
|
||||
);
|
||||
sql_query($delete);
|
||||
if (!$maxattemptlog)
|
||||
stderr('Error',$lang_functions['std_invalid_image_code']."<a href=\"".htmlspecialchars($where)."\">".$lang_functions['std_here_to_request_new'], false);
|
||||
@@ -1744,7 +1746,8 @@ function check_code ($imagehash, $imagestring, $where = 'signup.php',$maxattempt
|
||||
failedlogins($lang_functions['std_invalid_image_code']."<a href=\"".htmlspecialchars($where)."\">".$lang_functions['std_here_to_request_new'],true,$head);
|
||||
}else{
|
||||
$delete = sprintf("DELETE FROM regimages WHERE imagehash='%s'",
|
||||
mysql_real_escape_string($imagehash));
|
||||
mysql_real_escape_string((string)$imagehash)
|
||||
);
|
||||
sql_query($delete);
|
||||
return true;
|
||||
}
|
||||
@@ -4271,9 +4274,13 @@ function getSmileIt($formname, $taname, $smilyNumber) {
|
||||
return "<a href=\"javascript: SmileIT('[em$smilyNumber]','".$formname."','".$taname."')\" onmouseover=\"domTT_activate(this, event, 'content', '".htmlspecialchars("<table><tr><td><img src=\'pic/smilies/$smilyNumber.gif\' alt=\'\' /></td></tr></table>")."', 'trail', false, 'delay', 0,'lifetime',10000,'styleClass','smilies','maxWidth', 400);\"><img style=\"max-width: 25px;\" src=\"pic/smilies/$smilyNumber.gif\" alt=\"\" /></a>";
|
||||
}
|
||||
|
||||
function classlist($selectname,$maxclass, $selected, $minClass = 0, $includeNoClass = false){
|
||||
function classlist($selectname,$maxclass, $selected, $minClass = 0, $includeNoClass = false, $disabled = false){
|
||||
global $lang_functions;
|
||||
$list = "<select name=\"".$selectname."\">";
|
||||
$disabledText = '';
|
||||
if ($disabled) {
|
||||
$disabledText = ' disabled = "disabled"';
|
||||
}
|
||||
$list = "<select name=\"".$selectname."\"$disabledText>";
|
||||
if ($includeNoClass) {
|
||||
$list .= sprintf('<option value="%s">%s</option>', \App\Models\Setting::PERMISSION_NO_CLASS, $lang_functions['select_an_user_class']);
|
||||
}
|
||||
|
||||
+12
-11
@@ -206,17 +206,18 @@ if ($action == "edituser")
|
||||
if ($curclass >= get_user_class())
|
||||
puke();
|
||||
|
||||
if (user_can('user-change-class') && $curclass != $class)
|
||||
{
|
||||
$what = ($class > $curclass ? $lang_modtask_target[get_user_lang($userid)]['msg_promoted'] : $lang_modtask_target[get_user_lang($userid)]['msg_demoted']);
|
||||
$subject = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_class_change']);
|
||||
$msg = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_you_have_been'].$what.$lang_modtask_target[get_user_lang($userid)]['msg_to'] . get_user_class_name($class) .$lang_modtask_target[get_user_lang($userid)]['msg_by'].$CURUSER['username']);
|
||||
$added = sqlesc(date("Y-m-d H:i:s"));
|
||||
sql_query("INSERT INTO messages (sender, receiver, subject, msg, added) VALUES(0, $userid, $subject, $msg, $added)") or sqlerr(__FILE__, __LINE__);
|
||||
$updateset[] = "class = $class";
|
||||
$what = ($class > $curclass ? "Promoted" : "Demoted");
|
||||
$modcomment = date("Y-m-d") . " - $what to '" . get_user_class_name($class) . "' by {$CURUSER['username']}.\n". $modcomment;
|
||||
}
|
||||
//migrate to management
|
||||
// if (user_can('user-change-class') && $curclass != $class)
|
||||
// {
|
||||
// $what = ($class > $curclass ? $lang_modtask_target[get_user_lang($userid)]['msg_promoted'] : $lang_modtask_target[get_user_lang($userid)]['msg_demoted']);
|
||||
// $subject = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_class_change']);
|
||||
// $msg = sqlesc($lang_modtask_target[get_user_lang($userid)]['msg_you_have_been'].$what.$lang_modtask_target[get_user_lang($userid)]['msg_to'] . get_user_class_name($class) .$lang_modtask_target[get_user_lang($userid)]['msg_by'].$CURUSER['username']);
|
||||
// $added = sqlesc(date("Y-m-d H:i:s"));
|
||||
// sql_query("INSERT INTO messages (sender, receiver, subject, msg, added) VALUES(0, $userid, $subject, $msg, $added)") or sqlerr(__FILE__, __LINE__);
|
||||
// $updateset[] = "class = $class";
|
||||
// $what = ($class > $curclass ? "Promoted" : "Demoted");
|
||||
// $modcomment = date("Y-m-d") . " - $what to '" . get_user_class_name($class) . "' by {$CURUSER['username']}.\n". $modcomment;
|
||||
// }
|
||||
if ($class == UC_VIP)
|
||||
{
|
||||
$updateset[] = "vip_added = ".sqlesc($vip_added);
|
||||
|
||||
@@ -474,8 +474,8 @@ if (user_can('prfmanage') && $user["class"] < get_user_class())
|
||||
}
|
||||
if (user_can('user-change-class')) {
|
||||
$maxclass = get_user_class() - 1;
|
||||
$classselect=classlist('class', $maxclass, $user["class"]);
|
||||
tr($lang_userdetails['row_class'], $classselect, 1);
|
||||
$classselect=classlist('class', $maxclass, $user["class"], 0, false, true);
|
||||
tr($lang_userdetails['row_class'], $classselect . $migratedHelp, 1);
|
||||
}
|
||||
tr($lang_userdetails['row_vip_by_bonus'], "<input type=\"radio\" name=\"vip_added\" value=\"yes\"" .($user["vip_added"] == "yes" ? " checked=\"checked\"" : "")." />".$lang_userdetails['radio_yes']." <input type=\"radio\" name=\"vip_added\" value=\"no\"" .($user["vip_added"] == "no" ? " checked=\"checked\"" : "")." />".$lang_userdetails['radio_no']."<br />".$lang_userdetails['text_vip_by_bonus_note'], 1);
|
||||
tr($lang_userdetails['row_vip_until'], "<input type=\"text\" name=\"vip_until\" value=\"".htmlspecialchars($user["vip_until"])."\" /> ".$lang_userdetails['text_vip_until_note'], 1);
|
||||
|
||||
@@ -79,6 +79,7 @@ return [
|
||||
'confirm_bulk' => 'Bulk confirm',
|
||||
'change_bonus_etc_duration_label' => 'Duration',
|
||||
'change_bonus_etc_duration_help' => 'Required when adding temporary invitation, in days',
|
||||
'change_class_btn' => 'Change class',
|
||||
]
|
||||
],
|
||||
'exam_user' => [
|
||||
|
||||
@@ -16,6 +16,7 @@ return [
|
||||
'invites' => 'Invites',
|
||||
'attendance_card' => 'Attend card',
|
||||
'props' => 'Props',
|
||||
'class' => 'Class',
|
||||
],
|
||||
'class_names' => [
|
||||
\App\Models\User::CLASS_VIP => 'Vip',
|
||||
@@ -39,6 +40,14 @@ return [
|
||||
'body' => ':operator Grant you :name, Validity period: :duration.',
|
||||
],
|
||||
'metas' => [
|
||||
'already_valid_forever' => ':meta_key_text 已經永久有效',
|
||||
'already_valid_forever' => ':meta_key_text already valid forever',
|
||||
],
|
||||
'edit_notifications' => [
|
||||
'change_class' => [
|
||||
'promote' => 'Promote',
|
||||
'demote' => 'Demote',
|
||||
'subject' => 'Class changed',
|
||||
'body' => 'You had been :action to :new_class, administrator: :operator, reason: :reason.',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -77,6 +77,7 @@ return [
|
||||
'confirm_bulk' => '批量确认',
|
||||
'change_bonus_etc_duration_label' => '有效期',
|
||||
'change_bonus_etc_duration_help' => '增加临时邀请时必须,单位:天',
|
||||
'change_class_btn' => '修改等级',
|
||||
]
|
||||
],
|
||||
'exam_user' => [
|
||||
|
||||
@@ -16,6 +16,7 @@ return [
|
||||
'invites' => '邀请',
|
||||
'attendance_card' => '补签卡',
|
||||
'props' => '道具',
|
||||
'class' => '等级',
|
||||
],
|
||||
'class_names' => [
|
||||
\App\Models\User::CLASS_VIP => '贵宾',
|
||||
@@ -41,4 +42,12 @@ return [
|
||||
'metas' => [
|
||||
'already_valid_forever' => ':meta_key_text already valid forever',
|
||||
],
|
||||
'edit_notifications' => [
|
||||
'change_class' => [
|
||||
'promote' => '提升',
|
||||
'demote' => '降级',
|
||||
'subject' => '等级变化',
|
||||
'body' => '你被:action为:new_class,管理员::operator, 原因::reason。',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -79,6 +79,7 @@ return [
|
||||
'confirm_bulk' => '批量確認',
|
||||
'change_bonus_etc_duration_label' => '有效期',
|
||||
'change_bonus_etc_duration_help' => '增加臨時邀請時必須,單位:天',
|
||||
'change_class_btn' => '修改等級',
|
||||
]
|
||||
],
|
||||
'exam_user' => [
|
||||
|
||||
@@ -16,6 +16,7 @@ return [
|
||||
'invites' => '邀請',
|
||||
'attendance_card' => '補簽卡',
|
||||
'props' => '道具',
|
||||
'class' => '等級',
|
||||
],
|
||||
'class_names' => [
|
||||
\App\Models\User::CLASS_VIP => '貴賓',
|
||||
@@ -41,4 +42,12 @@ return [
|
||||
'metas' => [
|
||||
'already_valid_forever' => ':meta_key_text 已經永久有效',
|
||||
],
|
||||
'edit_notifications' => [
|
||||
'change_class' => [
|
||||
'promote' => '提升',
|
||||
'demote' => '降級',
|
||||
'subject' => '等級變化',
|
||||
'body' => '你被:action為:new_class,管理員::operator, 原因::reason。',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user