From 5ebe4ee01ee41e253b01719e3ff5fec04f99b8eb Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 5 Dec 2023 18:37:51 +0800 Subject: [PATCH] iamsmart login --- src/auth/utils.js | 4 +- src/pages/authentication/IAmSmartRegister.js | 4 ++ .../auth-forms/AuthLoginCustom.js | 20 ++++++++- .../auth-forms/IAmSmartFormWizard.js | 10 +++-- src/pages/iAmSmart/AuthCallback/index.js | 2 +- src/pages/iAmSmart/RegistryCallback/index.js | 43 +++++++++++++++++++ src/routes/LoginRoutes.js | 5 +++ src/themes/palette.js | 6 +++ src/utils/ApiPathConst.js | 3 +- 9 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 src/pages/iAmSmart/RegistryCallback/index.js diff --git a/src/auth/utils.js b/src/auth/utils.js index 65bd4ab..b9eb67c 100644 --- a/src/auth/utils.js +++ b/src/auth/utils.js @@ -18,8 +18,10 @@ export const clientId = "cf61fa7c121e4869966f69c8694b1cd2"; export const iAmSmartCallbackPath = () => { let hostname = window.location.hostname; - if (hostname.match("localhost")) { + if (hostname.match("pnspsuat")) { hostname = "pnspsuat.gld.gov.hk"; + }else{ + hostname = "pnspsdev.gld.gov.hk"; } return hostname; }; diff --git a/src/pages/authentication/IAmSmartRegister.js b/src/pages/authentication/IAmSmartRegister.js index 6fd6c11..8dd909e 100644 --- a/src/pages/authentication/IAmSmartRegister.js +++ b/src/pages/authentication/IAmSmartRegister.js @@ -83,6 +83,10 @@ const Register = () => { } const handleNext = async () => { + if(!idNo){ + notifyActionError("資料,請返回注冊頁面。") + return; + } const test = await handleCheckID() if (test) { notifyActionError("此用戶已注冊,請返回登入頁面並進行登入流程。") diff --git a/src/pages/authentication/auth-forms/AuthLoginCustom.js b/src/pages/authentication/auth-forms/AuthLoginCustom.js index ff1400e..ca13486 100644 --- a/src/pages/authentication/auth-forms/AuthLoginCustom.js +++ b/src/pages/authentication/auth-forms/AuthLoginCustom.js @@ -6,6 +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' // material-ui import { @@ -167,6 +168,21 @@ const AuthLoginCustom = () => { const { handleSubmit } = useForm({}) + const getQRWithIAmSmart = () => { + 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 + //+"&state=" + +"&brokerPage=false" + window.location.assign(url); + } + + return (
@@ -261,12 +277,12 @@ const AuthLoginCustom = () => { - + - 了解更多智方便 + {"了解更多 >"} diff --git a/src/pages/authentication/auth-forms/IAmSmartFormWizard.js b/src/pages/authentication/auth-forms/IAmSmartFormWizard.js index 99f936f..fcba63b 100644 --- a/src/pages/authentication/auth-forms/IAmSmartFormWizard.js +++ b/src/pages/authentication/auth-forms/IAmSmartFormWizard.js @@ -75,8 +75,6 @@ const CustomFormWizard = (props) => { + "授權,否則嚴禁複製、改編、分發、發布或向公眾提供該等版權作品。" - const dataStr = "{\"emailAddress\":\"test@gmail.com\",\"postalAddress\":{\"EngPremisesAddress\":{\"EngDistrict\":{\"DcDistrict\":\"KC\",\"Sub-district\":\"TSING YI\"},\"EngEstate\":{\"EstateName\":\"Cheung Hang Estate\",\"EngPhase\":{\"PhaseName\":\"N/A\"}},\"BuildingName\":\"Hang Lai House\",\"EngBlock\":{\"BlockDescriptor\":\"Block\",\"BlockNo\":\"2\"},\"Region\":\"NT\",\"EngStreet\":{\"StreetName\":\"Liu To Road\",\"BuildingNoFrom\":\"6\"},\"Eng3dAddress\":{\"EngFloor\":{\"FloorNum\":\"33\"},\"EngUnit\":{\"UnitDescriptor\":\"Room\",\"UnitNo\":\"3301\"}}}},\"mobileNumber\":{\"CountryCode\":\"852\",\"SubscriberNumber\":\"99999999\"},\"residentialAddress\":{\"ChiPremisesAddress\":{\"Chi3dAddress\":{\"ChiUnit\":{\"UnitDescriptor\":\"室\",\"UnitNo\":\"1010\"},\"ChiFloor\":{\"FloorNum\":\"10\"}},\"ChiBlock\":{\"BlockDescriptor\":\"座\",\"BlockNo\":\"2\"},\"BuildingName\":\"亨麗樓(第2座)\",\"ChiDistrict\":{\"DcDistrict\":\"KC\",\"Sub-district\":\"青衣\"},\"Region\":\"新界\",\"ChiEstate\":{\"EstateName\":\"長亨邨\"},\"ChiStreet\":{\"StreetName\":\"寮肚路\",\"BuildingNoFrom\":\"6\"}}},\"enName\":{\"UnstructuredName\":\"Testing Co One\"},\"idNo\":{\"Identification\":\"G561107\",\"CheckDigit\":\"4\"},\"chName\":{\"ChineseName\":\"測試商一\"}}"; - useEffect(() => { location.state?.responseData ?? {} onCaptchaChange(); @@ -84,7 +82,8 @@ const CustomFormWizard = (props) => { }, []); const responseToData = () => { - let rd = JSON.parse(dataStr); + //let rd = JSON.parse("{\"emailAddress\":\"test@gmail.com\",\"postalAddress\":{\"EngPremisesAddress\":{\"EngDistrict\":{\"DcDistrict\":\"KC\",\"Sub-district\":\"TSING YI\"},\"EngEstate\":{\"EstateName\":\"Cheung Hang Estate\",\"EngPhase\":{\"PhaseName\":\"N/A\"}},\"BuildingName\":\"Hang Lai House\",\"EngBlock\":{\"BlockDescriptor\":\"Block\",\"BlockNo\":\"2\"},\"Region\":\"NT\",\"EngStreet\":{\"StreetName\":\"Liu To Road\",\"BuildingNoFrom\":\"6\"},\"Eng3dAddress\":{\"EngFloor\":{\"FloorNum\":\"33\"},\"EngUnit\":{\"UnitDescriptor\":\"Room\",\"UnitNo\":\"3301\"}}}},\"mobileNumber\":{\"CountryCode\":\"852\",\"SubscriberNumber\":\"99999999\"},\"residentialAddress\":{\"ChiPremisesAddress\":{\"Chi3dAddress\":{\"ChiUnit\":{\"UnitDescriptor\":\"室\",\"UnitNo\":\"1010\"},\"ChiFloor\":{\"FloorNum\":\"10\"}},\"ChiBlock\":{\"BlockDescriptor\":\"座\",\"BlockNo\":\"2\"},\"BuildingName\":\"亨麗樓(第2座)\",\"ChiDistrict\":{\"DcDistrict\":\"KC\",\"Sub-district\":\"青衣\"},\"Region\":\"新界\",\"ChiEstate\":{\"EstateName\":\"長亨邨\"},\"ChiStreet\":{\"StreetName\":\"寮肚路\",\"BuildingNoFrom\":\"6\"}}},\"enName\":{\"UnstructuredName\":\"Testing Co One\"},\"idNo\":{\"Identification\":\"G561107\",\"CheckDigit\":\"4\"},\"chName\":{\"ChineseName\":\"測試商一\"}}"); + let rd = props.state.responseData; let data = { "enName": rd.enName?.UnstructuredName ?? "", "chName": rd.chName?.ChineseName ?? "", @@ -394,7 +393,7 @@ const CustomFormWizard = (props) => { 註有*的項目必須輸入資料。 - iAM Smart: 表示該項由「智方便」提供。 + iAM Smart: 表示該項由「智方便」提供。 @@ -441,6 +440,7 @@ const CustomFormWizard = (props) => { 地址 * + {iAmSmartData.address1?iAM Smart:null} { 電郵 * + {iAmSmartData.email?iAM Smart:null} { 聯絡電話 * + {iAmSmartData.phone?iAM Smart:null} diff --git a/src/pages/iAmSmart/AuthCallback/index.js b/src/pages/iAmSmart/AuthCallback/index.js index 0c03fbe..cefa70e 100644 --- a/src/pages/iAmSmart/AuthCallback/index.js +++ b/src/pages/iAmSmart/AuthCallback/index.js @@ -21,7 +21,7 @@ const Index = () => { let params = new URLSearchParams(window.location.search) if(params.get("code")){ HttpUtils.post({ - url: UrlUtils.GET_SMART_PROFILE, + url: UrlUtils.GET_SMART_LOGIN, params:{ code: params.get("code") }, diff --git a/src/pages/iAmSmart/RegistryCallback/index.js b/src/pages/iAmSmart/RegistryCallback/index.js new file mode 100644 index 0000000..0c03fbe --- /dev/null +++ b/src/pages/iAmSmart/RegistryCallback/index.js @@ -0,0 +1,43 @@ + +import * as React from "react"; +import * as HttpUtils from "utils/HttpUtils"; +import * as UrlUtils from "utils/ApiPathConst"; +import { useNavigate } from "react-router-dom"; +import Loadable from 'components/Loadable'; +const LoadingComponent = Loadable(React.lazy(() => import('pages/extra-pages/LoadingComponent'))); + + +// ==============================|| DASHBOARD - DEFAULT ||============================== // + +const Index = () => { + + const navigate = useNavigate() + + React.useEffect(() => { + getPrfile(); + }, []); + + function getPrfile(){ + let params = new URLSearchParams(window.location.search) + if(params.get("code")){ + HttpUtils.post({ + url: UrlUtils.GET_SMART_PROFILE, + params:{ + code: params.get("code") + }, + onSuccess: (responseData) => { + navigate('/iAmSmartRegisterFrom', { state: { responseData: responseData } }); + } + }); + } + } + + + + + return ( + + ); +}; + +export default Index; \ No newline at end of file diff --git a/src/routes/LoginRoutes.js b/src/routes/LoginRoutes.js index f32edfe..f3b857b 100644 --- a/src/routes/LoginRoutes.js +++ b/src/routes/LoginRoutes.js @@ -15,6 +15,7 @@ const ErrorPage = Loadable(lazy(() => import('pages/extra-pages/ErrorPage'))); const IAmSmart_FailCallback = Loadable(lazy(() => import('pages/iAmSmart/FailCallback'))); const IAmSmart_SuccessCallback = Loadable(lazy(() => import('pages/iAmSmart/SuccessCallback'))); const IAmSmart_AuthCallback = Loadable(lazy(() => import('pages/iAmSmart/AuthCallback'))); +const IAmSmart_RegistryCallback = Loadable(lazy(() => import('pages/iAmSmart/RegistryCallback'))); //TODO: this page for testing only, please remove at prod const TestMailPage = Loadable(lazy(() => import('pages/pnspsNotifyTest'))); @@ -58,6 +59,10 @@ const LoginRoutes = { path: 'iamsmart/authcallback', element: }, + { + path: 'iamsmart/registrycallback', + element: + }, { path: 'iamsmart/loginfallback', element: diff --git a/src/themes/palette.js b/src/themes/palette.js index 635de12..80eda43 100644 --- a/src/themes/palette.js +++ b/src/themes/palette.js @@ -83,6 +83,12 @@ const Palette = (mode) => { dark: '#b0671e', contrastText: '#fff', }, + iAmSmart: { + main: '#2B7366', + light: '#ff5e5e', + dark: '#b0671e', + contrastText: '#fff', + }, backgroundColor: { default: '#F2F2F2' } diff --git a/src/utils/ApiPathConst.js b/src/utils/ApiPathConst.js index 4a351ab..ec29d6f 100644 --- a/src/utils/ApiPathConst.js +++ b/src/utils/ApiPathConst.js @@ -106,4 +106,5 @@ export const POST_EMAIL_SAVE = apiPath+'/email/save'; export const DELETE_EMAIL = apiPath+'/email/delete'; //iAmSmart -export const GET_SMART_PROFILE = apiPath+'smart/getProfile'; //POST \ No newline at end of file +export const GET_SMART_PROFILE = apiPath+'smart/getProfile'; //POST +export const GET_SMART_LOGIN = apiPath+'smart/login'; //POST \ No newline at end of file