@@ -29,11 +29,12 @@ export const getTpaProvider = (tpaHintProvider, primaryProviders, secondaryProvi
|
||||
return tpaProvider;
|
||||
};
|
||||
|
||||
export const processTpaHintURL = (params) => {
|
||||
export const getTpaHint = () => {
|
||||
const params = QueryString.parse(window.location.search);
|
||||
let tpaHint = null;
|
||||
tpaHint = params.get('tpa_hint');
|
||||
tpaHint = params.tpa_hint;
|
||||
if (!tpaHint) {
|
||||
const next = params.get('next');
|
||||
const { next } = params;
|
||||
if (next) {
|
||||
const index = next.indexOf('tpa_hint=');
|
||||
if (index !== -1) {
|
||||
@@ -55,7 +56,7 @@ export const updatePathWithQueryParams = (path) => {
|
||||
};
|
||||
|
||||
export const getAllPossibleQueryParam = () => {
|
||||
const urlParams = QueryString.parse(document.location.search);
|
||||
const urlParams = QueryString.parse(window.location.search);
|
||||
const params = {};
|
||||
Object.entries(urlParams).forEach(([key, value]) => {
|
||||
if (AUTH_PARAMS.indexOf(key) > -1) {
|
||||
@@ -65,3 +66,9 @@ export const getAllPossibleQueryParam = () => {
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
export const getActivationStatus = () => {
|
||||
const params = QueryString.parse(window.location.search);
|
||||
|
||||
return params.account_activation_status;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
export {
|
||||
default,
|
||||
getTpaProvider,
|
||||
processTpaHintURL,
|
||||
getTpaHint,
|
||||
updatePathWithQueryParams,
|
||||
getAllPossibleQueryParam,
|
||||
getActivationStatus,
|
||||
} from './dataUtils';
|
||||
export { default as AsyncActionType } from './reduxUtils';
|
||||
|
||||
@@ -29,11 +29,11 @@ import {
|
||||
InstitutionLogistration, AuthnValidationFormGroup,
|
||||
} from '../common-components';
|
||||
import {
|
||||
DEFAULT_REDIRECT_URL, DEFAULT_STATE, LOGIN_PAGE, REGISTER_PAGE, ENTERPRISE_LOGIN_URL, PENDING_STATE,
|
||||
DEFAULT_STATE, LOGIN_PAGE, REGISTER_PAGE, ENTERPRISE_LOGIN_URL, PENDING_STATE,
|
||||
} from '../data/constants';
|
||||
import { forgotPasswordResultSelector } from '../forgot-password';
|
||||
import {
|
||||
getTpaProvider, processTpaHintURL, updatePathWithQueryParams, getAllPossibleQueryParam,
|
||||
getTpaProvider, getTpaHint, updatePathWithQueryParams, getAllPossibleQueryParam, getActivationStatus,
|
||||
} from '../data/utils';
|
||||
|
||||
class LoginPage extends React.Component {
|
||||
@@ -51,17 +51,15 @@ class LoginPage extends React.Component {
|
||||
institutionLogin: false,
|
||||
isSubmitted: false,
|
||||
};
|
||||
this.queryParams = getAllPossibleQueryParam();
|
||||
this.tpaHint = getTpaHint();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const params = (new URL(document.location)).searchParams;
|
||||
const payload = {
|
||||
redirect_to: params.get('next') || DEFAULT_REDIRECT_URL,
|
||||
};
|
||||
const payload = { ...this.queryParams };
|
||||
|
||||
const tpaHint = processTpaHintURL(params);
|
||||
if (tpaHint) {
|
||||
payload.tpa_hint = tpaHint;
|
||||
if (this.tpaHint) {
|
||||
payload.tpa_hint = this.tpaHint;
|
||||
}
|
||||
this.props.getThirdPartyAuthContext(payload);
|
||||
}
|
||||
@@ -92,10 +90,9 @@ class LoginPage extends React.Component {
|
||||
return;
|
||||
}
|
||||
|
||||
let payload = { email, password };
|
||||
const postParams = getAllPossibleQueryParam();
|
||||
|
||||
payload = { ...payload, ...postParams };
|
||||
const payload = {
|
||||
email, password, ...this.queryParams,
|
||||
};
|
||||
this.props.loginRequest(payload);
|
||||
}
|
||||
|
||||
@@ -148,16 +145,17 @@ class LoginPage extends React.Component {
|
||||
} return thirdPartyComponent;
|
||||
}
|
||||
|
||||
renderForm(params,
|
||||
renderForm(
|
||||
currentProvider,
|
||||
providers,
|
||||
secondaryProviders,
|
||||
thirdPartyAuthContext,
|
||||
thirdPartyAuthApiStatus,
|
||||
submitState,
|
||||
intl) {
|
||||
intl,
|
||||
) {
|
||||
const { email, errors, password } = this.state;
|
||||
const activationMsgType = params.get('account_activation_status');
|
||||
const activationMsgType = getActivationStatus();
|
||||
if (this.state.institutionLogin) {
|
||||
return (
|
||||
<InstitutionLogistration
|
||||
@@ -274,31 +272,30 @@ class LoginPage extends React.Component {
|
||||
} = this.props;
|
||||
const { currentProvider, providers, secondaryProviders } = this.props.thirdPartyAuthContext;
|
||||
|
||||
const params = (new URL(window.location.href)).searchParams;
|
||||
|
||||
const tpaHint = processTpaHintURL(params);
|
||||
if (tpaHint) {
|
||||
if (this.tpaHint) {
|
||||
if (thirdPartyAuthApiStatus === PENDING_STATE) {
|
||||
return <Skeleton height={36} />;
|
||||
}
|
||||
const provider = getTpaProvider(tpaHint, providers, secondaryProviders);
|
||||
return provider ? (<EnterpriseSSO provider={provider} intl={intl} />) : this.renderForm(params,
|
||||
const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
return provider ? (<EnterpriseSSO provider={provider} intl={intl} />) : this.renderForm(
|
||||
currentProvider,
|
||||
providers,
|
||||
secondaryProviders,
|
||||
thirdPartyAuthContext,
|
||||
thirdPartyAuthApiStatus,
|
||||
submitState,
|
||||
intl);
|
||||
intl,
|
||||
);
|
||||
}
|
||||
return this.renderForm(params,
|
||||
return this.renderForm(
|
||||
currentProvider,
|
||||
providers,
|
||||
secondaryProviders,
|
||||
thirdPartyAuthContext,
|
||||
thirdPartyAuthApiStatus,
|
||||
submitState,
|
||||
intl);
|
||||
intl,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ describe('LoginPage', () => {
|
||||
|
||||
it('should show account activation message', () => {
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login?account_activation_status=info') };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?account_activation_status=info' };
|
||||
|
||||
const expectedMessage = 'This account has already been activated.';
|
||||
|
||||
@@ -429,7 +429,7 @@ describe('LoginPage', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${appleProvider.id}`) };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
|
||||
appleProvider.iconImage = null;
|
||||
|
||||
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
|
||||
@@ -451,7 +451,7 @@ describe('LoginPage', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login?next=/dashboard&tpa_hint=invalid') };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?next=/dashboard&tpa_hint=invalid' };
|
||||
appleProvider.iconImage = null;
|
||||
|
||||
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
|
||||
@@ -473,7 +473,7 @@ describe('LoginPage', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${secondaryProviders.id}`) };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
|
||||
secondaryProviders.iconImage = null;
|
||||
|
||||
const loginPage = mount(reduxWrapper(<IntlLoginPage {...props} />));
|
||||
|
||||
@@ -29,10 +29,10 @@ import { getThirdPartyAuthContext } from '../common-components/data/actions';
|
||||
import { thirdPartyAuthContextSelector } from '../common-components/data/selectors';
|
||||
import EnterpriseSSO from '../common-components/EnterpriseSSO';
|
||||
import {
|
||||
DEFAULT_REDIRECT_URL, DEFAULT_STATE, LOGIN_PAGE, PENDING_STATE, REGISTER_PAGE,
|
||||
DEFAULT_STATE, LOGIN_PAGE, PENDING_STATE, REGISTER_PAGE,
|
||||
} from '../data/constants';
|
||||
import {
|
||||
getTpaProvider, processTpaHintURL, updatePathWithQueryParams, getAllPossibleQueryParam,
|
||||
getTpaProvider, getTpaHint, updatePathWithQueryParams, getAllPossibleQueryParam,
|
||||
} from '../data/utils';
|
||||
|
||||
class RegistrationPage extends React.Component {
|
||||
@@ -41,6 +41,8 @@ class RegistrationPage extends React.Component {
|
||||
|
||||
sendPageEvent('login_and_registration', 'register');
|
||||
this.intl = props.intl;
|
||||
this.queryParams = getAllPossibleQueryParam();
|
||||
this.tpaHint = getTpaHint();
|
||||
|
||||
this.state = {
|
||||
email: '',
|
||||
@@ -77,14 +79,10 @@ class RegistrationPage extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const params = (new URL(document.location)).searchParams;
|
||||
const payload = {
|
||||
redirect_to: params.get('next') || DEFAULT_REDIRECT_URL,
|
||||
};
|
||||
const payload = { ...this.queryParams };
|
||||
|
||||
const tpaHint = processTpaHintURL(params);
|
||||
if (tpaHint) {
|
||||
payload.tpa_hint = tpaHint;
|
||||
if (this.tpaHint) {
|
||||
payload.tpa_hint = this.tpaHint;
|
||||
}
|
||||
this.props.getThirdPartyAuthContext(payload);
|
||||
}
|
||||
@@ -624,14 +622,11 @@ class RegistrationPage extends React.Component {
|
||||
currentProvider, finishAuthUrl, providers, secondaryProviders,
|
||||
} = this.props.thirdPartyAuthContext;
|
||||
|
||||
const params = (new URL(window.location.href)).searchParams;
|
||||
const tpaHint = processTpaHintURL(params);
|
||||
|
||||
if (tpaHint) {
|
||||
if (this.tpaHint) {
|
||||
if (thirdPartyAuthApiStatus === PENDING_STATE) {
|
||||
return <Skeleton height={36} />;
|
||||
}
|
||||
const provider = getTpaProvider(tpaHint, providers, secondaryProviders);
|
||||
const provider = getTpaProvider(this.tpaHint, providers, secondaryProviders);
|
||||
return provider ? (<EnterpriseSSO provider={provider} intl={intl} />)
|
||||
: this.renderForm(
|
||||
currentProvider,
|
||||
|
||||
@@ -654,7 +654,7 @@ describe('RegistrationPageTests', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${appleProvider.id}`) };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${appleProvider.id}` };
|
||||
appleProvider.iconImage = null;
|
||||
|
||||
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
|
||||
@@ -676,7 +676,7 @@ describe('RegistrationPageTests', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login?next=/dashboard&tpa_hint=invalid') };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: '?next=/dashboard&tpa_hint=invalid' };
|
||||
appleProvider.iconImage = null;
|
||||
|
||||
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
|
||||
@@ -698,7 +698,7 @@ describe('RegistrationPageTests', () => {
|
||||
});
|
||||
|
||||
delete window.location;
|
||||
window.location = { href: getConfig().BASE_URL.concat(`/login?next=/dashboard&tpa_hint=${secondaryProviders.id}`) };
|
||||
window.location = { href: getConfig().BASE_URL.concat('/login'), search: `?next=/dashboard&tpa_hint=${secondaryProviders.id}` };
|
||||
secondaryProviders.iconImage = null;
|
||||
|
||||
const registerPage = mount(reduxWrapper(<IntlRegistrationPage {...props} />));
|
||||
|
||||
Reference in New Issue
Block a user