Skip to content

Commit

Permalink
Add ui_locales to login
Browse files Browse the repository at this point in the history
  • Loading branch information
mostekcm committed Jan 24, 2018
1 parent 7fd9fc2 commit 18f0ecc
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
13 changes: 10 additions & 3 deletions client/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ const webAuth = new auth0.WebAuth({ // eslint-disable-line no-undef
}
});

export function login(returnUrl) {
export function login(returnUrl, uiLocales) {
sessionStorage.setItem('delegated-admin:returnTo', returnUrl);

webAuth.authorize({
responseType: 'id_token',
redirectUri: `${window.config.BASE_URL}/login`,
scope: 'openid roles'
scope: 'openid roles',
ui_locales: uiLocales
});

return {
Expand Down Expand Up @@ -164,7 +165,13 @@ function getLanguageDictionary(response, onSuccess) {
if (_.isObject(settings.languageDictionary)) {
promise = Promise.resolve({ data: settings.languageDictionary });
} else if (_.isString(settings.languageDictionary) && settings.languageDictionary.startsWith('http')) {
promise = axios.get(settings.languageDictionary, { headers: {}, responseType: 'json' });
// Setting Authorization to None because we don't want to ship the token to some undeclared endpoint,
// especially if not enforcing https
promise = axios.get(settings.languageDictionary, { headers: { 'Authorization': 'None' }, responseType: 'json' })
.then((response) => {
if (response.data) return response;
return Promise.reject(new Error(`Language Dictionary endpoint: ${settings.languageDictionary} returned no data`));
});
} // ignore else, bad languageDictionary
}

Expand Down
2 changes: 1 addition & 1 deletion client/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Provider } from 'react-redux';

import { useRouterHistory } from 'react-router';
import { createHistory } from 'history';
import { push, routerMiddleware, syncHistoryWithStore } from 'react-router-redux';
import { routerMiddleware, syncHistoryWithStore } from 'react-router-redux';

import { loadCredentials } from './actions/auth';
import routes from './routes';
Expand Down
10 changes: 9 additions & 1 deletion client/components/Users/UsersTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ export default class UsersTable extends Component {
];

const connectionField = _.find(userFields, { property: 'connection' });
if (connectionField && (_.isFunction(connectionField.display) || (_.isBoolean(connectionField.display) && connectionField.display === true))) {
if (!connectionField) {
defaultListFields.push({
listOrder: 4,
listSize: '25%',
property: 'identities',
label: 'Connection',
display: (user, value) => value[0].connection
});
} else if (_.isFunction(connectionField.display) || (_.isBoolean(connectionField.display) && connectionField.display === true)) {
defaultListFields.push({
listOrder: 4,
listSize: '25%',
Expand Down
5 changes: 3 additions & 2 deletions client/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class App extends Component {
};

render() {
const { settingsLoading, languageDictionary } = this.props;
const { settingsLoading } = this.props;
const languageDictionary = this.props.languageDictionary && this.props.languageDictionary.toJS() || {};
if (settingsLoading) {
return <LoadingPanel show={settingsLoading} />;
}
Expand Down Expand Up @@ -80,7 +81,7 @@ function select(state) {
accessLevel: state.accessLevel.get('record'),
settings: state.settings.get('record'),
settingsLoading: state.settings.get('loading'),
languageDictionary: state.languageDictionary.get('record').toJS()
languageDictionary: state.languageDictionary.get('record')
};
}

Expand Down
4 changes: 2 additions & 2 deletions client/containers/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class LoginContainer extends Component {
if (this.props.auth.isAuthenticated) {
this.props.push(this.props.auth.returnTo || '/users');
} else if (!this.props.auth.isAuthenticating && !this.props.auth.error) {
this.props.login(this.props.location.query.returnUrl);
this.props.login(this.props.location.query.returnUrl, this.props.location.query.ui_locales);
}
}

login() {
this.props.login(this.props.location.query.returnUrl);
this.props.login(this.props.location.query.returnUrl, this.props.location.query.ui_locales);
}

render() {
Expand Down
9 changes: 5 additions & 4 deletions client/containers/RequireAuthentication.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';

Expand All @@ -8,7 +9,7 @@ export default function RequireAuthentication(InnerComponent) {
push: PropTypes.func.isRequired,
auth: PropTypes.object.isRequired,
location: PropTypes.object.isRequired
}
};

componentWillMount() {
this.requireAuthentication();
Expand All @@ -23,7 +24,7 @@ export default function RequireAuthentication(InnerComponent) {
if (!this.props.location) {
this.props.push('/login');
} else {
this.props.push(`/login?returnUrl=${this.props.location.pathname}`);
this.props.push(`/login?returnUrl=${this.props.location.pathname}${this.props.location.search ? this.props.location.search : ''}`);
}
}
}
Expand All @@ -37,5 +38,5 @@ export default function RequireAuthentication(InnerComponent) {
}
}

return connect((state) => ({ auth: state.auth.toJS() }), { push })(RequireAuthenticationContainer);
return connect((state) => ({ auth: state.auth.toJS() }))(RequireAuthenticationContainer);
}
3 changes: 2 additions & 1 deletion client/reducers/languageDictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import createReducer from '../utils/createReducer';
const initialState = {
loading: false,
error: null,
record: {}
record: { }
};

export const languageDictionary = createReducer(fromJS(initialState), { // eslint-disable-line
// import/prefer-default-export
[constants.FETCH_LANGUAGE_DICTIONARY_PENDING]: (state) =>
state.merge({
...initialState,
loading: true,
error: null
}),
Expand Down

0 comments on commit 18f0ecc

Please sign in to comment.