mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
show current role at user/admin panel
This commit is contained in:
parent
1d4dca0ff3
commit
118d8cc649
@ -6,14 +6,14 @@ class CheckAdministrator
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
$user = (new CheckAuthenticated)->handle($request, $next, true);
|
||||
$result = (new CheckAuthenticated)->handle($request, $next, true);
|
||||
|
||||
if ($user instanceof \Illuminate\Http\RedirectResponse) {
|
||||
return $user;
|
||||
if ($result instanceof \Illuminate\Http\RedirectResponse) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!$user->isAdmin()) {
|
||||
return redirect('user')->with('msg', '看起来你并不是管理员哦');
|
||||
if (!$result->isAdmin()) {
|
||||
abort(403, trans('auth.check.admin'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -7,13 +7,13 @@ use View;
|
||||
use Http;
|
||||
use Cookie;
|
||||
use Session;
|
||||
use Closure;
|
||||
use App\Models\User;
|
||||
use App\Events\UserAuthenticated;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
|
||||
class CheckAuthenticated
|
||||
{
|
||||
public function handle($request, \Closure $next, $returnUser = false)
|
||||
public function handle($request, Closure $next, $returnUser = false)
|
||||
{
|
||||
if (Session::has('uid')) {
|
||||
|
||||
@ -32,29 +32,12 @@ class CheckAuthenticated
|
||||
delete_sessions();
|
||||
delete_cookies();
|
||||
|
||||
throw new PrettyPageException(trans('auth.check.banned'), 5);
|
||||
abort(403, trans('auth.check.banned'));
|
||||
}
|
||||
|
||||
// ask for filling email
|
||||
if ($user->email == "") {
|
||||
if (isset($request->email)) {
|
||||
if (filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
||||
if (User::where('email', $request->email)->get()->isEmpty()) {
|
||||
$user->setEmail($request->email);
|
||||
// refresh token
|
||||
Session::put('token', $user->getToken(true));
|
||||
Cookie::queue('token', $user->getToken(), 60);
|
||||
|
||||
return $next($request);
|
||||
} else {
|
||||
return response()->view('auth.bind', ['msg' => trans('auth.bind.registered')]);
|
||||
}
|
||||
} else {
|
||||
return response()->view('auth.bind', ['msg' => trans('auth.validation.email')]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->view('auth.bind');
|
||||
return $this->askForFillingEmail($request, $next);
|
||||
}
|
||||
|
||||
event(new UserAuthenticated($user));
|
||||
@ -67,4 +50,26 @@ class CheckAuthenticated
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
public function askForFillingEmail($request, Closure $next)
|
||||
{
|
||||
if (isset($request->email)) {
|
||||
if (filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
||||
if (User::where('email', $request->email)->get()->isEmpty()) {
|
||||
$user->setEmail($request->email);
|
||||
// refresh token
|
||||
Session::put('token', $user->getToken(true));
|
||||
Cookie::queue('token', $user->getToken(), 60);
|
||||
|
||||
return $next($request);
|
||||
} else {
|
||||
return response()->view('auth.bind', ['msg' => trans('auth.bind.registered')]);
|
||||
}
|
||||
} else {
|
||||
return response()->view('auth.bind', ['msg' => trans('auth.validation.email')]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->view('auth.bind');
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ class CheckSessionUserValid
|
||||
// remove sessions & cookies
|
||||
delete_sessions();
|
||||
delete_cookies();
|
||||
|
||||
return redirect('auth/login')->with('msg', trans('auth.check.token'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
@ -25,7 +26,7 @@ if (! function_exists('get_current_url')) {
|
||||
|
||||
if (! function_exists('avatar')) {
|
||||
|
||||
function avatar(App\Models\User $user, $size)
|
||||
function avatar(User $user, $size)
|
||||
{
|
||||
$fname = base64_encode($user->email).".png?tid=".$user->getAvatarId();
|
||||
|
||||
@ -101,10 +102,6 @@ if (! function_exists('bs_footer')) {
|
||||
echo "<script type=\"text/javascript\" src=\"$script\"></script>";
|
||||
}
|
||||
|
||||
if (Session::has('msg')) {
|
||||
echo "<script>toastr.info('".Session::pull('msg')."');</script>";
|
||||
}
|
||||
|
||||
echo '<script>'.Option::get("custom_js").'</script>';
|
||||
|
||||
$extra_contents = [];
|
||||
@ -237,7 +234,7 @@ if (! function_exists('bs_announcement')) {
|
||||
|
||||
if (! function_exists('bs_nickname')) {
|
||||
|
||||
function bs_nickname(\App\Models\User $user = null)
|
||||
function bs_nickname(User $user = null)
|
||||
{
|
||||
$user = $user ?: app('users')->getCurrentUser();
|
||||
|
||||
@ -245,6 +242,25 @@ if (! function_exists('bs_nickname')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('bs_role')) {
|
||||
|
||||
function bs_role(User $user = null)
|
||||
{
|
||||
$user = $user ?: app('users')->getCurrentUser();
|
||||
|
||||
$roles = [
|
||||
User::NORMAL => 'normal',
|
||||
User::BANNED => 'banned',
|
||||
User::ADMIN => 'admin',
|
||||
User::SUPER_ADMIN => 'super-admin'
|
||||
];
|
||||
|
||||
$role = Arr::get($roles, $user->getPermission());
|
||||
|
||||
return trans("admin.users.status.$role");
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('option')) {
|
||||
/**
|
||||
* Get / set the specified option value.
|
||||
|
@ -7,6 +7,7 @@ login:
|
||||
|
||||
check:
|
||||
anonymous: Illegal access. Please log in first.
|
||||
admin: Only admins are permitted to access this page.
|
||||
banned: You are banned on this site. Please contact the admin.
|
||||
token: Invalid token. Please log in.
|
||||
|
||||
|
@ -5,7 +5,6 @@ logout: Log Out
|
||||
login: Log In
|
||||
register: Register Now
|
||||
profile: User Profile
|
||||
online: Online
|
||||
admin-panel: Admin Panel
|
||||
explore: Explore
|
||||
manage: Manage
|
||||
|
@ -8,7 +8,7 @@ index:
|
||||
users:
|
||||
status:
|
||||
title: 状态
|
||||
normal: 正常
|
||||
normal: 普通用户
|
||||
banned: 封禁
|
||||
admin: 管理员
|
||||
super-admin: 超级管理员
|
||||
@ -114,7 +114,7 @@ plugins:
|
||||
|
||||
update:
|
||||
complete: 更新完成
|
||||
|
||||
|
||||
info:
|
||||
title: 更新信息
|
||||
|
||||
|
@ -7,6 +7,7 @@ login:
|
||||
|
||||
check:
|
||||
anonymous: 非法访问,请先登录
|
||||
admin: 看起来你并不是管理员哦
|
||||
banned: 你已经被本站封禁啦,请联系管理员解决
|
||||
token: 无效的 token,请重新登录
|
||||
|
||||
|
@ -5,7 +5,6 @@ logout: 登出
|
||||
login: 登录
|
||||
register: 现在注册
|
||||
profile: 个人资料
|
||||
online: 在线
|
||||
admin-panel: 管理面板
|
||||
explore: 浏览
|
||||
manage: 管理
|
||||
|
@ -82,7 +82,7 @@
|
||||
</div>
|
||||
<div class="pull-left info">
|
||||
<p class="nickname">{{ bs_nickname($user) }}</p>
|
||||
<i class="fa fa-circle text-success"></i> {{ trans('general.online') }}
|
||||
<i class="fa fa-circle text-success"></i> {{ bs_role($user) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -12,6 +12,10 @@
|
||||
<div class="login-box-body">
|
||||
<p class="login-box-msg">{{ trans('auth.forgot.message') }}</p>
|
||||
|
||||
@if (Session::has('msg'))
|
||||
<div class="callout callout-warning">{{ Session::pull('msg') }}</div>
|
||||
@endif
|
||||
|
||||
<form id="login-form">
|
||||
<div class="form-group has-feedback">
|
||||
<input id="email" type="email" class="form-control" placeholder="{{ trans('auth.email') }}">
|
||||
|
@ -12,6 +12,10 @@
|
||||
<div class="login-box-body">
|
||||
<p class="login-box-msg">{{ trans('auth.login.message') }}</p>
|
||||
|
||||
@if (Session::has('msg'))
|
||||
<div class="callout callout-warning">{{ Session::pull('msg') }}</div>
|
||||
@endif
|
||||
|
||||
<form id="login-form">
|
||||
<div class="form-group has-feedback">
|
||||
<input id="identification" type="email" class="form-control" placeholder="{{ trans('auth.identification') }}">
|
||||
|
@ -80,7 +80,7 @@
|
||||
</div>
|
||||
<div class="pull-left info">
|
||||
<p class="nickname">{{ bs_nickname($user) }}</p>
|
||||
<i class="fa fa-circle text-success"></i> {{ trans('general.online') }}
|
||||
<i class="fa fa-circle text-success"></i> {{ bs_role($user) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user