Local auth seems to work
This commit is contained in:
parent
d79bbad575
commit
9758b4b104
34 changed files with 199 additions and 141 deletions
|
@ -16,34 +16,34 @@
|
|||
"license": "GPL-3.0",
|
||||
"homepage": "https://mailtrain.org/",
|
||||
"dependencies": {
|
||||
"axios": "^0.16.1",
|
||||
"axios": "^0.16.2",
|
||||
"datatables.net": "^1.10.15",
|
||||
"datatables.net-bs": "^1.10.15",
|
||||
"datatables.net-select": "^1.2.2",
|
||||
"datatables.net-select-bs": "^1.2.2",
|
||||
"i18next": "^8.3.0",
|
||||
"i18next-xhr-backend": "^1.4.1",
|
||||
"i18next": "^8.4.3",
|
||||
"i18next-xhr-backend": "^1.4.2",
|
||||
"immutable": "^3.8.1",
|
||||
"owasp-password-strength-test": "github:bures/owasp-password-strength-test",
|
||||
"prop-types": "^15.5.10",
|
||||
"react": "^15.5.4",
|
||||
"react-dom": "^15.5.4",
|
||||
"react-i18next": "^4.1.0",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-i18next": "^4.6.1",
|
||||
"react-router-dom": "^4.1.1",
|
||||
"url-parse": "^1.1.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-loader": "^7.0.0",
|
||||
"babel-loader": "^7.1.1",
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.4",
|
||||
"babel-plugin-transform-function-bind": "^6.22.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"babel-preset-stage-1": "^6.24.1",
|
||||
"css-loader": "^0.28.3",
|
||||
"css-loader": "^0.28.4",
|
||||
"i18next-conv": "^3.0.3",
|
||||
"style-loader": "^0.18.1",
|
||||
"url-loader": "^0.5.8",
|
||||
"style-loader": "^0.18.2",
|
||||
"url-loader": "^0.5.9",
|
||||
"webpack": "^2.6.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { translate, Trans } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import URL from 'url-parse';
|
||||
|
@ -23,7 +23,9 @@ export default class API extends Component {
|
|||
@withAsyncErrorHandler
|
||||
async loadAccessToken() {
|
||||
const response = await axios.get('/rest/access-token');
|
||||
this.setState('accessToken', response.data);
|
||||
this.setState({
|
||||
accessToken: response.data
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -32,7 +34,9 @@ export default class API extends Component {
|
|||
|
||||
async resetAccessToken() {
|
||||
const response = await axios.post('/rest/access-token-reset');
|
||||
this.setState('accessToken', response.data);
|
||||
this.setState({
|
||||
accessToken: response.data
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
@ -42,33 +46,36 @@ export default class API extends Component {
|
|||
const serviceUrl = thisUrl.origin + '/';
|
||||
const accessToken = this.state.accessToken || 'ACCESS_TOKEN';
|
||||
|
||||
let accessTokenMsg;
|
||||
if (this.state.accessToken) {
|
||||
accessTokenMsg = <div>{t('Personal access token') + ': '}<code>{accessToken}</code></div>;
|
||||
} else {
|
||||
accessTokenMsg = <div>{t('Access token not yet generated')}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Title>{t('Sign in')}</Title>
|
||||
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<div class="pull-right">
|
||||
<div className="panel panel-default">
|
||||
<div className="panel-body">
|
||||
<div className="pull-right">
|
||||
<Button label={this.state.accessToken ? t('Reset Access Token') : t('Generate Access Token')} icon="retweet" className="btn-info" onClickAsync={::this.resetAccessToken} />
|
||||
</div>
|
||||
{ this.state.accessToken ?
|
||||
<div>{t('Personal access token:')} <code>{accessToken}</code></div>
|
||||
:
|
||||
<div>{t('Access token not yet generated')}</div>
|
||||
}
|
||||
{accessTokenMsg}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="well">
|
||||
<div className="well">
|
||||
<h3>{t('Notes about the API')}</h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
{t('API response is a JSON structure with <code>error</code> and <code>data</code> properties. If the response <code>error</code> has a value set then the request failed.')}
|
||||
<Trans>API response is a JSON structure with <code>error</code> and <code>data</code> properties. If the response <code>error</code> has a value set then the request failed.</Trans>
|
||||
</li>
|
||||
<li>
|
||||
{t('You need to define proper <code>Content-Type</code> when making a request. You can either use <code>application/x-www-form-urlencoded</code> for normal form data or <code>application/json</code> for a JSON payload. Using <code>multipart/form-data</code> is not supported.')}
|
||||
<Trans>You need to define proper <code>Content-Type</code> when making a request. You can either use <code>application/x-www-form-urlencoded</code> for normal form data or <code>application/json</code> for a JSON payload. Using <code>multipart/form-data</code> is not supported.</Trans>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -183,9 +190,11 @@ export default class API extends Component {
|
|||
</p>
|
||||
<ul>
|
||||
<li><strong>access_token</strong> – {t('your personal access token')}
|
||||
<ul>
|
||||
<li><strong>start</strong> – {t('Start position')} (<em>{t('optional, default 0')}</em>)</li>
|
||||
<li><strong>limit</strong> – {t('limit emails count in response')} (<em>{t('optional, default 10000')}</em>)</li>
|
||||
<li><strong>search</strong> – {t('filter by part of email')} (<em>{t('optional, default ""')}</em>)</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from '../lib/form';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import passwordValidator from '../../../shared/password-validator';
|
||||
import interoperableErrors from '../../../shared/interoperable-errors';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
@translate()
|
||||
|
@ -120,6 +121,7 @@ export default class Account extends Component {
|
|||
|
||||
this.clearFormStatusMessage();
|
||||
} else {
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('warning', t('There are errors in the form. Please fix them and submit again.'));
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
@ -47,7 +47,7 @@ export default class Forget extends Component {
|
|||
const submitSuccessful = await this.validateAndSendFormValuesToURL(FormSendMethod.POST, '/rest/password-reset-send');
|
||||
|
||||
if (submitSuccessful) {
|
||||
this.navigateToWithFlashMessage('/login', 'success', t('If the username / email exists in the system, password reset link will be sent to the registered email.'));
|
||||
this.navigateToWithFlashMessage('/account/login', 'success', t('If the username / email exists in the system, password reset link will be sent to the registered email.'));
|
||||
} else {
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('warning', t('Please enter your username / email and try again.'));
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
} from '../lib/form';
|
||||
import { withErrorHandling } from '../lib/error-handling';
|
||||
import URL from 'url-parse';
|
||||
import interoperableErrors from '../../../shared/interoperable-errors';
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
|
||||
@translate()
|
||||
|
@ -61,9 +62,10 @@ export default class Login extends Component {
|
|||
|
||||
if (submitSuccessful) {
|
||||
const query = new URL(this.props.location.search, true).query;
|
||||
const nextUrl = query.next || '/';
|
||||
|
||||
/* FIXME, once we turn Mailtrain to single-page application, this should become navigateTo */
|
||||
window.location = query.next;
|
||||
window.location = nextUrl;
|
||||
} else {
|
||||
this.setFormStatusMessage('warning', t('Please enter your credentials and try again.'));
|
||||
}
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
import React, { Component } from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { withPageHelpers, Title } from '../lib/page'
|
||||
import { Link } from 'react-router-dom'
|
||||
import {
|
||||
withForm, Form, Fieldset, FormSendMethod, InputField, ButtonRow, Button
|
||||
} from '../lib/form';
|
||||
import { withErrorHandling, withAsyncErrorHandler } from '../lib/error-handling';
|
||||
import passwordValidator from '../../../shared/password-validator';
|
||||
import axios from '../lib/axios';
|
||||
import interoperableErrors from '../../../shared/interoperable-errors';
|
||||
|
||||
const ResetTokenValidationState = {
|
||||
PENDING: 0,
|
||||
|
@ -34,7 +36,7 @@ export default class Account extends Component {
|
|||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async loadAccessToken() {
|
||||
async validateResetToken() {
|
||||
const params = this.props.match.params;
|
||||
|
||||
const response = await axios.post('/rest/password-reset-validate', {
|
||||
|
@ -42,7 +44,9 @@ export default class Account extends Component {
|
|||
resetToken: params.resetToken
|
||||
});
|
||||
|
||||
this.setState('resetTokenValidationState', response.data ? ResetTokenValidationState.VALID : ResetTokenValidationState.INVALID);
|
||||
this.setState({
|
||||
resetTokenValidationState: response.data ? ResetTokenValidationState.VALID : ResetTokenValidationState.INVALID
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -54,6 +58,8 @@ export default class Account extends Component {
|
|||
password: '',
|
||||
password2: ''
|
||||
});
|
||||
|
||||
this.validateResetToken();
|
||||
}
|
||||
|
||||
localValidateFormValues(state) {
|
||||
|
@ -64,7 +70,7 @@ export default class Account extends Component {
|
|||
|
||||
let passwordMsgs = [];
|
||||
|
||||
if (password || currentPassword) {
|
||||
if (password) {
|
||||
const passwordResults = this.passwordValidator.test(password);
|
||||
passwordMsgs.push(...passwordResults.errors);
|
||||
}
|
||||
|
@ -91,6 +97,7 @@ export default class Account extends Component {
|
|||
if (submitSuccessful) {
|
||||
this.navigateToWithFlashMessage('/account/login', 'success', t('Password reset'));
|
||||
} else {
|
||||
this.enableForm();
|
||||
this.setFormStatusMessage('warning', t('There are errors in the form. Please fix them and submit again.'));
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -98,7 +105,7 @@ export default class Account extends Component {
|
|||
this.setFormStatusMessage('danger',
|
||||
<span>
|
||||
<strong>{t('Your password cannot be reset.')}</strong>{' '}
|
||||
{t('The reset token has expired.')}{' '}<Link to={`/account/forgot/${this.getFormValue('username')}`}>{t('Click here to request a new password reset link.')}</Link>
|
||||
{t('The password reset token has expired.')}{' '}<Link to={`/account/forgot/${this.getFormValue('username')}`}>{t('Click here to request a new password reset link.')}</Link>
|
||||
</span>
|
||||
);
|
||||
return;
|
||||
|
@ -113,9 +120,17 @@ export default class Account extends Component {
|
|||
|
||||
if (this.state.resetTokenValidationState === ResetTokenValidationState.PENDING) {
|
||||
return (
|
||||
<div>{t('Validating password reset token ...')}</div>
|
||||
)
|
||||
<p>{t('Validating password reset token ...')}</p>
|
||||
);
|
||||
|
||||
} else if (this.state.resetTokenValidationState === ResetTokenValidationState.INVALID) {
|
||||
return (
|
||||
<div>
|
||||
<Title>{t('The password cannot be reset')}</Title>
|
||||
|
||||
<p>{t('The password reset token has expired.')}{' '}<Link to={`/account/forgot/${this.getFormValue('username')}`}>{t('Click here to request a new password reset link.')}</Link></p>
|
||||
</div>
|
||||
);
|
||||
|
||||
} else {
|
||||
return (
|
||||
|
|
|
@ -64,7 +64,7 @@ const getStructure = t => {
|
|||
|
||||
export default function() {
|
||||
ReactDOM.render(
|
||||
<I18nextProvider i18n={ i18n }><Section root='/account' structure={getStructure}/></I18nextProvider>,
|
||||
<I18nextProvider i18n={ i18n }><Section root='/account/login' structure={getStructure}/></I18nextProvider>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
};
|
||||
|
|
|
@ -194,7 +194,7 @@ class CheckBox extends Component {
|
|||
const htmlId = 'form_' + id;
|
||||
|
||||
return wrapInputInline(id, htmlId, owner, 'checkbox', props.label, props.help,
|
||||
<input type="checkbox" checked={owner.getFormValue(id)} id={htmlId} aria-describedby={htmlId + '_help'} onChange={evt => {console.log(evt); /* FIXME owner.updateFormValue(id, evt.target.value)*/ }}/>
|
||||
<input type="checkbox" checked={owner.getFormValue(id)} id={htmlId} aria-describedby={htmlId + '_help'} onClick={evt => owner.updateFormValue(id, !owner.getFormValue(id))}/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ const getStructure = t => {
|
|||
render: props => (<CUD edit {...props} />)
|
||||
};
|
||||
|
||||
subPahts.create = {
|
||||
subPaths.create = {
|
||||
title: t('Create User'),
|
||||
render: props => (<CUD {...props} />)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue