<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Admin\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Str; use ModStart\Admin\Auth\Admin; use ModStart\Admin\Auth\AdminPermission; use ModStart\Admin\Concern\HasAdminCRUD; use ModStart\Admin\Model\AdminUser; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\CRUDUtil; use ModStart\Core\Util\RandomUtil; use ModStart\Detail\Detail; use ModStart\Field\AbstractField; use ModStart\Form\Form; use ModStart\Grid\Displayer\ItemOperate; use ModStart\Grid\Grid; use ModStart\Grid\GridFilter; class AdminUserController extends Controller { use HasAdminCRUD; protected function grid() { goto EiE98; U5vtk: return $QnI0I; goto guiyj; EiE98: $QnI0I = new Grid(AdminUser::class, function (Grid $QnI0I) { $QnI0I->display('id', L('ID'))->sortable(true)->width(80); $QnI0I->text('username', L('Username'))->width(100); $QnI0I->tags('roles', L('Roles'))->hookFormatValue(function ($tzAUI, AbstractField $Q2vn5) { $Nrp0b = $Q2vn5->item(); if (AdminPermission::isFounder($Nrp0b->id)) { return array(L('Admin Founder')); } return collect($tzAUI)->pluck('name')->toArray(); }); $QnI0I->text('lastLoginTime', L('Last Login Time'))->width(150); $QnI0I->text('lastLoginIp', L('Last Login Ip'))->width(150); $QnI0I->filter(function (GridFilter $cF9SB) { $cF9SB->eq('id', L('ID')); $cF9SB->like('username', L('Username')); }); $QnI0I->hookItemOperateRendering(function (ItemOperate $wuBKV) { if (AdminPermission::isFounder($wuBKV->item()->id)) { $wuBKV->canDelete(false); } }); }); goto j8twH; j8twH: if (AdminPermission::isNotPermit('AdminUserManage')) { $QnI0I->canAdd(false)->canEdit(false)->canDelete(false); } goto mn48y; mn48y: $QnI0I->title(L('Admin User')); goto U5vtk; guiyj: } protected function form() { goto k7iNc; Cagtn: return $Pl0Cf; goto azld2; k7iNc: $Pl0Cf = new Form(AdminUser::class, function (Form $Pl0Cf) { $Pl0Cf->text('username', L('Username'))->rules('required|unique:admin_user,username,' . CRUDUtil::id()); $Pl0Cf->text('password', L('Password'))->rules($Pl0Cf->isModeAdd() ? 'required' : '')->placeholder($Pl0Cf->isModeAdd() ? '' : L('Keep Old Password If Empty'))->value($Pl0Cf->isModeAdd() ? RandomUtil::string(6) : '')->hookFormatValue(function ($tzAUI, AbstractField $Q2vn5) { return ''; }); $Nrp0b = $Pl0Cf->item(); if ($Pl0Cf->isModeEdit() && !AdminPermission::isFounder($Nrp0b->id)) { $Pl0Cf->checkbox('roles', L('Roles'))->optionModel('admin_role')->hookValueUnserialize(function ($tzAUI, AbstractField $Q2vn5) { return $tzAUI->map(function ($yGFxf) { return $yGFxf['id']; }); })->hookValueSerialize(function ($tzAUI, AbstractField $Q2vn5) { return ConvertUtil::toArray($tzAUI); }); } $Pl0Cf->display('created_at', L('Created At'))->editable(true); $Pl0Cf->hookSaving(function (Form $Pl0Cf) { if ($Pl0Cf->isModeAdd()) { goto bx0ca; qahOc: $Y0YxF['password'] = Admin::passwordEncrypt($Y0YxF['password'], $Y0YxF['passwordSalt']); goto EGpb4; bx0ca: $Y0YxF = $Pl0Cf->dataAdding(); goto yP70a; EGpb4: $Pl0Cf->dataAdding($Y0YxF); goto X6Z3w; yP70a: $Y0YxF['passwordSalt'] = Str::random(16); goto qahOc; X6Z3w: } else { if ($Pl0Cf->isModeEdit()) { goto ofeJe; kXcOw: if ($Y0YxF['password']) { $Y0YxF['passwordSalt'] = Str::random(16); $Y0YxF['password'] = Admin::passwordEncrypt($Y0YxF['password'], $Y0YxF['passwordSalt']); } else { unset($Y0YxF['password']); } goto PQRga; PQRga: $Pl0Cf->dataEditing($Y0YxF); goto OmZ0k; ofeJe: $Y0YxF = $Pl0Cf->dataEditing(); goto kXcOw; OmZ0k: } } }); $Pl0Cf->hookDeleting(function (Form $Pl0Cf) { $Pl0Cf->item()->each(function ($Nrp0b) { if (AdminPermission::isFounder($Nrp0b->id)) { BizException::throws(L('Admin Founder Delete Forbidden')); } }); }); }); goto FPGIo; FPGIo: if (AdminPermission::isNotPermit('AdminUserManage')) { $Pl0Cf->canAdd(false)->canEdit(false)->canDelete(false); } goto MxnwV; MxnwV: $Pl0Cf->title(L('Admin User')); goto Cagtn; azld2: } protected function detail() { goto Pq67q; G0Hci: $z3x5T->title(L('Admin User')); goto LPK3Q; Pq67q: $z3x5T = new Detail(AdminUser::class, function (Detail $z3x5T) { $z3x5T->display('id', L('ID')); $z3x5T->text('username', L('Username')); $z3x5T->tags('roles', L('Roles'))->hookFormatValue(function ($tzAUI, AbstractField $Q2vn5) { $Nrp0b = $Q2vn5->item(); if (AdminPermission::isFounder($Nrp0b->id)) { return array(L('Admin Founder')); } return collect($tzAUI)->pluck('name')->toArray(); }); $z3x5T->display('created_at', L('Created At')); $z3x5T->display('updated_at', L('Updated At')); }); goto G0Hci; LPK3Q: return $z3x5T; goto GQdHc; GQdHc: } }