mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
Refactor login/signup containers
This commit is contained in:
parent
3878dc12da
commit
db1c6a530a
@ -1,78 +1,130 @@
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
|
||||
import { getLangText } from '../../utils/lang_utils';
|
||||
|
||||
import UserStore from '../../stores/user_store';
|
||||
|
||||
import GlobalNotificationModel from '../../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../../actions/global_notification_actions';
|
||||
|
||||
import Form from './form';
|
||||
import Property from './property';
|
||||
import FormPropertyHeader from './form_property_header';
|
||||
import InputCheckbox from './input_checkbox';
|
||||
|
||||
import apiUrls from '../../constants/api_urls';
|
||||
import FormMixin from '../../mixins/form_mixin';
|
||||
import InputText from './input_text';
|
||||
import InputCheckbox from './input_checkbox';
|
||||
import ButtonSubmitOrClose from '../ascribe_buttons/button_submit_close';
|
||||
import { getLangText } from '../../utils/lang_utils.js'
|
||||
|
||||
|
||||
let SignupForm = React.createClass({
|
||||
mixins: [FormMixin],
|
||||
|
||||
url() {
|
||||
return apiUrls.users_signup;
|
||||
propTypes: {
|
||||
handleSuccess: React.PropTypes.func
|
||||
},
|
||||
|
||||
getFormData() {
|
||||
return {
|
||||
email: this.refs.email.state.value,
|
||||
password: this.refs.password.state.value,
|
||||
password_confirm: this.refs.password_confirm.state.value,
|
||||
terms: this.refs.terms.state.value,
|
||||
promo_code: this.refs.promo_code.state.value
|
||||
};
|
||||
mixins: [Router.Navigation],
|
||||
|
||||
getInitialState() {
|
||||
return UserStore.getState();
|
||||
},
|
||||
|
||||
renderForm() {
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
|
||||
// if user is already logged in, redirect him to piece list
|
||||
if(this.state.currentUser && this.state.currentUser.email) {
|
||||
this.transitionTo('pieces');
|
||||
}
|
||||
},
|
||||
|
||||
handleSuccess(response){
|
||||
|
||||
let notificationText = getLangText('Sign up successful');
|
||||
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email +
|
||||
', ' + getLangText('please confirm') + '.');
|
||||
|
||||
},
|
||||
getFormData(){
|
||||
return {terms: this.refs.form.refs.terms.refs.input.state.value};
|
||||
},
|
||||
render() {
|
||||
let tooltipPassword = getLangText('Your password must be at least 10 characters') + '.\n ' +
|
||||
getLangText('This password is securing your digital property like a bank account') + '.\n ' +
|
||||
getLangText('Store it in a safe place') + '!';
|
||||
return (
|
||||
<form id="signup_modal_content" role="form" onSubmit={this.submit}>
|
||||
<input className="invisible" type="email" name="fake_consignee"/>
|
||||
<input className="invisible" type="password" name="fake_password"/>
|
||||
<InputText
|
||||
ref="email"
|
||||
placeHolder={getLangText('Email')}
|
||||
required="required"
|
||||
<Form
|
||||
className="ascribe-form-bordered"
|
||||
ref='form'
|
||||
url={apiUrls.users_signup}
|
||||
handleSuccess={this.handleSuccess}
|
||||
getFormData={this.getFormData}
|
||||
buttons={
|
||||
<button type="submit" className="btn ascribe-btn ascribe-btn-login">
|
||||
{getLangText('Sign up to ascribe')}
|
||||
</button>}
|
||||
spinner={
|
||||
<button className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
|
||||
</button>
|
||||
}>
|
||||
<FormPropertyHeader>
|
||||
<h3>{getLangText('Welcome to ascribe')}</h3>
|
||||
</FormPropertyHeader>
|
||||
<Property
|
||||
name='email'
|
||||
label={getLangText('Email')}>
|
||||
<input
|
||||
type="email"
|
||||
submitted={this.state.submitted}/>
|
||||
<InputText
|
||||
ref="password"
|
||||
placeHolder={getLangText('Choose a password')}
|
||||
required="required"
|
||||
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='password'
|
||||
label={getLangText('Password')}
|
||||
tooltip={tooltipPassword}>
|
||||
<input
|
||||
type="password"
|
||||
submitted={this.state.submitted}/>
|
||||
<InputText
|
||||
ref="password_confirm"
|
||||
placeHolder={getLangText('Confirm password')}
|
||||
required="required"
|
||||
placeholder={getLangText('Use a combination of minimum 10 chars and numbers')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='password_confirm'
|
||||
label={getLangText('Confirm Password')}
|
||||
tooltip={tooltipPassword}>
|
||||
<input
|
||||
type="password"
|
||||
submitted={this.state.submitted}/>
|
||||
<div>
|
||||
{getLangText('Your password must be at least 10 characters')}.
|
||||
{getLangText('This password is securing your digital property like a bank account')}.
|
||||
{getLangText('Store it in a safe place')}!
|
||||
</div>
|
||||
<InputCheckbox
|
||||
ref="terms"
|
||||
required="required"
|
||||
label={
|
||||
<div>
|
||||
{getLangText('I agree to the')}
|
||||
<a href="/terms" target="_blank"> {getLangText('Terms of Service')}</a>
|
||||
</div>}/>
|
||||
<InputText
|
||||
ref="promo_code"
|
||||
placeHolder={getLangText('Promocode (Optional)')}
|
||||
required=""
|
||||
placeholder={getLangText('Enter your password once again')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='promo_code'
|
||||
label={getLangText('Promocode')}>
|
||||
<input
|
||||
type="text"
|
||||
submitted={this.state.submitted}/>
|
||||
<ButtonSubmitOrClose
|
||||
text={getLangText('JOIN US')}
|
||||
onClose={this.props.onRequestHide}
|
||||
submitted={this.state.submitted} />
|
||||
</form>
|
||||
placeholder={getLangText('Enter a promocode here (Optional)')}/>
|
||||
</Property>
|
||||
<Property
|
||||
name="terms"
|
||||
className="ascribe-settings-property-collapsible-toggle"
|
||||
style={{paddingBottom: 0}}>
|
||||
<InputCheckbox/>
|
||||
</Property>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -3,60 +3,24 @@
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
|
||||
import GlobalNotificationModel from '../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||
|
||||
import UserStore from '../stores/user_store';
|
||||
import UserActions from '../actions/user_actions';
|
||||
|
||||
import Form from './ascribe_forms/form';
|
||||
import Property from './ascribe_forms/property';
|
||||
|
||||
import apiUrls from '../constants/api_urls';
|
||||
import AppConstants from '../constants/application_constants';
|
||||
import LoginForm from './ascribe_forms/form_login';
|
||||
|
||||
import { getLangText } from '../utils/lang_utils';
|
||||
|
||||
let Link = Router.Link;
|
||||
|
||||
|
||||
let LoginContainer = React.createClass({
|
||||
propTypes: {
|
||||
message: React.PropTypes.string,
|
||||
redirectOnLoggedIn: React.PropTypes.bool,
|
||||
redirectOnLoginSuccess: React.PropTypes.bool
|
||||
message: React.PropTypes.string
|
||||
},
|
||||
|
||||
mixins: [Router.Navigation],
|
||||
|
||||
getDefaultProps() {
|
||||
return {
|
||||
message: getLangText('Enter') + ' ascribe',
|
||||
redirectOnLoggedIn: true,
|
||||
redirectOnLoginSuccess: true
|
||||
message: getLangText('Enter') + ' ascribe'
|
||||
};
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return UserStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
|
||||
// if user is already logged in, redirect him to piece list
|
||||
if(this.state.currentUser && this.state.currentUser.email && this.props.redirectOnLoggedIn) {
|
||||
this.transitionTo('pieces');
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="ascribe-login-wrapper">
|
||||
@ -75,76 +39,5 @@ let LoginContainer = React.createClass({
|
||||
});
|
||||
|
||||
|
||||
let LoginForm = React.createClass({
|
||||
propTypes: {
|
||||
redirectOnLoginSuccess: React.PropTypes.bool
|
||||
},
|
||||
|
||||
handleSuccess(){
|
||||
let notification = new GlobalNotificationModel('Login successful', 'success', 10000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
|
||||
// register_piece is waiting for a login success as login_container and it is wrapped
|
||||
// in a slides_container component.
|
||||
// The easiest way to check if the user was successfully logged in is to fetch the user
|
||||
// in the user store (which is obviously only possible if the user is logged in), since
|
||||
// register_piece is listening to the changes of the user_store.
|
||||
UserActions.fetchCurrentUser();
|
||||
|
||||
/* Taken from http://stackoverflow.com/a/14916411 */
|
||||
/*
|
||||
We actually have to trick the Browser into showing the "save password" dialog
|
||||
as Chrome expects the login page to be reloaded after the login.
|
||||
Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future.
|
||||
Until then, we redirect the HARD way, but reloading the whole page using window.location
|
||||
*/
|
||||
if(this.props.redirectOnLoginSuccess) {
|
||||
window.location = AppConstants.baseUrl + 'collection';
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form
|
||||
ref="loginForm"
|
||||
url={apiUrls.users_login}
|
||||
handleSuccess={this.handleSuccess}
|
||||
buttons={
|
||||
<button
|
||||
type="submit"
|
||||
className="btn ascribe-btn ascribe-btn-login">
|
||||
{getLangText('Enter')} ascribe
|
||||
</button>}
|
||||
spinner={
|
||||
<button className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
|
||||
</button>
|
||||
}>
|
||||
<Property
|
||||
name='email'
|
||||
label={getLangText('Email')}>
|
||||
<input
|
||||
type="email"
|
||||
placeholder={getLangText('Enter your email')}
|
||||
autoComplete="on"
|
||||
name="username"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='password'
|
||||
label={getLangText('Password')}>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={getLangText('Enter your password')}
|
||||
autoComplete="on"
|
||||
name="password"
|
||||
required/>
|
||||
</Property>
|
||||
<hr />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
export default LoginContainer;
|
||||
|
@ -1,50 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
import Router from 'react-router';
|
||||
|
||||
import { mergeOptions } from '../utils/general_utils';
|
||||
import { getLangText } from '../utils/lang_utils';
|
||||
|
||||
import UserStore from '../stores/user_store';
|
||||
|
||||
import GlobalNotificationModel from '../models/global_notification_model';
|
||||
import GlobalNotificationActions from '../actions/global_notification_actions';
|
||||
|
||||
import Form from './ascribe_forms/form';
|
||||
import Property from './ascribe_forms/property';
|
||||
import FormPropertyHeader from './ascribe_forms/form_property_header';
|
||||
import InputCheckbox from './ascribe_forms/input_checkbox';
|
||||
|
||||
|
||||
import apiUrls from '../constants/api_urls';
|
||||
import SignupForm from './ascribe_forms/form_signup';
|
||||
|
||||
// import { getLangText } from '../utils/lang_utils';
|
||||
|
||||
let SignupContainer = React.createClass({
|
||||
mixins: [Router.Navigation],
|
||||
|
||||
getInitialState() {
|
||||
return mergeOptions({
|
||||
return {
|
||||
submitted: false,
|
||||
message: null
|
||||
}, UserStore.getState());
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
UserStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
this.setState(state);
|
||||
|
||||
// if user is already logged in, redirect him to piece list
|
||||
if(this.state.currentUser && this.state.currentUser.email) {
|
||||
this.transitionTo('pieces');
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
handleSuccess(message){
|
||||
@ -75,93 +41,4 @@ let SignupContainer = React.createClass({
|
||||
});
|
||||
|
||||
|
||||
let SignupForm = React.createClass({
|
||||
propTypes: {
|
||||
handleSuccess: React.PropTypes.func
|
||||
},
|
||||
|
||||
mixins: [Router.Navigation],
|
||||
|
||||
handleSuccess(response){
|
||||
|
||||
let notificationText = getLangText('Sign up successful');
|
||||
let notification = new GlobalNotificationModel(notificationText, 'success', 50000);
|
||||
GlobalNotificationActions.appendGlobalNotification(notification);
|
||||
this.props.handleSuccess(getLangText('We sent an email to your address') + ' ' + response.user.email +
|
||||
', ' + getLangText('please confirm') + '.');
|
||||
|
||||
},
|
||||
getFormData(){
|
||||
return {terms: this.refs.form.refs.terms.refs.input.state.value};
|
||||
},
|
||||
render() {
|
||||
let tooltipPassword = getLangText('Your password must be at least 10 characters') + '.\n ' +
|
||||
getLangText('This password is securing your digital property like a bank account') + '.\n ' +
|
||||
getLangText('Store it in a safe place') + '!';
|
||||
return (
|
||||
<Form
|
||||
className="ascribe-form-bordered"
|
||||
ref='form'
|
||||
url={apiUrls.users_signup}
|
||||
handleSuccess={this.handleSuccess}
|
||||
getFormData={this.getFormData}
|
||||
buttons={
|
||||
<button type="submit" className="btn ascribe-btn ascribe-btn-login">
|
||||
{getLangText('Sign up to ascribe')}
|
||||
</button>}
|
||||
spinner={
|
||||
<button className="btn ascribe-btn ascribe-btn-login ascribe-btn-login-spinner">
|
||||
<img src="https://s3-us-west-2.amazonaws.com/ascribe0/media/thumbnails/ascribe_animated_medium.gif" />
|
||||
</button>
|
||||
}>
|
||||
<FormPropertyHeader>
|
||||
<h3>{getLangText('Welcome to ascribe')}</h3>
|
||||
</FormPropertyHeader>
|
||||
<Property
|
||||
name='email'
|
||||
label={getLangText('Email')}>
|
||||
<input
|
||||
type="email"
|
||||
placeholder={getLangText('(e.g. andy@warhol.co.uk)')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='password'
|
||||
label={getLangText('Password')}
|
||||
tooltip={tooltipPassword}>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={getLangText('Use a combination of minimum 10 chars and numbers')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='password_confirm'
|
||||
label={getLangText('Confirm Password')}
|
||||
tooltip={tooltipPassword}>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={getLangText('Enter your password once again')}
|
||||
autoComplete="on"
|
||||
required/>
|
||||
</Property>
|
||||
<Property
|
||||
name='promo_code'
|
||||
label={getLangText('Promocode')}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder={getLangText('Enter a promocode here (Optional)')}/>
|
||||
</Property>
|
||||
<Property
|
||||
name="terms"
|
||||
className="ascribe-settings-property-collapsible-toggle"
|
||||
style={{paddingBottom: 0}}>
|
||||
<InputCheckbox/>
|
||||
</Property>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default SignupContainer;
|
Loading…
Reference in New Issue
Block a user