mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 09:39:10 +08:00
update
This commit is contained in:
parent
5b29257227
commit
1351ec583e
@ -6,6 +6,8 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Requests\Passport\LoginIndex;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
@ -35,24 +37,43 @@ class LoginController extends Controller
|
||||
}
|
||||
|
||||
public function token2Login (Request $request) {
|
||||
if (empty($request->input('token'))) {
|
||||
abort(500, '参数错误');
|
||||
if ($request->input('token')) {
|
||||
$user = User::where('token', $request->input('token'))->first();
|
||||
if (!$user) {
|
||||
return header('Location:' . config('v2board.app_url'));
|
||||
}
|
||||
$key = 'token2Login_' . Helper::guid();
|
||||
Redis::set($key, $user->id);
|
||||
Redis::expire($key, 600);
|
||||
$redirect = '/#/login?verify='. $key .'&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$location = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$location = url($redirect);
|
||||
}
|
||||
return header('Location:' . $location);
|
||||
}
|
||||
$redirect = $request->input('redirect') ? $request->input('redirect') : 'dashboard';
|
||||
$user = User::where('token', $request->input('token'))->first();
|
||||
if ($user) {
|
||||
|
||||
if ($request->input('verify')) {
|
||||
$key = 'token2Login_' . $request->input('verify');
|
||||
$userId = Redis::get($key);
|
||||
if (!$userId) {
|
||||
abort(500, '令牌有误');
|
||||
}
|
||||
$user = User::find($userId);
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
if ($user->is_admin) {
|
||||
$request->session()->put('is_admin', true);
|
||||
}
|
||||
Redis::del($key);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
if (config('v2board.app_url')) {
|
||||
$location = config('v2board.app_url') . '/#/' . $redirect;
|
||||
} else {
|
||||
$location = url('/#/' . $redirect);
|
||||
}
|
||||
header('Location:' . $location);
|
||||
}
|
||||
|
||||
public function check (Request $request) {
|
||||
|
Loading…
Reference in New Issue
Block a user