Fix redirecting without URL query string after logged in

This commit is contained in:
Pig Fang 2019-07-12 15:53:49 +08:00
parent bb719bd089
commit 718c7a61a5
7 changed files with 9 additions and 9 deletions

View File

@ -59,7 +59,9 @@ class AuthController extends Controller
Cache::forget($loginFailsCacheKey);
return json(trans('auth.login.success'), 0);
return json(trans('auth.login.success'), 0, [
'redirectTo' => $request->session()->pull('last_requested_path', url('/user')),
]);
} else {
// Increase the counter
Cache::put($loginFailsCacheKey, ++$loginFails, 3600);

View File

@ -10,7 +10,7 @@ class Authenticate extends Middleware
{
if (! $request->expectsJson()) {
session([
'last_requested_path' => $request->path(),
'last_requested_path' => $request->fullUrl(),
'msg' => trans('auth.check.anonymous'),
]);

View File

@ -89,7 +89,7 @@ export default {
this.pending = true
const {
code, message, data: { login_fails: loginFails } = { login_fails: 0 },
code, message, data: { login_fails: loginFails, redirectTo } = { login_fails: 0 },
} = await this.$http.post(
'/auth/login',
{
@ -103,9 +103,7 @@ export default {
)
if (code === 0) {
this.$message.success(message)
setTimeout(() => {
window.location = `${blessing.base_url}/${blessing.redirect_to || 'user'}`
}, 1000)
setTimeout(() => (window.location = redirectTo), 1000)
} else {
if (loginFails > 3 && !this.tooManyFails) {
if (this.recaptcha) {

View File

@ -25,7 +25,7 @@ test('login', async () => {
.mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 1, data: { login_fails: 4 } })
.mockResolvedValueOnce({ code: 0, message: 'ok' })
.mockResolvedValueOnce({ code: 0, message: 'ok', data: { redirectTo: '' } })
const wrapper = mount(Login, { stubs: { Captcha } })
const form = wrapper.find('form')
const warning = wrapper.find('.callout-warning')

View File

@ -15,3 +15,4 @@
- Fixed renaming item in closet.
- Fixed Font Awesome of bottom of home page.
- Fixed loading front-end i18n texts of plugins.
- Fixed redirecting without URL query string after logged in.

View File

@ -15,3 +15,4 @@
- 修复不能重命名衣柜物品的问题
- 修复首页底部 Font Awesome 的问题
- 修复插件系统中加载前端国际化文本的问题
- 修复登录重定向没有包含 URL 查询的问题

View File

@ -11,8 +11,6 @@
@include('common.seo-meta-tags')
<!-- App Styles -->
@include('common.dependencies.style')
<script>blessing.redirect_to = "{{ session('last_requested_path') }}";</script>
</head>
<body class="hold-transition login-page">