2015-06-15 16:56:17 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-10-01 11:16:38 +02:00
|
|
|
import { History } from 'react-router';
|
2015-06-15 16:56:17 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
import Form from './ascribe_forms/form';
|
|
|
|
import Property from './ascribe_forms/property';
|
2015-08-07 15:08:02 +02:00
|
|
|
import ApiUrls from '../constants/api_urls';
|
2015-10-12 17:55:02 +02:00
|
|
|
import AscribeSpinner from './ascribe_spinner';
|
2015-06-15 16:56:17 +02:00
|
|
|
|
|
|
|
import GlobalNotificationModel from '../models/global_notification_model';
|
|
|
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
2015-07-01 18:58:13 +02:00
|
|
|
import { getLangText } from '../utils/lang_utils';
|
2015-10-13 16:42:40 +02:00
|
|
|
import { setDocumentTitle } from '../utils/dom_utils';
|
2015-07-01 18:58:13 +02:00
|
|
|
|
2015-06-15 16:56:17 +02:00
|
|
|
|
|
|
|
let PasswordResetContainer = React.createClass({
|
2015-10-07 09:39:30 +02:00
|
|
|
propTypes: {
|
2016-01-11 12:54:15 +01:00
|
|
|
// Provided from AscribeApp
|
|
|
|
currentUser: React.PropTypes.object,
|
|
|
|
whitelabel: React.PropTypes.object,
|
|
|
|
|
2016-01-11 16:26:36 +01:00
|
|
|
// Provided from router
|
2015-10-07 09:39:30 +02:00
|
|
|
location: React.PropTypes.object
|
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
getInitialState() {
|
2016-01-11 12:54:15 +01:00
|
|
|
return { isRequested: false };
|
2015-06-30 14:46:28 +02:00
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
|
|
|
handleRequestSuccess(email) {
|
2016-01-18 17:31:56 +01:00
|
|
|
this.setState({ isRequested: !!email });
|
2015-06-30 14:46:28 +02:00
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
render() {
|
2016-01-11 12:54:15 +01:00
|
|
|
const { email: emailQuery, token: tokenQuery } = this.props.location.query;
|
|
|
|
const { isRequested } = this.state;
|
2015-10-07 09:39:30 +02:00
|
|
|
|
2016-01-11 12:54:15 +01:00
|
|
|
if (emailQuery && tokenQuery) {
|
2015-06-30 14:46:28 +02:00
|
|
|
return (
|
2016-01-18 17:31:56 +01:00
|
|
|
<PasswordResetForm
|
|
|
|
email={emailQuery}
|
|
|
|
token={tokenQuery} />
|
|
|
|
);
|
|
|
|
} else if (!isRequested) {
|
|
|
|
return (
|
|
|
|
<PasswordRequestResetForm handleRequestSuccess={this.handleRequestSuccess} />
|
2015-06-30 14:46:28 +02:00
|
|
|
);
|
2016-01-11 12:54:15 +01:00
|
|
|
} else {
|
2016-01-18 17:31:56 +01:00
|
|
|
return (
|
|
|
|
<div className="ascribe-login-text ascribe-login-header">
|
|
|
|
{getLangText('If your email address exists in our database, you will receive a password recovery link in a few minutes.')}
|
|
|
|
</div>
|
|
|
|
);
|
2015-06-30 14:46:28 +02:00
|
|
|
}
|
2016-01-11 12:54:15 +01:00
|
|
|
}
|
2015-06-30 14:46:28 +02:00
|
|
|
});
|
2015-06-15 16:56:17 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
let PasswordRequestResetForm = React.createClass({
|
2015-08-06 10:23:01 +02:00
|
|
|
propTypes: {
|
|
|
|
handleRequestSuccess: React.PropTypes.func
|
|
|
|
},
|
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
handleSuccess() {
|
2016-01-11 12:54:15 +01:00
|
|
|
const notificationText = getLangText('If your email address exists in our database, you will receive a password recovery link in a few minutes.');
|
|
|
|
const notification = new GlobalNotificationModel(notificationText, 'success', 50000);
|
2015-06-30 14:46:28 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
2016-01-11 12:54:15 +01:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
this.props.handleRequestSuccess(this.refs.form.refs.email.state.value);
|
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
render() {
|
2015-10-13 16:42:40 +02:00
|
|
|
setDocumentTitle(getLangText('Reset your password'));
|
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
ref="form"
|
2015-08-18 16:24:36 +02:00
|
|
|
className='ascribe-form-wrapper'
|
2015-08-07 15:08:02 +02:00
|
|
|
url={ApiUrls.users_password_reset_request}
|
2015-06-30 14:46:28 +02:00
|
|
|
handleSuccess={this.handleSuccess}
|
|
|
|
buttons={
|
|
|
|
<button
|
|
|
|
type="submit"
|
2015-10-12 17:55:02 +02:00
|
|
|
className="btn btn-default btn-wide">
|
2015-07-01 18:58:13 +02:00
|
|
|
{getLangText('Reset your password')}
|
2016-01-11 12:54:15 +01:00
|
|
|
</button>
|
|
|
|
}
|
2015-06-30 14:46:28 +02:00
|
|
|
spinner={
|
2015-10-12 17:55:02 +02:00
|
|
|
<span className="btn btn-default btn-wide btn-spinner">
|
|
|
|
<AscribeSpinner color="dark-blue" size="md" />
|
2015-07-13 18:13:47 +02:00
|
|
|
</span>
|
2016-01-11 12:54:15 +01:00
|
|
|
}>
|
2015-08-06 10:23:01 +02:00
|
|
|
<div className="ascribe-form-header">
|
2015-07-15 13:20:34 +02:00
|
|
|
<h3>{getLangText('Reset your password')}</h3>
|
2015-08-06 10:23:01 +02:00
|
|
|
</div>
|
2015-06-30 14:46:28 +02:00
|
|
|
<Property
|
|
|
|
name='email'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Email')}>
|
2015-06-30 14:46:28 +02:00
|
|
|
<input
|
|
|
|
type="email"
|
2015-08-06 10:23:01 +02:00
|
|
|
placeholder={getLangText('Enter your email and we\'ll send a link')}
|
2015-06-30 14:46:28 +02:00
|
|
|
name="email"
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let PasswordResetForm = React.createClass({
|
2015-08-06 10:23:01 +02:00
|
|
|
propTypes: {
|
|
|
|
email: React.PropTypes.string,
|
|
|
|
token: React.PropTypes.string
|
|
|
|
},
|
|
|
|
|
2015-10-01 11:16:38 +02:00
|
|
|
mixins: [History],
|
2015-06-30 14:46:28 +02:00
|
|
|
|
2015-08-06 10:23:01 +02:00
|
|
|
getFormData() {
|
2015-07-10 15:52:09 +02:00
|
|
|
return {
|
|
|
|
email: this.props.email,
|
|
|
|
token: this.props.token
|
|
|
|
};
|
2015-06-30 14:46:28 +02:00
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
2015-06-30 14:46:28 +02:00
|
|
|
handleSuccess() {
|
2016-01-11 17:52:32 +01:00
|
|
|
this.history.push('/collection');
|
|
|
|
|
2016-02-08 14:50:24 +01:00
|
|
|
const notification = new GlobalNotificationModel(getLangText('Password successfully updated'), 'success', 10000);
|
2015-06-15 16:56:17 +02:00
|
|
|
GlobalNotificationActions.appendGlobalNotification(notification);
|
|
|
|
},
|
2015-08-06 10:23:01 +02:00
|
|
|
|
2015-06-15 16:56:17 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2015-06-30 14:46:28 +02:00
|
|
|
<Form
|
|
|
|
ref="form"
|
2015-08-18 16:24:36 +02:00
|
|
|
className='ascribe-form-wrapper'
|
2015-08-07 15:08:02 +02:00
|
|
|
url={ApiUrls.users_password_reset}
|
2015-06-15 16:56:17 +02:00
|
|
|
handleSuccess={this.handleSuccess}
|
2015-06-30 14:46:28 +02:00
|
|
|
getFormData={this.getFormData}
|
|
|
|
buttons={
|
|
|
|
<button
|
|
|
|
type="submit"
|
2015-10-12 17:55:02 +02:00
|
|
|
className="btn btn-default btn-wide">
|
2015-07-01 18:58:13 +02:00
|
|
|
{getLangText('Reset your password')}
|
2016-01-11 12:54:15 +01:00
|
|
|
</button>
|
|
|
|
}
|
2015-06-30 14:46:28 +02:00
|
|
|
spinner={
|
2015-10-12 17:55:02 +02:00
|
|
|
<span className="btn btn-default btn-wide btn-spinner">
|
|
|
|
<AscribeSpinner color="dark-blue" size="md" />
|
2015-07-13 18:13:47 +02:00
|
|
|
</span>
|
2016-01-11 12:54:15 +01:00
|
|
|
}>
|
2015-08-06 10:23:01 +02:00
|
|
|
<div className="ascribe-form-header">
|
2015-07-15 13:20:34 +02:00
|
|
|
<h3>{getLangText('Reset the password for')} {this.props.email}</h3>
|
2015-08-06 10:23:01 +02:00
|
|
|
</div>
|
2015-06-30 14:46:28 +02:00
|
|
|
<Property
|
|
|
|
name='password'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Password')}>
|
2015-06-30 14:46:28 +02:00
|
|
|
<input
|
|
|
|
type="password"
|
2015-07-01 18:58:13 +02:00
|
|
|
placeholder={getLangText('Enter a new password')}
|
2015-06-30 14:46:28 +02:00
|
|
|
name="password"
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<Property
|
|
|
|
name='password_confirm'
|
2015-07-01 18:58:13 +02:00
|
|
|
label={getLangText('Confirm password')}>
|
2015-06-30 14:46:28 +02:00
|
|
|
<input
|
|
|
|
type="password"
|
2015-07-01 18:58:13 +02:00
|
|
|
placeholder={getLangText('Enter your password once again')}
|
2015-06-30 14:46:28 +02:00
|
|
|
name="password"
|
|
|
|
required/>
|
|
|
|
</Property>
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
2015-06-15 16:56:17 +02:00
|
|
|
});
|
|
|
|
|
2015-07-13 19:53:16 +02:00
|
|
|
export default PasswordResetContainer;
|