Merged PR 672: Update cookies manager functions and added in Gov Gateway
Related work items: #5255, #6936, #6937, #6938
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ class MyDocument extends Document {
|
||||
let hasBasicAuth =
|
||||
typeof process.env.BASIC_AUTH_CREDENTIALS != "undefined";
|
||||
|
||||
console.log(hasBasicAuth);
|
||||
console.log("hasbasicAuth:", hasBasicAuth);
|
||||
|
||||
if (ctx.req && ctx.res) {
|
||||
hasBasicAuth &&
|
||||
|
||||
+30
-12
@@ -17,9 +17,10 @@ import jsonpath from "jsonpath";
|
||||
import { reduxForm, formValueSelector } from "redux-form";
|
||||
|
||||
import RegisterForm from "../../components/account/registerform";
|
||||
import { dehashString, hashAPIPath } from "../../actions";
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, formData } = props;
|
||||
const { footerLinks, formData, loggedInUserEmail } = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
@@ -97,6 +98,9 @@ const Home = (props) => {
|
||||
setAccountCreatedComplete={
|
||||
setAccountCreatedComplete
|
||||
}
|
||||
loggedInUserEmail={
|
||||
loggedInUserEmail
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{registerFormComplete != true ||
|
||||
@@ -151,17 +155,31 @@ const Home = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
// export const getServerSideProps = wrapper.getServerSideProps(
|
||||
// (store) =>
|
||||
// async ({ query, req, res }) => {
|
||||
// const appealTypeData = await getAppealsTypes();
|
||||
// const lpaData = await getLPA();
|
||||
// console.log("appeal types", appealTypeData);
|
||||
// console.log("lpa typeswwwww", lpaData);
|
||||
// store.dispatch(setAppealType(appealTypeData));
|
||||
// store.dispatch(setLPA(lpaData));
|
||||
// }
|
||||
// );
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) =>
|
||||
async ({ query, req, res }) => {
|
||||
// const appealTypeData = await getAppealsTypes();
|
||||
// const lpaData = await getLPA();
|
||||
// console.log("appeal types", appealTypeData);
|
||||
// console.log("lpa typeswwwww", lpaData);
|
||||
// store.dispatch(setAppealType(appealTypeData));
|
||||
// store.dispatch(setLPA(lpaData));
|
||||
|
||||
let hasRegistrationEmail = typeof query.id != "undefined";
|
||||
let loginEmailStr = "";
|
||||
|
||||
if (hasRegistrationEmail == true) {
|
||||
loginEmailStr = dehashString(query.id);
|
||||
|
||||
console.log(loginEmailStr);
|
||||
}
|
||||
return {
|
||||
props: {
|
||||
loggedInUserEmail: loginEmailStr,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
|
||||
+138
-8
@@ -13,16 +13,68 @@ import { useSelector, shallowEqual, connect } from "react-redux";
|
||||
import { wrapper } from "../store/store";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import { getIncidents } from "../actions";
|
||||
import { parseCookies } from "nookies";
|
||||
import { getIncidents, hashString } from "../actions";
|
||||
import CryptoJS from "crypto-js";
|
||||
import HmacSHA256 from "crypto-js/hmac-sha256";
|
||||
|
||||
import {
|
||||
getProviderConfig,
|
||||
getGGToken,
|
||||
getUserInfo,
|
||||
getPortalLogin,
|
||||
} from "../actions/govgateway";
|
||||
import { getToken } from "../actions";
|
||||
import { getGovGatewayConfig } from "../store/govgateway/action";
|
||||
import {
|
||||
setLoggedInUserId,
|
||||
setAccountDetails,
|
||||
} from "../store/accountDetails/action";
|
||||
import { parseCookies, setCookie, destroyCookie } from "nookies";
|
||||
|
||||
const WORDKEY = process.env.NEXT_PUBLIC_HASHKEY;
|
||||
|
||||
const Home = (props) => {
|
||||
const { footerLinks, pages, showLogin } = props;
|
||||
const {
|
||||
footerLinks,
|
||||
pages,
|
||||
showLogin,
|
||||
loggedInUserId,
|
||||
hasGGCode,
|
||||
loginEmailStr,
|
||||
loggedInUserEmail,
|
||||
} = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
let now = new Date();
|
||||
let expDate = new Date(now);
|
||||
expDate.setDate(now.getDate() + 1);
|
||||
|
||||
console.log("hashed email str", loginEmailStr);
|
||||
_.isEmpty(loggedInUserId) != false && !hasGGCode
|
||||
? console.log("no log in no ggcode")
|
||||
: _.has(loggedInUserId, "value")
|
||||
? _.isEmpty(loggedInUserId.value)
|
||||
? router.replace({
|
||||
pathname:
|
||||
router.locale == "cy"
|
||||
? "/account/register"
|
||||
: "/account/register",
|
||||
query: {
|
||||
id: encodeURI(loggedInUserEmail),
|
||||
},
|
||||
})
|
||||
: (setCookie(null, "pinsUser", loggedInUserId.value[0].contactid, {
|
||||
path: "/",
|
||||
expires: expDate,
|
||||
}),
|
||||
router.replace({
|
||||
pathname: router.locale == "cy" ? "/fymhorth" : "/myportal",
|
||||
}))
|
||||
: console.log("no value in user id");
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
@@ -77,8 +129,21 @@ const Home = (props) => {
|
||||
<CookieBanner />
|
||||
<Header courseName="Appeals Casework Portal" />
|
||||
<div className="govuk-width-container">
|
||||
<ServiceBanner />
|
||||
<Main pages={pages} showLogin={showLogin} />
|
||||
{hasGGCode ? (
|
||||
<>
|
||||
<h1>Logging in</h1>
|
||||
<h2>Please wait...</h2>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ServiceBanner />
|
||||
<Main
|
||||
pages={pages}
|
||||
showLogin={showLogin}
|
||||
loggedInUserId={loggedInUserId}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} />
|
||||
</div>
|
||||
@@ -90,13 +155,78 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
|
||||
var relayToken = await getToken();
|
||||
relayToken = relayToken.access_token;
|
||||
|
||||
console.log("gg code:", query.code);
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
|
||||
console.log("Show login module: ", showLoginCheck);
|
||||
const hasLoginCode = typeof query.code != "undefined";
|
||||
let providerConfig = await getProviderConfig();
|
||||
|
||||
console.log(
|
||||
"endpoint: ",
|
||||
providerConfig.token_endpoint,
|
||||
"\n",
|
||||
"hasloginCode:",
|
||||
hasLoginCode
|
||||
);
|
||||
|
||||
store.dispatch(getGovGatewayConfig(providerConfig));
|
||||
|
||||
let ggUserInfo = {};
|
||||
let portalUserObj = {};
|
||||
let loginEmailStr = "";
|
||||
|
||||
if (hasLoginCode == true) {
|
||||
const ggToken = await getGGToken(
|
||||
providerConfig.token_endpoint,
|
||||
query.code,
|
||||
process.env.GG_REDIRECT_URI
|
||||
);
|
||||
|
||||
_.has(ggToken, "access_token")
|
||||
? ((ggUserInfo = await getUserInfo(
|
||||
providerConfig.userinfo_endpoint,
|
||||
ggToken.access_token
|
||||
)),
|
||||
(loginEmailStr = hashString(ggUserInfo.data.email)),
|
||||
(portalUserObj = await getPortalLogin(
|
||||
ggUserInfo.data.email,
|
||||
relayToken
|
||||
)),
|
||||
console.log("loggin user stuff: ", portalUserObj),
|
||||
store.dispatch(setAccountDetails(portalUserObj)))
|
||||
: console.log(
|
||||
ggToken.status + " " + ggToken.data.error_description
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
props: { showLogin: showLoginCheck },
|
||||
props: {
|
||||
showLogin: showLoginCheck,
|
||||
hasGGCode: hasLoginCode,
|
||||
loggedInUserId: portalUserObj,
|
||||
loggedInUserEmail: loginEmailStr,
|
||||
},
|
||||
};
|
||||
}
|
||||
);
|
||||
export default Home; //connect(mapStateToProps)(Home);
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
currentView: state.currentView,
|
||||
search: state.search,
|
||||
searchResultsObj: state.searchResultsObj,
|
||||
formData: state.formData,
|
||||
appealType: state.appealType,
|
||||
form: state.form,
|
||||
myCases: state.myCases,
|
||||
watchedCases: state.watchedCases,
|
||||
myRepresentations: state.myRepresentations,
|
||||
awaitingSubmission: state.awaitingSubmission,
|
||||
govGateway: state.govGateway,
|
||||
};
|
||||
};
|
||||
export default connect(mapStateToProps)(Home);
|
||||
|
||||
+11
-11
@@ -85,20 +85,20 @@ const Home = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getServerSideProps = wrapper.getServerSideProps(
|
||||
(store) => async (ctx) => {
|
||||
const { query, req, res } = ctx;
|
||||
// export const getServerSideProps = wrapper.getServerSideProps(
|
||||
// (store) => async (ctx) => {
|
||||
// const { query, req, res } = ctx;
|
||||
|
||||
const showRepresentationsCheck =
|
||||
process.env.SHOWREPRESENTATIONS || false;
|
||||
// const showRepresentationsCheck =
|
||||
// process.env.SHOWREPRESENTATIONS || false;
|
||||
|
||||
console.log("Show representation module: ", showRepresentationsCheck);
|
||||
// console.log("Show representation module: ", showRepresentationsCheck);
|
||||
|
||||
return {
|
||||
props: { showRepresentations: showRepresentationsCheck },
|
||||
};
|
||||
}
|
||||
);
|
||||
// return {
|
||||
// props: { showRepresentations: showRepresentationsCheck },
|
||||
// };
|
||||
// }
|
||||
// );
|
||||
|
||||
const mapStateToProps = (state) => {
|
||||
//console.log(state);
|
||||
|
||||
Reference in New Issue
Block a user