@@ -33,11 +33,10 @@ export const getNonce = () => { | |||
return hostname; | |||
}; | |||
export const getBowerType = () => { | |||
export const getBowserType = () => { | |||
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; | |||
// if(!regex.test(navigator.userAgent)) | |||
if (navigator.userAgent.indexOf("Edg") != -1) { | |||
if (navigator.userAgent.match(/Android/i)) return "Android_Edge" | |||
if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) return "iOS_Edge" | |||
@@ -63,6 +62,10 @@ export const getBowerType = () => { | |||
return "PC_Browser"; | |||
} | |||
export const isAppBowser = () => { | |||
return "PC_Browser" != getBowserType(); | |||
} | |||
export const isUserLoggedIn = () => { | |||
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName); | |||
@@ -68,7 +68,9 @@ export default function UserTable_Individual({ recordList }) { | |||
valueGetter: (params) => { | |||
if (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 banner from 'assets/images/bg_ml.jpg'; | |||
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'; | |||
@@ -29,7 +29,7 @@ const RegisterCustom = () => { | |||
let url = iAmSmartPath + "/api/v1/auth/getQR" | |||
+ "?clientID=" + clientId | |||
+ "&responseType=code" | |||
+"&source=" + getBowerType() | |||
+"&source=" + getBowserType() | |||
+"&redirectURI="+encodeURIComponent(callbackUrl) | |||
+"&scope="+encodeURIComponent("eidapi_auth eidapi_profiles") | |||
+"&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 { useNavigate } from 'react-router-dom'; | |||
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 | |||
import { | |||
@@ -169,31 +169,42 @@ const AuthLoginCustom = () => { | |||
const { handleSubmit } = useForm({}) | |||
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" | |||
+ "?clientID=" + clientId | |||
+ "&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=" | |||
+"&brokerPage=false" | |||
window.location.assign(url); | |||
+ "&brokerPage=false" | |||
window.location=url; | |||
} | |||
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 | |||
+ "&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=" | |||
+"&brokerPage=false" | |||
window.location.assign(url); | |||
+ "&brokerPage=false" | |||
window.location=url; | |||
} | |||
@@ -291,12 +302,7 @@ const AuthLoginCustom = () => { | |||
</Grid> | |||
<Grid item xs={12}> | |||
<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> | |||
</Grid> | |||
<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', | |||
element: <ErrorPage/> | |||
}, | |||
{ | |||
path: 'iamsmart/fallcallback', | |||
element: <IAmSmart_AuthCallback/> | |||
}, | |||
{ | |||
path: 'iamsmart/authcallback', | |||
element: <IAmSmart_AuthCallback/> | |||