@@ -33,11 +33,10 @@ export const getNonce = () => { | |||||
return hostname; | return hostname; | ||||
}; | }; | ||||
export const getBowerType = () => { | |||||
export const getBowserType = () => { | |||||
console.log(navigator.userAgent) | console.log(navigator.userAgent) | ||||
// const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mi|huawei|Opera Mini|SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i; | // const regex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mi|huawei|Opera Mini|SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L/i; | ||||
// if(!regex.test(navigator.userAgent)) | // if(!regex.test(navigator.userAgent)) | ||||
if (navigator.userAgent.indexOf("Edg") != -1) { | if (navigator.userAgent.indexOf("Edg") != -1) { | ||||
if (navigator.userAgent.match(/Android/i)) return "Android_Edge" | if (navigator.userAgent.match(/Android/i)) return "Android_Edge" | ||||
if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge" | if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge" | ||||
@@ -63,6 +62,10 @@ export const getBowerType = () => { | |||||
return "PC_Browser"; | return "PC_Browser"; | ||||
} | } | ||||
export const isAppBowser = () => { | |||||
return "PC_Browser" != getBowserType(); | |||||
} | |||||
export const isUserLoggedIn = () => { | export const isUserLoggedIn = () => { | ||||
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName); | return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName); | ||||
@@ -68,7 +68,9 @@ export default function UserTable_Individual({ recordList }) { | |||||
valueGetter: (params) => { | valueGetter: (params) => { | ||||
if (params.value) { | if (params.value) { | ||||
let tel = JSON.parse(params.value); | let tel = JSON.parse(params.value); | ||||
return "+" + tel.countryCode + " " + tel.phoneNumber; | |||||
if(tel?.phoneNumber) | |||||
return "+" + tel?.countryCode + " " + tel?.phoneNumber; | |||||
else return ""; | |||||
} | } | ||||
} | } | ||||
@@ -9,7 +9,7 @@ import Typography from '@mui/material/Typography'; | |||||
import iAmSmartICon from 'assets/images/icons/icon_iAmSmart.png'; | import iAmSmartICon from 'assets/images/icons/icon_iAmSmart.png'; | ||||
import banner from 'assets/images/bg_ml.jpg'; | import banner from 'assets/images/bg_ml.jpg'; | ||||
import { Stack } from '../../../node_modules/@mui/material/index'; | import { Stack } from '../../../node_modules/@mui/material/index'; | ||||
import { iAmSmartPath, clientId, getBowerType , iAmSmartCallbackPath} from 'auth/utils' | |||||
import { iAmSmartPath, clientId, getBowserType , iAmSmartCallbackPath} from 'auth/utils' | |||||
import * as React from 'react'; | import * as React from 'react'; | ||||
@@ -29,7 +29,7 @@ const RegisterCustom = () => { | |||||
let url = iAmSmartPath + "/api/v1/auth/getQR" | let url = iAmSmartPath + "/api/v1/auth/getQR" | ||||
+ "?clientID=" + clientId | + "?clientID=" + clientId | ||||
+ "&responseType=code" | + "&responseType=code" | ||||
+"&source=" + getBowerType() | |||||
+"&source=" + getBowserType() | |||||
+"&redirectURI="+encodeURIComponent(callbackUrl) | +"&redirectURI="+encodeURIComponent(callbackUrl) | ||||
+"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") | +"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") | ||||
+"&lang=zh-HK"//en-US, zh-HK, or zh-CN | +"&lang=zh-HK"//en-US, zh-HK, or zh-CN | ||||
@@ -6,7 +6,7 @@ import React, { | |||||
import { Link as RouterLink } from 'react-router-dom'; | import { Link as RouterLink } from 'react-router-dom'; | ||||
import { useNavigate } from 'react-router-dom'; | import { useNavigate } from 'react-router-dom'; | ||||
import { useForm, } from 'react-hook-form' | import { useForm, } from 'react-hook-form' | ||||
import { iAmSmartPath, clientId, getBowerType , iAmSmartCallbackPath} from 'auth/utils' | |||||
import { iAmSmartPath, clientId, getBowserType, isAppBowser, iAmSmartCallbackPath } from 'auth/utils' | |||||
// material-ui | // material-ui | ||||
import { | import { | ||||
@@ -169,31 +169,42 @@ const AuthLoginCustom = () => { | |||||
const { handleSubmit } = useForm({}) | const { handleSubmit } = useForm({}) | ||||
const getQRWithIAmSmart = () => { | const getQRWithIAmSmart = () => { | ||||
let callbackUrl = "https://"+iAmSmartCallbackPath()+"/iamsmart/authcallback"; | |||||
if (isAppBowser()) { | |||||
openApp(); | |||||
} else { | |||||
openQR(); | |||||
} | |||||
} | |||||
const openQR = () => { | |||||
let callbackUrl = "https://" + iAmSmartCallbackPath() + "/iamsmart/authcallback"; | |||||
let url = iAmSmartPath + "/api/v1/auth/getQR" | let url = iAmSmartPath + "/api/v1/auth/getQR" | ||||
+ "?clientID=" + clientId | + "?clientID=" + clientId | ||||
+ "&responseType=code" | + "&responseType=code" | ||||
+"&source=" + getBowerType() | |||||
+"&redirectURI="+encodeURIComponent(callbackUrl) | |||||
+"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") | |||||
+"&lang=zh-HK"//en-US, zh-HK, or zh-CN | |||||
+ "&source=" + getBowserType() | |||||
+ "&redirectURI=" + encodeURIComponent(callbackUrl) | |||||
+ "&scope=" + encodeURIComponent("eidapi_auth eidapi_profiles") | |||||
+ "&lang=zh-HK"//en-US, zh-HK, or zh-CN | |||||
//+"&state=" | //+"&state=" | ||||
+"&brokerPage=false" | |||||
window.location.assign(url); | |||||
+ "&brokerPage=false" | |||||
window.location=url; | |||||
} | } | ||||
const openApp = () => { | const openApp = () => { | ||||
let callbackUrl = "https://"+iAmSmartCallbackPath()+"/iamsmart/authcallback"; | |||||
let url = "hk.gov.iamsmart.testapp://" +"auth" | |||||
setTimeout(function () { | |||||
openQR(); | |||||
}, 1000); | |||||
let callbackUrl = "https://" + iAmSmartCallbackPath() + "/iamsmart/authcallback"; | |||||
let url = "hk.gov.iamsmart.testapp://" + "auth" | |||||
+ "?clientID=" + clientId | + "?clientID=" + clientId | ||||
+ "&responseType=code" | + "&responseType=code" | ||||
+"&source=" + getBowerType() | |||||
+"&redirectURI="+encodeURIComponent(callbackUrl) | |||||
+"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") | |||||
+"&lang=zh-HK"//en-US, zh-HK, or zh-CN | |||||
+ "&source=" + getBowserType() | |||||
+ "&redirectURI=" + encodeURIComponent(callbackUrl) | |||||
+ "&scope=" + encodeURIComponent("eidapi_auth eidapi_profiles") | |||||
+ "&lang=zh-HK"//en-US, zh-HK, or zh-CN | |||||
//+"&state=" | //+"&state=" | ||||
+"&brokerPage=false" | |||||
window.location.assign(url); | |||||
+ "&brokerPage=false" | |||||
window.location=url; | |||||
} | } | ||||
@@ -291,12 +302,7 @@ const AuthLoginCustom = () => { | |||||
</Grid> | </Grid> | ||||
<Grid item xs={12}> | <Grid item xs={12}> | ||||
<Stack direction="row" justifyContent="space-between" alignItems="center" spacing={2}> | <Stack direction="row" justifyContent="space-between" alignItems="center" spacing={2}> | ||||
<Button onClick={()=>getQRWithIAmSmart()} color="iAmSmart" fullWidth size="large" variant="outlined" startIcon={<img src={iAmSmartICon} alt="iAM Smart" width="30" />}><Typography variant="h5">智方便登入</Typography></Button> | |||||
</Stack> | |||||
</Grid> | |||||
<Grid item xs={12}> | |||||
<Stack direction="row" justifyContent="space-between" alignItems="center" spacing={2}> | |||||
<Button onClick={()=>openApp()} color="iAmSmart" fullWidth size="large" variant="outlined" startIcon={<img src={iAmSmartICon} alt="iAM Smart" width="30" />}><Typography variant="h5">智方便登入(App)</Typography></Button> | |||||
<Button onClick={() => getQRWithIAmSmart()} color="iAmSmart" fullWidth size="large" variant="outlined" startIcon={<img src={iAmSmartICon} alt="iAM Smart" width="30" />}><Typography variant="h5">智方便登入</Typography></Button> | |||||
</Stack> | </Stack> | ||||
</Grid> | </Grid> | ||||
<Grid item xs={12}> | <Grid item xs={12}> | ||||
@@ -0,0 +1,72 @@ | |||||
import * as React from "react"; | |||||
import * as HttpUtils from "utils/HttpUtils"; | |||||
import * as UrlUtils from "utils/ApiPathConst"; | |||||
import { useNavigate } from "react-router-dom"; | |||||
import { useDispatch } from "react-redux"; | |||||
import { handleLogoutFunction, handleLogin } from 'auth/index'; | |||||
import Loadable from 'components/Loadable'; | |||||
const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); | |||||
// ==============================|| DASHBOARD - DEFAULT ||============================== // | |||||
const Index = () => { | |||||
const dispatch = useDispatch() | |||||
const navigate = useNavigate() | |||||
React.useEffect(() => { | |||||
getPrfile(); | |||||
}, []); | |||||
function getPrfile(){ | |||||
dispatch(handleLogoutFunction()); | |||||
let params = new URLSearchParams(window.location.search) | |||||
if(params.get("code")){ | |||||
HttpUtils.post({ | |||||
url: UrlUtils.GET_SMART_LOGIN, | |||||
params:{ | |||||
code: params.get("code") | |||||
}, | |||||
onSuccess: (responseData) => { | |||||
//navigate('/iAmSmartRegisterFrom', { state: { responseData: responseData } }); | |||||
console.log(response) | |||||
const userData = { | |||||
id: responseData.id, | |||||
fullenName: responseData.name, | |||||
fullchName: responseData.chName, | |||||
email: responseData.email, | |||||
type: responseData.type, | |||||
role: responseData.role, | |||||
abilities: responseData.abilities, | |||||
creditor: responseData.creditor, | |||||
//avatar: require('src/assets/images/users/avatar-3.png').default, | |||||
} | |||||
const data = { ...userData, accessToken: responseData.accessToken, refreshToken: responseData.refreshToken } | |||||
// setSuccess(true) | |||||
dispatch(handleLogin(data)) | |||||
navigate('/dashboard'); | |||||
location.reload() | |||||
}, | |||||
onFail: ()=>{ | |||||
window.location.assign("/iamsmart/loginFall"); | |||||
}, | |||||
onError:()=>{ | |||||
window.location.assign("/iamsmart/loginFall"); | |||||
} | |||||
}); | |||||
} | |||||
} | |||||
return ( | |||||
<LoadingComponent /> | |||||
); | |||||
}; | |||||
export default Index; |
@@ -55,6 +55,10 @@ const LoginRoutes = { | |||||
path: 'error', | path: 'error', | ||||
element: <ErrorPage/> | element: <ErrorPage/> | ||||
}, | }, | ||||
{ | |||||
path: 'iamsmart/fallcallback', | |||||
element: <IAmSmart_AuthCallback/> | |||||
}, | |||||
{ | { | ||||
path: 'iamsmart/authcallback', | path: 'iamsmart/authcallback', | ||||
element: <IAmSmart_AuthCallback/> | element: <IAmSmart_AuthCallback/> | ||||