mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
user modify migrate
This commit is contained in:
@@ -77,7 +77,11 @@ class NexusWebUserProvider implements UserProvider
|
||||
public function validateCredentials(Authenticatable $user, array $credentials)
|
||||
{
|
||||
if ($credentials["c_secure_login"] == base64("yeah")) {
|
||||
if ($credentials["c_secure_pass"] != md5($user->passhash . getip())) {
|
||||
/**
|
||||
* Not IP related
|
||||
* @since 1.8.0
|
||||
*/
|
||||
if ($credentials["c_secure_pass"] != md5($user->passhash)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -35,12 +35,14 @@ class PluginResource extends Resource
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('package_name')->label(__('label.plugin.package_name')),
|
||||
Forms\Components\TextInput::make('remote_url')->label(__('label.plugin.remote_url')),
|
||||
Forms\Components\TextInput::make('package_name')->label(__('plugin.labels.package_name')),
|
||||
Forms\Components\TextInput::make('remote_url')->label(__('plugin.labels.remote_url')),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,16 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
self::DONATE_NO => ['text' => 'No'],
|
||||
];
|
||||
|
||||
const GENDER_FEMALE = 'Female';
|
||||
const GENDER_MALE = 'Male';
|
||||
const GENDER_UNKNOWN = 'N/A';
|
||||
|
||||
public static array $genders = [
|
||||
self::GENDER_MALE => 'Male',
|
||||
self::GENDER_FEMALE => 'Female',
|
||||
self::GENDER_UNKNOWN => 'N/A',
|
||||
];
|
||||
|
||||
public static array $cardTitles = [
|
||||
'uploaded_human' => '上传量',
|
||||
'downloaded_human' => '下载量',
|
||||
@@ -269,12 +279,16 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
|
||||
public function getLocaleAttribute()
|
||||
{
|
||||
$locale = Locale::getLocaleFromCookie();
|
||||
$log = "locale from cookie: $locale";
|
||||
$locale = null;
|
||||
$log = "user: " . $this->id;
|
||||
if (get_user_id() == $this->id) {
|
||||
$locale = Locale::getLocaleFromCookie();
|
||||
$log .= ", locale from cookie: $locale";
|
||||
}
|
||||
if (!$locale) {
|
||||
$lang = $this->language->site_lang_folder;
|
||||
$locale = Locale::$languageMaps[$lang] ?? 'en';
|
||||
$log .= ", [NO_DATA], lang from database: $lang, locale: $locale";
|
||||
$log .= ", [NO_DATA_FROM_COOKIE], lang from database: $lang, locale: $locale";
|
||||
}
|
||||
do_log($log);
|
||||
return $locale;
|
||||
@@ -303,6 +317,13 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
);
|
||||
}
|
||||
|
||||
protected function genderText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => nexus_trans('user.genders.' . $attributes['gender'])
|
||||
);
|
||||
}
|
||||
|
||||
public static function getMinSeedPoints($class)
|
||||
{
|
||||
$setting = Setting::get("account.{$class}_min_seed_points");
|
||||
|
||||
102
app/Policies/CodecPolicy.php
Normal file
102
app/Policies/CodecPolicy.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Codec;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class CodecPolicy extends BasePolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function viewAny(User $user)
|
||||
{
|
||||
return $this->can($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Codec $codec
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function view(User $user, Codec $codec)
|
||||
{
|
||||
return $this->can($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return $this->can($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Codec $codec
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function update(User $user, Codec $codec)
|
||||
{
|
||||
return $this->can($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Codec $codec
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function delete(User $user, Codec $codec)
|
||||
{
|
||||
return $this->can($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Codec $codec
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function restore(User $user, Codec $codec)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Models\Codec $codec
|
||||
* @return \Illuminate\Auth\Access\Response|bool
|
||||
*/
|
||||
public function forceDelete(User $user, Codec $codec)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
private function can(User $user)
|
||||
{
|
||||
if ($user->class >= User::CLASS_SYSOP) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -4,13 +4,23 @@ namespace App\Providers;
|
||||
|
||||
use App\Auth\NexusWebGuard;
|
||||
use App\Auth\NexusWebUserProvider;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\AudioCodec;
|
||||
use App\Models\Category;
|
||||
use App\Models\Codec;
|
||||
use App\Models\Icon;
|
||||
use App\Models\Media;
|
||||
use App\Models\Plugin;
|
||||
use App\Models\Processing;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\SecondIcon;
|
||||
use App\Models\Source;
|
||||
use App\Models\Standard;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use App\Policies\CodecPolicy;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -20,7 +30,20 @@ class AuthServiceProvider extends ServiceProvider
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
|
||||
SearchBox::class => CodecPolicy::class,
|
||||
Category::class => CodecPolicy::class,
|
||||
Icon::class => CodecPolicy::class,
|
||||
SecondIcon::class => CodecPolicy::class,
|
||||
|
||||
Codec::class => CodecPolicy::class,
|
||||
AudioCodec::class => CodecPolicy::class,
|
||||
Source::class => CodecPolicy::class,
|
||||
Media::class => CodecPolicy::class,
|
||||
Standard::class => CodecPolicy::class,
|
||||
Team::class => CodecPolicy::class,
|
||||
Processing::class => CodecPolicy::class,
|
||||
|
||||
Plugin::class => CodecPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -58,7 +81,11 @@ class AuthServiceProvider extends ServiceProvider
|
||||
return null;
|
||||
}
|
||||
if ($cookie["c_secure_login"] == base64("yeah")) {
|
||||
if ($cookie["c_secure_pass"] != md5($user->passhash . getip())) {
|
||||
/**
|
||||
* Not IP related
|
||||
* @since 1.8.0
|
||||
*/
|
||||
if ($cookie["c_secure_pass"] != md5($user->passhash)) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -177,6 +177,9 @@ class DashboardRepository extends BaseRepository
|
||||
|
||||
$statGender = User::query()->groupBy('gender')->selectRaw('gender, count(*) as counts')->get()->pluck('counts','gender');
|
||||
foreach ($statGender as $gender => $value) {
|
||||
if (!isset(User::$genders[$gender])) {
|
||||
$gender = User::GENDER_UNKNOWN;
|
||||
}
|
||||
$name = "gender_$gender";
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
|
||||
@@ -360,7 +360,9 @@ class HitAndRunRepository extends BaseRepository
|
||||
}
|
||||
$users = User::query()
|
||||
->with('language')
|
||||
->where('class', '<', User::CLASS_VIP)
|
||||
->where('enabled', User::ENABLED_YES)
|
||||
->where('donor', 'no')
|
||||
->find($result->pluck('uid')->toArray(), ['id', 'username', 'lang']);
|
||||
do_log("$logPrefix, Going to disable user: " . json_encode($users->toArray()));
|
||||
foreach ($users as $user) {
|
||||
|
||||
@@ -468,9 +468,22 @@ class UserRepository extends BaseRepository
|
||||
public function addMeta($user, array $metaData, array $keyExistsUpdates = [])
|
||||
{
|
||||
$user = $this->getUser($user);
|
||||
$locale = $user->locale;
|
||||
$metaKey = $metaData['meta_key'];
|
||||
$metaName = nexus_trans("label.user_meta.meta_keys.$metaKey", [], $locale);
|
||||
$allowMultiple = UserMeta::$metaKeys[$metaKey]['multiple'];
|
||||
$log = "user: {$user->id}, metaKey: $metaKey, allowMultiple: $allowMultiple";
|
||||
$log = "user: {$user->id}, locale: $locale, metaKey: $metaKey, allowMultiple: $allowMultiple";
|
||||
$message = [
|
||||
'receiver' => $user->id,
|
||||
'added' => now(),
|
||||
'subject' => nexus_trans('user.grant_props_notification.subject', ['name' => $metaName], $locale),
|
||||
];
|
||||
if (!empty($keyExistsUpdates['duration']) && $metaKey != UserMeta::META_KEY_CHANGE_USERNAME) {
|
||||
$durationText = $keyExistsUpdates['duration'] . " Days";
|
||||
} else {
|
||||
$durationText = nexus_trans('label.permanent', [], $locale);
|
||||
}
|
||||
$message['msg'] = nexus_trans('user.grant_props_notification.body', ['name' => $metaName, 'operator' => Auth::user()->username, 'duration' => $durationText], $locale);
|
||||
if ($allowMultiple) {
|
||||
//Allow multiple, just insert
|
||||
$result = $user->metas()->create($metaData);
|
||||
@@ -503,6 +516,7 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
if ($result) {
|
||||
clear_user_cache($user->id, $user->passkey);
|
||||
Message::query()->insert($message);
|
||||
}
|
||||
do_log($log);
|
||||
return $result;
|
||||
|
||||
Reference in New Issue
Block a user