get_username() support in laravel

This commit is contained in:
xiaomlove
2022-06-12 15:15:09 +08:00
parent 4fc91f52cc
commit 43156f7fc5
8 changed files with 108 additions and 24 deletions

View File

@@ -2,6 +2,9 @@
namespace App\Repositories;
use App\Models\Setting;
use App\Models\Torrent;
use App\Models\User;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Str;
@@ -17,4 +20,20 @@ class BaseRepository
return [$field, $type];
}
protected function handleAnonymous($username, User $user, User $authenticator, Torrent $torrent = null)
{
$canViewAnonymousClass = Setting::get('authority.viewanonymous');
if($user->privacy == "strong" || ($torrent && $torrent->anonymous == 'yes' && $user->id == $torrent->owner)) {
//用户强私密,或者种子作者匿名而当前项作者刚好为种子作者
if($authenticator->class >= $canViewAnonymousClass || $user->id == $authenticator->id) {
//但当前用户权限可以查看匿名者,或当前用户查看自己的数据,显示个匿名,后边加真实用户名
return sprintf('匿名(%s)', $username);
} else {
return '匿名';
}
} else {
return $username;
}
}
}