Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react';
import appendQuery from 'append-query';
import PropTypes from 'prop-types';
import isBrandConsolidationEnabled from '../../../../platform/brand-consolidation/feature-flag';
import CallVBACenter from '../../../../platform/brand-consolidation/components/CallVBACenter';
import disabilityIncreaseManifest from '../../526EZ/manifest.json';
const propertyName = isBrandConsolidationEnabled() ? 'VA.gov' : 'Vets.gov';
const { rootUrl: increaseRootUrl } = disabilityIncreaseManifest;
import { profileStatuses } from '../helpers';
const { SERVER_ERROR, NOT_FOUND } = profileStatuses;
const nextQuery = { next: window.location.pathname };
const signInUrl = appendQuery('/', nextQuery);
const verifyUrl = appendQuery('/verify', nextQuery);
export default class AuthorizationMessage extends React.Component {
redirectToAuthentication = () => {
if (!this.props.user.isLoggedIn) window.location.replace(signInUrl);
else if (!this.props.user.isVerified) window.location.replace(verifyUrl);
};
// eslint-disable-next-line consistent-return
render() {
const {
has30PercentDisabilityRating,
user: { profileStatus, isLoggedIn, isVerified },
} = this.props;
if (profileStatus === SERVER_ERROR) {
// If va_profile is null, show a system down message.
import appendQuery from 'append-query';
import PropTypes from 'prop-types';
import React from 'react';
import { intersection } from 'lodash';
import LoadingIndicator from '@department-of-veterans-affairs/formation-react/LoadingIndicator';
import SystemDownView from '@department-of-veterans-affairs/formation-react/SystemDownView';
import SubmitSignInForm from '../../../static-data/SubmitSignInForm';
import backendServices from '../../profile/constants/backendServices';
import { hasSession } from '../../profile/utilities';
const nextQuery = { next: window.location.pathname };
const signInUrl = appendQuery('/', nextQuery);
const verifyUrl = appendQuery('/verify', nextQuery);
class RequiredLoginView extends React.Component {
componentDidMount() {
this.redirectIfNeeded();
}
componentDidUpdate() {
this.redirectIfNeeded();
}
shouldSignIn = () => !this.props.user.login.currentlyLoggedIn;
shouldVerify = () => {
const { user, verify } = this.props;
// Certain sign-in methods can grant access to the service,
const { accountState } = this.props.mhvAccount;
// Unverified accounts should have been handled before this component
// rendered, but if it hasn't for some reason, we will redirect now.
if (accountState === 'needs_identity_verification') {
const nextQuery = { next: window.location.pathname };
const verifyUrl = appendQuery('/verify', nextQuery);
window.location.replace(verifyUrl);
return;
}
switch (accountState) {
case 'needs_terms_acceptance': {
const redirectQuery = { tc_redirect: window.location.pathname }; // eslint-disable-line camelcase
const termsConditionsUrl = appendQuery('/health-care/medical-information-terms-conditions', redirectQuery);
window.location.replace(termsConditionsUrl);
break;
}
case 'no_account':
this.props.createMHVAccount();
break;
case 'existing':
case 'registered':
this.props.upgradeMHVAccount();
break;
case 'upgraded': {
const forceCacheClear = true;
this.props.refreshProfile(forceCacheClear);
const redirectToTermsAndConditions = () => {
const redirectQuery = { tc_redirect: window.location.pathname }; // eslint-disable-line camelcase
const termsConditionsUrl = appendQuery(
'/health-care/medical-information-terms-conditions/',
redirectQuery,
);
window.location = termsConditionsUrl;
};
export function fetchProgramAutocompleteSuggestions(term, version) {
const url = appendQuery(`${api.url}/institution_programs/autocomplete`, {
term,
version,
});
return dispatch =>
fetch(url, api.settings)
.then(res => res.json())
.then(
payload => dispatch({ type: AUTOCOMPLETE_SUCCEEDED, payload }),
err => dispatch({ type: AUTOCOMPLETE_FAILED, err }),
);
}
import appendQuery from 'append-query';
import PropTypes from 'prop-types';
import React from 'react';
import { intersection } from 'lodash';
import LoadingIndicator from '@department-of-veterans-affairs/formation-react/LoadingIndicator';
import SystemDownView from '@department-of-veterans-affairs/formation-react/SystemDownView';
import SubmitSignInForm from '../../../static-data/SubmitSignInForm';
import backendServices from '../../profile/constants/backendServices';
import { hasSession } from '../../profile/utilities';
const nextQuery = { next: window.location.pathname };
const signInUrl = appendQuery('/', nextQuery);
const verifyUrl = appendQuery('/verify', nextQuery);
class RequiredLoginView extends React.Component {
componentDidMount() {
this.redirectIfNeeded();
}
componentDidUpdate() {
this.redirectIfNeeded();
}
shouldSignIn = () => !this.props.user.login.currentlyLoggedIn;
shouldVerify = () => {
const { user, verify } = this.props;
.then(response => {
const data = isJson(response)
? response.json()
: Promise.resolve(response);
if (!response.ok) {
const { pathname } = window.location;
const shouldRedirectToLogin =
response.status === 401 && !pathname.includes('auth/login/callback');
if (shouldRedirectToLogin) {
const loginUrl = appendQuery(environment.BASE_URL, {
next: pathname,
});
window.location.href = loginUrl;
}
return data.then(Promise.reject.bind(Promise));
}
return data;
})
.then(success)
onClick = () => {
if (this.props.user.login.currentlyLoggedIn) {
this.setState({ isEnrolling: true });
this.props.registerBeta(this.props.feature).then(this.onRegistered).catch(this.onError);
} else {
const nextQuery = { next: window.location.pathname };
const signInUrl = appendQuery('/', nextQuery);
window.location.replace(signInUrl);
}
}
export function fetchInstitutionAutocompleteSuggestions(term, version) {
const url = appendQuery(`${api.url}/institutions/autocomplete`, {
term,
version,
});
return dispatch =>
fetch(url, api.settings)
.then(res => res.json())
.then(
payload => dispatch({ type: AUTOCOMPLETE_SUCCEEDED, payload }),
err => dispatch({ type: AUTOCOMPLETE_FAILED, err }),
);
}
authenticate = e => {
e.preventDefault();
const nextQuery = { next: e.target.getAttribute('href') };
const nextPath = appendQuery('/', nextQuery);
history.pushState({}, e.target.textContent, nextPath);
this.props.toggleLoginModal(true);
};