1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-16 01:55:07 +01:00
onion/js/components/password_reset_container.js

161 lines
5.8 KiB
JavaScript
Raw Normal View History

2015-06-15 16:56:17 +02:00
'use strict';
import React from 'react';
import Router from 'react-router';
2015-06-30 14:46:28 +02:00
import Form from './ascribe_forms/form';
import Property from './ascribe_forms/property';
2015-07-15 13:20:34 +02:00
import FormPropertyHeader from './ascribe_forms/form_property_header';
2015-06-30 14:46:28 +02:00
import apiUrls from '../constants/api_urls';
2015-06-15 16:56:17 +02:00
import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions';
import { getLangText } from '../utils/lang_utils';
2015-06-15 16:56:17 +02:00
let PasswordResetContainer = React.createClass({
mixins: [Router.Navigation],
2015-06-30 14:46:28 +02:00
getInitialState() {
return {isRequested: false};
},
handleRequestSuccess(email){
this.setState({isRequested: email});
},
render() {
if (this.props.query.email && this.props.query.token) {
return (
<div>
<PasswordResetForm
email={this.props.query.email}
token={this.props.query.token}/>
</div>
);
}
else {
if (this.state.isRequested === false) {
return (
<div>
<PasswordRequestResetForm
handleRequestSuccess={this.handleRequestSuccess}/>
</div>
);
}
else if (this.state.isRequested) {
return (
<div>
<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.')}
2015-06-30 14:46:28 +02:00
</div>
</div>
);
}
else {
return <span />;
}
}
}
});
2015-06-15 16:56:17 +02:00
2015-06-30 14:46:28 +02:00
let PasswordRequestResetForm = React.createClass({
handleSuccess() {
let notificationText = getLangText('If your email address exists in our database, you will receive a password recovery link in a few minutes.');
2015-06-30 14:46:28 +02:00
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
GlobalNotificationActions.appendGlobalNotification(notification);
this.props.handleRequestSuccess(this.refs.form.refs.email.state.value);
},
render() {
return (
<Form
ref="form"
url={apiUrls.users_password_reset_request}
handleSuccess={this.handleSuccess}
buttons={
<button
type="submit"
className="btn ascribe-btn ascribe-btn-login">
{getLangText('Reset your password')}
2015-06-30 14:46:28 +02:00
</button>}
spinner={
<span className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
2015-06-30 14:46:28 +02:00
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
</span>
2015-06-30 14:46:28 +02:00
}>
2015-07-15 13:20:34 +02:00
<FormPropertyHeader>
<h3>{getLangText('Reset your password')}</h3>
</FormPropertyHeader>
2015-06-30 14:46:28 +02:00
<Property
name='email'
label={getLangText('Email')}>
2015-06-30 14:46:28 +02:00
<input
type="email"
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({
mixins: [Router.Navigation],
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
},
handleSuccess() {
2015-06-15 16:56:17 +02:00
this.transitionTo('pieces');
let notification = new GlobalNotificationModel(getLangText('password successfully updated'), 'success', 10000);
2015-06-15 16:56:17 +02:00
GlobalNotificationActions.appendGlobalNotification(notification);
},
render() {
return (
2015-06-30 14:46:28 +02:00
<Form
ref="form"
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"
className="btn ascribe-btn ascribe-btn-login">
{getLangText('Reset your password')}
2015-06-30 14:46:28 +02:00
</button>}
spinner={
<span className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
2015-06-30 14:46:28 +02:00
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
</span>
2015-06-30 14:46:28 +02:00
}>
2015-07-15 13:20:34 +02:00
<FormPropertyHeader>
<h3>{getLangText('Reset the password for')} {this.props.email}</h3>
</FormPropertyHeader>
2015-06-30 14:46:28 +02:00
<Property
name='password'
label={getLangText('Password')}>
2015-06-30 14:46:28 +02:00
<input
type="password"
placeholder={getLangText('Enter a new password')}
2015-06-30 14:46:28 +02:00
name="password"
required/>
</Property>
<Property
name='password_confirm'
label={getLangText('Confirm password')}>
2015-06-30 14:46:28 +02:00
<input
type="password"
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;