mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Refactor EventActions and UserStore to more cleanly handle user authentication and log out events
This commit is contained in:
parent
2acf3f4056
commit
19841ce6c4
@ -8,9 +8,8 @@ class EventActions {
|
|||||||
this.generateActions(
|
this.generateActions(
|
||||||
'applicationWillBoot',
|
'applicationWillBoot',
|
||||||
'applicationDidBoot',
|
'applicationDidBoot',
|
||||||
'profileDidLoad',
|
'userDidAuthenticate',
|
||||||
//'userDidLogin',
|
'userDidLogout',
|
||||||
//'userDidLogout',
|
|
||||||
'routeDidChange'
|
'routeDidChange'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -59,19 +59,6 @@ let Header = React.createClass({
|
|||||||
// close the mobile expanded navigation after a click by itself.
|
// close the mobile expanded navigation after a click by itself.
|
||||||
// To get rid of this, we set the state of the component ourselves.
|
// To get rid of this, we set the state of the component ourselves.
|
||||||
history.listen(this.onRouteChange);
|
history.listen(this.onRouteChange);
|
||||||
|
|
||||||
if (this.state.currentUser && this.state.currentUser.email) {
|
|
||||||
EventActions.profileDidLoad.defer(this.state.currentUser);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUpdate(nextProps, nextState) {
|
|
||||||
const { currentUser: { email: curEmail } = {} } = this.state;
|
|
||||||
const { currentUser: { email: nextEmail } = {} } = nextState;
|
|
||||||
|
|
||||||
if (nextEmail && curEmail !== nextEmail) {
|
|
||||||
EventActions.profileDidLoad.defer(nextState.currentUser);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -81,7 +68,7 @@ let Header = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getLogo() {
|
getLogo() {
|
||||||
let { whitelabel } = this.state;
|
const { whitelabel } = this.state;
|
||||||
|
|
||||||
if (whitelabel.head) {
|
if (whitelabel.head) {
|
||||||
constructHead(whitelabel.head);
|
constructHead(whitelabel.head);
|
||||||
@ -102,7 +89,7 @@ let Header = React.createClass({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
getPoweredBy(){
|
getPoweredBy() {
|
||||||
return (
|
return (
|
||||||
<AclProxy
|
<AclProxy
|
||||||
aclObject={this.state.whitelabel}
|
aclObject={this.state.whitelabel}
|
||||||
|
@ -6,7 +6,6 @@ import { History } from 'react-router';
|
|||||||
import AscribeSpinner from './ascribe_spinner';
|
import AscribeSpinner from './ascribe_spinner';
|
||||||
|
|
||||||
import UserActions from '../actions/user_actions';
|
import UserActions from '../actions/user_actions';
|
||||||
import { alt, altWhitelabel, altUser, altThirdParty } from '../alt';
|
|
||||||
|
|
||||||
import { getLangText } from '../utils/lang_utils';
|
import { getLangText } from '../utils/lang_utils';
|
||||||
import { setDocumentTitle } from '../utils/dom_utils';
|
import { setDocumentTitle } from '../utils/dom_utils';
|
||||||
@ -17,12 +16,6 @@ let LogoutContainer = React.createClass({
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
UserActions.logoutCurrentUser();
|
UserActions.logoutCurrentUser();
|
||||||
alt.flush();
|
|
||||||
altWhitelabel.flush();
|
|
||||||
altUser.flush();
|
|
||||||
altThirdParty.flush();
|
|
||||||
// kill intercom (with fire)
|
|
||||||
window.Intercom('shutdown');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -32,19 +32,6 @@ let PRApp = React.createClass({
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser();
|
||||||
|
|
||||||
if (this.state.currentUser && this.state.currentUser.email) {
|
|
||||||
EventActions.profileDidLoad.defer(this.state.currentUser);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUpdate(nextProps, nextState) {
|
|
||||||
const { currentUser: { email: curEmail } = {} } = this.state;
|
|
||||||
const { currentUser: { email: nextEmail } = {} } = nextState;
|
|
||||||
|
|
||||||
if (nextEmail && curEmail !== nextEmail) {
|
|
||||||
EventActions.profileDidLoad.defer(nextState.currentUser);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { altUser } from '../alt';
|
import { alt, altWhitelabel, altUser, altThirdParty } from '../alt';
|
||||||
import UserActions from '../actions/user_actions';
|
|
||||||
|
|
||||||
|
import EventActions from '../actions/event_actions';
|
||||||
|
|
||||||
|
import UserActions from '../actions/user_actions';
|
||||||
import UserSource from '../sources/user_source';
|
import UserSource from '../sources/user_source';
|
||||||
|
|
||||||
|
|
||||||
@ -21,7 +23,7 @@ class UserStore {
|
|||||||
onFetchCurrentUser(invalidateCache) {
|
onFetchCurrentUser(invalidateCache) {
|
||||||
this.userMeta.invalidateCache = invalidateCache;
|
this.userMeta.invalidateCache = invalidateCache;
|
||||||
|
|
||||||
if(!this.getInstance().isLoading()) {
|
if (!this.getInstance().isLoading()) {
|
||||||
this.getInstance().lookupCurrentUser();
|
this.getInstance().lookupCurrentUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,11 +31,26 @@ class UserStore {
|
|||||||
onSuccessFetchCurrentUser({users: [user = {}]}) {
|
onSuccessFetchCurrentUser({users: [user = {}]}) {
|
||||||
this.userMeta.invalidateCache = false;
|
this.userMeta.invalidateCache = false;
|
||||||
this.userMeta.err = null;
|
this.userMeta.err = null;
|
||||||
|
|
||||||
|
if (user.email && user.email !== this.currentUser.email) {
|
||||||
|
EventActions.userDidAuthenticate(user);
|
||||||
|
}
|
||||||
|
|
||||||
this.currentUser = user;
|
this.currentUser = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
onLogoutCurrentUser() {
|
onLogoutCurrentUser() {
|
||||||
this.getInstance().performLogoutCurrentUser();
|
this.getInstance()
|
||||||
|
.performLogoutCurrentUser()
|
||||||
|
.then(() => {
|
||||||
|
EventActions.userDidLogout();
|
||||||
|
|
||||||
|
// Reset all stores back to their initial state
|
||||||
|
alt.recycle();
|
||||||
|
altWhitelabel.recycle();
|
||||||
|
altUser.recycle();
|
||||||
|
altThirdParty.recycle();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSuccessLogoutCurrentUser() {
|
onSuccessLogoutCurrentUser() {
|
||||||
|
13
js/third_party/intercom.js
vendored
13
js/third_party/intercom.js
vendored
@ -12,16 +12,14 @@ class IntercomHandler {
|
|||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onProfileDidLoad(profile) {
|
onUserDidAuthenticate(user) {
|
||||||
if (this.loaded) {
|
if (this.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable */
|
window.Intercom('boot', {
|
||||||
Intercom('boot', {
|
|
||||||
/* eslint-enable */
|
|
||||||
app_id: 'oboxh5w1',
|
app_id: 'oboxh5w1',
|
||||||
email: profile.email,
|
email: user.email,
|
||||||
subdomain: getSubdomain(),
|
subdomain: getSubdomain(),
|
||||||
widget: {
|
widget: {
|
||||||
activator: '#IntercomDefaultWidget'
|
activator: '#IntercomDefaultWidget'
|
||||||
@ -31,6 +29,11 @@ class IntercomHandler {
|
|||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUserDidLogout() {
|
||||||
|
// kill intercom (with fire)
|
||||||
|
window.Intercom('shutdown');
|
||||||
|
this.loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default altThirdParty.createStore(IntercomHandler, 'IntercomHandler');
|
export default altThirdParty.createStore(IntercomHandler, 'IntercomHandler');
|
||||||
|
11
js/third_party/notifications.js
vendored
11
js/third_party/notifications.js
vendored
@ -17,18 +17,19 @@ class NotificationsHandler {
|
|||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onProfileDidLoad() {
|
onUserDidAuthenticate() {
|
||||||
if (this.loaded) {
|
if (this.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let subdomain = getSubdomain();
|
const subdomain = getSubdomain();
|
||||||
if (subdomain === 'ikonotv') {
|
if (subdomain === 'ikonotv') {
|
||||||
NotificationActions.fetchContractAgreementListNotifications().then(
|
NotificationActions.fetchContractAgreementListNotifications().then(
|
||||||
(res) => {
|
(res) => {
|
||||||
if (res.notifications && res.notifications.length > 0) {
|
if (res.notifications && res.notifications.length > 0) {
|
||||||
this.loaded = true;
|
|
||||||
console.log('Contractagreement notifications loaded');
|
console.log('Contractagreement notifications loaded');
|
||||||
|
this.loaded = true;
|
||||||
|
|
||||||
history.pushState(null, '/contract_notifications');
|
history.pushState(null, '/contract_notifications');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,6 +37,10 @@ class NotificationsHandler {
|
|||||||
}
|
}
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUserDidLogout() {
|
||||||
|
this.loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default altThirdParty.createStore(NotificationsHandler, 'NotificationsHandler');
|
export default altThirdParty.createStore(NotificationsHandler, 'NotificationsHandler');
|
||||||
|
9
js/third_party/raven.js
vendored
9
js/third_party/raven.js
vendored
@ -12,17 +12,22 @@ class RavenHandler {
|
|||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
onProfileDidLoad(profile) {
|
onUserDidAuthenticate(user) {
|
||||||
if (this.loaded) {
|
if (this.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Raven.setUserContext({
|
Raven.setUserContext({
|
||||||
email: profile.email
|
email: user.email
|
||||||
});
|
});
|
||||||
console.log('Raven loaded');
|
console.log('Raven loaded');
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUserDidLogout() {
|
||||||
|
Raven.setUserContext();
|
||||||
|
this.loaded = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default altThirdParty.createStore(RavenHandler, 'RavenHandler');
|
export default altThirdParty.createStore(RavenHandler, 'RavenHandler');
|
||||||
|
Loading…
Reference in New Issue
Block a user