diff --git a/app/Http/Middleware/CheckAdministrator.php b/app/Http/Middleware/CheckAdministrator.php index 13175d44..eda6ae17 100644 --- a/app/Http/Middleware/CheckAdministrator.php +++ b/app/Http/Middleware/CheckAdministrator.php @@ -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); diff --git a/app/Http/Middleware/CheckAuthenticated.php b/app/Http/Middleware/CheckAuthenticated.php index f648c7a4..f637d268 100644 --- a/app/Http/Middleware/CheckAuthenticated.php +++ b/app/Http/Middleware/CheckAuthenticated.php @@ -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'); + } } diff --git a/app/Http/Middleware/CheckSessionUserValid.php b/app/Http/Middleware/CheckSessionUserValid.php index 6ba543c5..ad56c6c0 100644 --- a/app/Http/Middleware/CheckSessionUserValid.php +++ b/app/Http/Middleware/CheckSessionUserValid.php @@ -29,6 +29,8 @@ class CheckSessionUserValid // remove sessions & cookies delete_sessions(); delete_cookies(); + + return redirect('auth/login')->with('msg', trans('auth.check.token')); } } diff --git a/app/helpers.php b/app/helpers.php index ad41f4e6..ec762db2 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,5 +1,6 @@ email).".png?tid=".$user->getAvatarId(); @@ -101,10 +102,6 @@ if (! function_exists('bs_footer')) { echo ""; } - if (Session::has('msg')) { - echo ""; - } - echo ''; $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. diff --git a/resources/lang/en/auth.yml b/resources/lang/en/auth.yml index 05dfba29..8e3b3ab2 100644 --- a/resources/lang/en/auth.yml +++ b/resources/lang/en/auth.yml @@ -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. diff --git a/resources/lang/en/general.yml b/resources/lang/en/general.yml index cdb50c45..d144fd74 100644 --- a/resources/lang/en/general.yml +++ b/resources/lang/en/general.yml @@ -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 diff --git a/resources/lang/zh_CN/admin.yml b/resources/lang/zh_CN/admin.yml index 01651eac..2be5bf73 100644 --- a/resources/lang/zh_CN/admin.yml +++ b/resources/lang/zh_CN/admin.yml @@ -8,7 +8,7 @@ index: users: status: title: 状态 - normal: 正常 + normal: 普通用户 banned: 封禁 admin: 管理员 super-admin: 超级管理员 @@ -114,7 +114,7 @@ plugins: update: complete: 更新完成 - + info: title: 更新信息 diff --git a/resources/lang/zh_CN/auth.yml b/resources/lang/zh_CN/auth.yml index 9f4e52e8..bc3d66b2 100644 --- a/resources/lang/zh_CN/auth.yml +++ b/resources/lang/zh_CN/auth.yml @@ -7,6 +7,7 @@ login: check: anonymous: 非法访问,请先登录 + admin: 看起来你并不是管理员哦 banned: 你已经被本站封禁啦,请联系管理员解决 token: 无效的 token,请重新登录 diff --git a/resources/lang/zh_CN/general.yml b/resources/lang/zh_CN/general.yml index 51aa4ae8..bcffc4f7 100644 --- a/resources/lang/zh_CN/general.yml +++ b/resources/lang/zh_CN/general.yml @@ -5,7 +5,6 @@ logout: 登出 login: 登录 register: 现在注册 profile: 个人资料 -online: 在线 admin-panel: 管理面板 explore: 浏览 manage: 管理 diff --git a/resources/views/admin/master.tpl b/resources/views/admin/master.tpl index 6991e8ff..affe16c3 100644 --- a/resources/views/admin/master.tpl +++ b/resources/views/admin/master.tpl @@ -82,7 +82,7 @@
{{ bs_nickname($user) }}
- {{ trans('general.online') }} + {{ bs_role($user) }}{{ trans('auth.forgot.message') }}
+ @if (Session::has('msg')) +