@@ -6,15 +6,12 @@ import securityService from "../../services/securityService"
66import { useNotification } from "../notification"
77
88function isValidHttpUrl ( string ) {
9- let url
10-
119 try {
12- url = new URL ( string )
13- } catch ( _ ) {
10+ const url = new URL ( string )
11+ return url . protocol === "http:" || url . protocol === "https:"
12+ } catch {
1413 return false
1514 }
16-
17- return url . protocol === "http:" || url . protocol === "https:"
1815}
1916
2017export function useLogin ( ) {
@@ -26,21 +23,30 @@ export function useLogin() {
2623
2724 const isLoading = ref ( false )
2825
29- async function performLogin ( payload ) {
26+ async function performLogin ( { login , password , _remember_me , totp = null } ) {
3027 isLoading . value = true
3128
3229 try {
30+ const payload = {
31+ username : login ,
32+ password,
33+ _remember_me,
34+ }
35+ if ( totp ) {
36+ payload . totp = totp
37+ }
38+ const returnUrl = route . query . redirect ?. toString ( ) || null
39+ if ( returnUrl ) {
40+ payload . returnUrl = returnUrl
41+ }
42+
3343 const responseData = await securityService . login ( payload )
3444
45+ // 2FA
3546 if ( responseData . requires2FA ) {
3647 return { success : true , requires2FA : true }
3748 }
3849
39- if ( route . query . redirect && isValidHttpUrl ( route . query . redirect . toString ( ) ) ) {
40- window . location . href = route . query . redirect . toString ( )
41- return
42- }
43-
4450 if ( responseData . redirect ) {
4551 window . location . href = responseData . redirect
4652 return
@@ -49,19 +55,17 @@ export function useLogin() {
4955 securityStore . setUser ( responseData )
5056 await platformConfigurationStore . initialize ( )
5157
52- if ( route . query . redirect ) {
58+ if ( route . query . redirect && isValidHttpUrl ( route . query . redirect . toString ( ) ) ) {
5359 await router . replace ( { path : route . query . redirect . toString ( ) } )
5460 return
5561 }
5662
5763 const setting = platformConfigurationStore . getSetting ( "registration.redirect_after_login" )
5864 let target = "/"
59-
6065 if ( setting && typeof setting === "string" ) {
6166 try {
6267 const map = JSON . parse ( setting )
6368 const roles = responseData . roles || [ ]
64-
6569 const getProfile = ( ) => {
6670 if ( roles . includes ( "ROLE_ADMIN" ) ) return "ADMIN"
6771 if ( roles . includes ( "ROLE_SESSION_MANAGER" ) ) return "SESSIONADMIN"
@@ -72,10 +76,8 @@ export function useLogin() {
7276 if ( roles . includes ( "ROLE_STUDENT" ) ) return "STUDENT"
7377 return null
7478 }
75-
7679 const profile = getProfile ( )
7780 const value = profile && map [ profile ] ? map [ profile ] : ""
78-
7981 switch ( value ) {
8082 case "user_portal.php" :
8183 case "index.php" :
@@ -109,7 +111,6 @@ export function useLogin() {
109111 if ( ! securityStore . isAuthenticated ) {
110112 return
111113 }
112-
113114 if ( route . query . redirect ) {
114115 await router . push ( { path : route . query . redirect . toString ( ) } )
115116 } else {
0 commit comments