mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-02-23 14:59:07 +08:00
use redirect helper function
This commit is contained in:
parent
cfd289c0c8
commit
0dd6d0125c
@ -79,12 +79,12 @@ class AdminController extends BaseController
|
||||
$total_pages = ceil($users->count() / 30);
|
||||
$users = $users->skip(($page - 1) * 30)->take(30)->get();
|
||||
|
||||
echo View::make('admin.users')->with('users', $users)
|
||||
->with('filter', $filter)
|
||||
->with('q', $q)
|
||||
->with('page', $page)
|
||||
->with('total_pages', $total_pages)
|
||||
->render();
|
||||
return View::make('admin.users')->with('users', $users)
|
||||
->with('filter', $filter)
|
||||
->with('q', $q)
|
||||
->with('page', $page)
|
||||
->with('total_pages', $total_pages)
|
||||
->render();
|
||||
}
|
||||
|
||||
public function players()
|
||||
@ -106,12 +106,12 @@ class AdminController extends BaseController
|
||||
$total_pages = ceil($players->count() / 30);
|
||||
$players = $players->skip(($page - 1) * 30)->take(30)->get();
|
||||
|
||||
echo View::make('admin.players')->with('players', $players)
|
||||
->with('filter', $filter)
|
||||
->with('q', $q)
|
||||
->with('page', $page)
|
||||
->with('total_pages', $total_pages)
|
||||
->render();
|
||||
return View::make('admin.players')->with('players', $players)
|
||||
->with('filter', $filter)
|
||||
->with('q', $q)
|
||||
->with('page', $page)
|
||||
->with('total_pages', $total_pages)
|
||||
->render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,6 @@ class AuthController extends BaseController
|
||||
setcookie('token', '', time() - 3600, '/');
|
||||
|
||||
Session::flush();
|
||||
Session::save();
|
||||
|
||||
View::json('登出成功~', 0);
|
||||
} else {
|
||||
@ -184,24 +183,24 @@ class AuthController extends BaseController
|
||||
if (isset($_GET['uid']) && isset($_GET['token'])) {
|
||||
$user = new User($_GET['uid']);
|
||||
if (!$user->is_registered)
|
||||
Http::redirect('./forgot', '无效的链接');
|
||||
return redirect('auth/forgot')->with('msg', '无效的链接');
|
||||
|
||||
$token = substr(base64_decode($_GET['token']), 0, -22);
|
||||
|
||||
if ($user->getToken() != $token) {
|
||||
Http::redirect('./forgot', '无效的链接');
|
||||
return redirect('auth/forgot')->with('msg', '无效的链接');
|
||||
}
|
||||
|
||||
$timestamp = substr(base64_decode($_GET['token']), strlen($token), 6);
|
||||
|
||||
// more than 1 hour
|
||||
if ((substr(time(), 4, 6) - $timestamp) > 3600) {
|
||||
Http::redirect('./forgot', '链接已过期');
|
||||
return redirect('auth/forgot')->with('msg', '链接已过期');
|
||||
}
|
||||
|
||||
echo View::make('auth.reset')->with('user', $user);
|
||||
return View::make('auth.reset')->with('user', $user);
|
||||
} else {
|
||||
Http::redirect('./login', '非法访问');
|
||||
return redirect('auth/login')->with('msg', '非法访问');
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,8 +223,9 @@ class AuthController extends BaseController
|
||||
$builder = new \Gregwar\Captcha\CaptchaBuilder;
|
||||
$builder->build($width = 100, $height = 34);
|
||||
Session::put('phrase', $builder->getPhrase());
|
||||
header('Content-type: image/jpeg');
|
||||
$builder->output();
|
||||
|
||||
return \Response::png();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,8 +8,12 @@ class CheckAdminMiddleware
|
||||
{
|
||||
$user = (new CheckAuthenticated)->handle($request, $next, true);
|
||||
|
||||
if ($user instanceof \Illuminate\Http\RedirectResponse) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
if (!$user->is_admin) {
|
||||
\Http::redirect('../user', '看起来你并不是管理员哦');
|
||||
return redirect('user')->with('msg', '看起来你并不是管理员哦');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -17,12 +17,13 @@ class CheckAuthenticated
|
||||
$user = new User(session('uid'));
|
||||
|
||||
if (session('token') != $user->getToken())
|
||||
Http::redirect('../auth/login', '无效的 token,请重新登录~');
|
||||
return redirect('auth/login')->with('msg', '无效的 token,请重新登录');
|
||||
|
||||
if ($user->getPermission() == "-1") {
|
||||
// delete cookies
|
||||
setcookie('uid', '', time() - 3600, '/');
|
||||
setcookie('token', '', time() - 3600, '/');
|
||||
|
||||
Session::flush();
|
||||
Session::save();
|
||||
|
||||
@ -38,6 +39,7 @@ class CheckAuthenticated
|
||||
// refresh token
|
||||
Session::put('token', $user->getToken(true));
|
||||
setcookie('token', session('token'), time() + 3600, '/');
|
||||
|
||||
return $user;
|
||||
} else {
|
||||
return View::make('auth.bind')->with('msg', '该邮箱已被占用');
|
||||
@ -45,10 +47,8 @@ class CheckAuthenticated
|
||||
} else {
|
||||
return View::make('auth.bind')->with('msg', '邮箱格式错误');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
return view('auth.bind');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($return_user)
|
||||
@ -56,7 +56,7 @@ class CheckAuthenticated
|
||||
|
||||
return $next($request);
|
||||
} else {
|
||||
Http::redirect('../auth/login', '非法访问,请先登录');
|
||||
return redirect('auth/login')->with('msg', '非法访问,请先登录');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@ -10,11 +10,10 @@ class RedirectIfAuthenticated
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if (session()->has('uid')) {
|
||||
if (session('token') != (new User(session('uid')))->getToken())
|
||||
{
|
||||
if (session('token') != (new User(session('uid')))->getToken()) {
|
||||
Session::put('msg', '无效的 token,请重新登录~');
|
||||
} else {
|
||||
\Http::redirect('../user');
|
||||
return redirect('user');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,32 +6,6 @@ use Session;
|
||||
|
||||
class Http
|
||||
{
|
||||
/**
|
||||
* HTTP redirect
|
||||
*
|
||||
* @param string $url
|
||||
* @param string $msg Write message to session
|
||||
* @return void
|
||||
*/
|
||||
public static function redirect($url, $msg = "")
|
||||
{
|
||||
if ($msg !== "") {
|
||||
if (app()->bound('session')) {
|
||||
Session::flash('msg', $msg);
|
||||
Session::save();
|
||||
} else {
|
||||
$_SESSION['msg'] = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
if (!headers_sent()) {
|
||||
header('Location: '.$url);
|
||||
} else {
|
||||
echo "<meta http-equiv='Refresh' content='0; URL=$url'>";
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 301 Moved Permanently
|
||||
*
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* @see \Illuminate\Support\Facades\View
|
||||
*/
|
||||
@ -24,16 +26,17 @@ class View extends \Illuminate\Support\Facades\View
|
||||
}
|
||||
}
|
||||
|
||||
private static function jsonCustom($array)
|
||||
private static function jsonCustom(Array $array)
|
||||
{
|
||||
if (is_array($array))
|
||||
if (is_array($array)) {
|
||||
Session::save();
|
||||
exit(json_encode($array));
|
||||
else
|
||||
throw new \Exception('The given arugument should be array.');
|
||||
}
|
||||
}
|
||||
|
||||
private static function jsonException($msg, $errno)
|
||||
{
|
||||
Session::save();
|
||||
exit(json_encode([
|
||||
'errno' => $errno,
|
||||
'msg' => $msg
|
||||
|
Loading…
Reference in New Issue
Block a user