1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00

nail login transition

This commit is contained in:
Tim Daubenschütz 2015-07-02 15:40:54 +02:00
parent 85a1574d41
commit 3ae94a2100
3 changed files with 73 additions and 13 deletions

View File

@ -58,7 +58,7 @@ let SlidesContainer = React.createClass({
// We let every one from the outsite set the page number of the slider, // We let every one from the outsite set the page number of the slider,
// though only if the slideNum is actually in the range of our children-list. // though only if the slideNum is actually in the range of our children-list.
setSlideNum(slideNum) { setSlideNum(slideNum) {
if(slideNum > 0 && slideNum < React.Children.count(this.props.children)) { if(slideNum < 0 || slideNum < React.Children.count(this.props.children)) {
this.transitionTo(this.getPathname(), null, {slide_num: slideNum}); this.transitionTo(this.getPathname(), null, {slide_num: slideNum});
this.setState({ this.setState({

View File

@ -7,6 +7,7 @@ import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions'; import GlobalNotificationActions from '../actions/global_notification_actions';
import UserStore from '../stores/user_store'; import UserStore from '../stores/user_store';
import UserActions from '../actions/user_actions';
import Form from './ascribe_forms/form'; import Form from './ascribe_forms/form';
import Property from './ascribe_forms/property'; import Property from './ascribe_forms/property';
@ -17,8 +18,22 @@ import AppConstants from '../constants/application_constants';
let Link = Router.Link; let Link = Router.Link;
let LoginContainer = React.createClass({ let LoginContainer = React.createClass({
propTypes: {
message: React.PropTypes.string,
redirectOnLoggedIn: React.PropTypes.bool,
redirectOnLoginSuccess: React.PropTypes.bool
},
mixins: [Router.Navigation], mixins: [Router.Navigation],
getDefaultProps() {
return {
message: 'Log in to ascribe...',
redirectOnLoggedIn: true,
redirectOnLoginSuccess: true
};
},
getInitialState() { getInitialState() {
return UserStore.getState(); return UserStore.getState();
}, },
@ -35,7 +50,7 @@ let LoginContainer = React.createClass({
this.setState(state); this.setState(state);
// if user is already logged in, redirect him to piece list // if user is already logged in, redirect him to piece list
if(this.state.currentUser && this.state.currentUser.email) { if(this.state.currentUser && this.state.currentUser.email && this.props.redirectOnLoggedIn) {
this.transitionTo('pieces'); this.transitionTo('pieces');
} }
}, },
@ -45,7 +60,7 @@ let LoginContainer = React.createClass({
<div className="ascribe-login-wrapper"> <div className="ascribe-login-wrapper">
<br/> <br/>
<div className="ascribe-login-text ascribe-login-header"> <div className="ascribe-login-text ascribe-login-header">
Log in to ascribe... {this.props.message}
</div> </div>
<LoginForm /> <LoginForm />
</div> </div>
@ -55,18 +70,31 @@ let LoginContainer = React.createClass({
let LoginForm = React.createClass({ let LoginForm = React.createClass({
propTypes: {
redirectOnLoginSuccess: React.PropTypes.bool
},
handleSuccess(){ handleSuccess(){
let notification = new GlobalNotificationModel('Login successsful', 'success', 10000); let notification = new GlobalNotificationModel('Login successsful', 'success', 10000);
GlobalNotificationActions.appendGlobalNotification(notification); GlobalNotificationActions.appendGlobalNotification(notification);
/*Taken from http://stackoverflow.com/a/14916411 */ // 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 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. 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. 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 Until then, we redirect the HARD way, but reloading the whole page using window.location
*/ */
window.location = AppConstants.baseUrl + 'collection'; if(this.props.redirectOnLoginSuccess) {
window.location = AppConstants.baseUrl + 'collection';
}
}, },
render() { render() {

View File

@ -12,6 +12,8 @@ import LicenseStore from '../stores/license_store';
import PieceListStore from '../stores/piece_list_store'; import PieceListStore from '../stores/piece_list_store';
import PieceListActions from '../actions/piece_list_actions'; import PieceListActions from '../actions/piece_list_actions';
import UserStore from '../stores/user_store';
import GlobalNotificationModel from '../models/global_notification_model'; import GlobalNotificationModel from '../models/global_notification_model';
import GlobalNotificationActions from '../actions/global_notification_actions'; import GlobalNotificationActions from '../actions/global_notification_actions';
@ -35,12 +37,13 @@ let RegisterPiece = React.createClass( {
getInitialState(){ getInitialState(){
return mergeOptions( return mergeOptions(
LicenseStore.getState(), LicenseStore.getState(),
UserStore.getState(),
PieceListStore.getState(), PieceListStore.getState(),
{ {
digitalWorkKey: null, digitalWorkKey: null,
uploadStatus: false, uploadStatus: false,
selectedLicense: 0, selectedLicense: 0,
isLoginShown: false isFineUploaderEditable: false
}); });
}, },
@ -48,15 +51,28 @@ let RegisterPiece = React.createClass( {
LicenseActions.fetchLicense(); LicenseActions.fetchLicense();
LicenseStore.listen(this.onChange); LicenseStore.listen(this.onChange);
PieceListStore.listen(this.onChange); PieceListStore.listen(this.onChange);
UserStore.listen(this.onChange);
}, },
componentWillUnmount() { componentWillUnmount() {
LicenseStore.unlisten(this.onChange); LicenseStore.unlisten(this.onChange);
PieceListStore.unlisten(this.onChange); PieceListStore.unlisten(this.onChange);
UserStore.unlisten(this.onChange);
}, },
onChange(state) { onChange(state) {
this.setState(state); this.setState(state);
// once the currentUser object from UserStore is defined (eventually the user was transitioned
// to the login form via the slider and successfully logged in), we can direct him back to the
// register_piece slide
if(state.currentUser && state.currentUser.email) {
this.refs.slidesContainer.setSlideNum(0);
// we should also make the fineuploader component editable again
this.setState({
isFineUploaderEditable: true
});
}
}, },
handleSuccess(response){ handleSuccess(response){
@ -131,14 +147,20 @@ let RegisterPiece = React.createClass( {
return null; return null;
}, },
changePage() { changeSlide() {
this.refs.slidesContainer.setSlideNum(1); // only transition to the login store, if user is not logged in
// ergo the currentUser object is not properly defined
if(!this.state.currentUser.email) {
this.refs.slidesContainer.setSlideNum(1);
}
}, },
render() { render() {
return ( return (
<SlidesContainer ref="slidesContainer"> <SlidesContainer ref="slidesContainer">
<div> <div
onClick={this.changeSlide}
onFocus={this.changeSlide}>
<h3 style={{'marginTop': 0}} onClick={this.changePage}>Lock down title</h3> <h3 style={{'marginTop': 0}} onClick={this.changePage}>Lock down title</h3>
<Form <Form
ref='form' ref='form'
@ -160,7 +182,8 @@ let RegisterPiece = React.createClass( {
<FileUploader <FileUploader
submitKey={this.submitKey} submitKey={this.submitKey}
setIsUploadReady={this.setIsUploadReady} setIsUploadReady={this.setIsUploadReady}
isReadyForFormSubmission={this.isReadyForFormSubmission}/> isReadyForFormSubmission={this.isReadyForFormSubmission}
editable={this.state.isFineUploaderEditable}/>
</Property> </Property>
<Property <Property
name='artist_name' name='artist_name'
@ -201,7 +224,10 @@ let RegisterPiece = React.createClass( {
</Form> </Form>
</div> </div>
<div> <div>
<LoginContainer/> <LoginContainer
message="Please login before ascribing your piece..."
redirectOnLoggedIn={false}
redirectOnLoginSuccess={false}/>
</div> </div>
</SlidesContainer> </SlidesContainer>
); );
@ -213,12 +239,18 @@ let FileUploader = React.createClass({
propTypes: { propTypes: {
setIsUploadReady: React.PropTypes.func, setIsUploadReady: React.PropTypes.func,
submitKey: React.PropTypes.func, submitKey: React.PropTypes.func,
isReadyForFormSubmission: React.PropTypes.func isReadyForFormSubmission: React.PropTypes.func,
onClick: React.PropTypes.func,
// editable is used to lock react fine uploader in case
// a user is actually not logged in already to prevent him from droping files
// before login in
editable: React.PropTypes.bool
}, },
render() { render() {
return ( return (
<ReactS3FineUploader <ReactS3FineUploader
onClick={this.props.onClick}
keyRoutine={{ keyRoutine={{
url: AppConstants.serverUrl + 's3/key/', url: AppConstants.serverUrl + 's3/key/',
fileClass: 'digitalwork' fileClass: 'digitalwork'
@ -234,7 +266,7 @@ let FileUploader = React.createClass({
setIsUploadReady={this.props.setIsUploadReady} setIsUploadReady={this.props.setIsUploadReady}
isReadyForFormSubmission={this.props.isReadyForFormSubmission} isReadyForFormSubmission={this.props.isReadyForFormSubmission}
areAssetsDownloadable={false} areAssetsDownloadable={false}
areAssetsEditable={true}/> areAssetsEditable={this.props.editable}/>
); );
} }
}); });