diff --git a/app/Http/Controllers/Auth/DingTalkLogin.php b/app/Http/Controllers/Auth/DingTalkLogin.php index 92c70755..7f8aac83 100644 --- a/app/Http/Controllers/Auth/DingTalkLogin.php +++ b/app/Http/Controllers/Auth/DingTalkLogin.php @@ -157,7 +157,10 @@ class DingTalkLogin extends Controller $url = $this->applicationRoute($user->landing_page, ['company_id' => $company->id]); - return redirect()->intended($url); + // 免登后固定回到首页(财务驾驶舱),不再回跳上次打开的业务页面。 + $request->session()->forget('url.intended'); + + return redirect()->to($url); } protected function failed(): RedirectResponse diff --git a/app/Http/Controllers/Auth/Login.php b/app/Http/Controllers/Auth/Login.php index 5469a756..fcbae1c5 100644 --- a/app/Http/Controllers/Auth/Login.php +++ b/app/Http/Controllers/Auth/Login.php @@ -107,8 +107,11 @@ class Login extends Controller // Redirect to landing page if is user $url = route($user->landing_page, ['company_id' => $company->id]); + // 登录后固定回到首页(财务驾驶舱),不再回跳上次打开/被拦截的业务页面。 + $request->session()->forget('url.intended'); + if (! $request->expectsJson()) { - return redirect()->intended($url); + return redirect()->to($url); } return response()->json([ @@ -117,7 +120,7 @@ class Login extends Controller 'error' => false, 'message' => trans('auth.login_redirect'), 'data' => null, - 'redirect' => redirect()->intended($url)->getTargetUrl(), + 'redirect' => url($url), ]); } diff --git a/tests/Feature/Auth/DingTalkLoginTest.php b/tests/Feature/Auth/DingTalkLoginTest.php index 5f99f310..c0ce8d55 100644 --- a/tests/Feature/Auth/DingTalkLoginTest.php +++ b/tests/Feature/Auth/DingTalkLoginTest.php @@ -143,7 +143,8 @@ class DingTalkLoginTest extends FeatureTestCase $this->get(route('login.dingtalk.callback', ['code' => 'fixture', 'state' => $state])) ->assertRedirect(route('dashboard', ['company_id' => $this->company->id])); $this->get(route('dashboard', ['company_id' => $this->company->id])) - ->assertRedirectContains('/workspace/courier-payables/courier-quote'); + ->assertOk() + ->assertSee('data-cockpit', false); $created = auth()->user(); $this->assertSame('dingtalk_roster_limited', $created->created_from); diff --git a/tests/Feature/Auth/UsersTest.php b/tests/Feature/Auth/UsersTest.php index 3e33bc78..6a878da6 100644 --- a/tests/Feature/Auth/UsersTest.php +++ b/tests/Feature/Auth/UsersTest.php @@ -148,6 +148,25 @@ class UsersTest extends FeatureTestCase $this->isAuthenticated($user->user); } + public function testItShouldLandOnTheHomePageAfterLoginInsteadOfTheLastOpenedBusinessPage() + { + // 未登录访问业务页面时,框架会记录 intended;登录后不应该再回跳到该页面。 + $this->withExceptionHandling()->get(route('business.pages.show', [ + 'company_id' => $this->company->id, + 'section' => 'courier-payables', + 'page' => 'freight-reconciliation', + ])); + + $response = $this->post(route('login'), [ + 'email' => $this->user->email, + 'password' => '123456', + ]); + + $response->assertRedirect(); + $this->assertTrue(auth()->check()); + $this->assertStringNotContainsString('/workspace/', (string) $response->headers->get('Location')); + } + public function testItShouldNotLoginUser() { $request = $this->getRequest(); diff --git a/tests/Feature/SystemSettings/UserAccessGroupsTest.php b/tests/Feature/SystemSettings/UserAccessGroupsTest.php index c19c0d87..52c83688 100644 --- a/tests/Feature/SystemSettings/UserAccessGroupsTest.php +++ b/tests/Feature/SystemSettings/UserAccessGroupsTest.php @@ -68,7 +68,7 @@ class UserAccessGroupsTest extends FeatureTestCase $this->loginAs()->patch(route('system-settings.sidebar.update'), ['subject' => 'group_'.$b->id, 'permissions' => []]) ->assertRedirect(route('system-settings.sidebar.edit', ['subject' => 'group_'.$b->id])); $this->assertSame(['store-management/basic-information'], SidebarPermissions::allowedKeys($member)); - $this->loginAs($member)->get(route('dashboard'))->assertRedirectContains('/workspace/store-management/basic-information'); + $this->loginAs($member)->get(route('dashboard'))->assertOk()->assertSee('data-cockpit', false); } public function test_user_override_can_be_empty_and_can_restore_group_inheritance(): void