From f3677501c1c787f7f84076d88ad4744f15261d2e Mon Sep 17 00:00:00 2001 From: diminator Date: Mon, 29 Jun 2015 15:58:47 +0200 Subject: [PATCH 1/2] whitelabel subdomains --- gulpfile.js | 3 +- js/actions/whitelabel_actions.js | 25 ++++++++ .../react_s3_fine_uploader.js | 20 +++--- js/components/header.js | 61 ++++++++++++++----- js/constants/api_urls.js | 3 +- js/fetchers/whitelabel_fetcher.js | 14 +++++ js/stores/whitelabel_store.js | 18 ++++++ sass/main.scss | 14 +++++ 8 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 js/actions/whitelabel_actions.js create mode 100644 js/fetchers/whitelabel_fetcher.js create mode 100644 js/stores/whitelabel_store.js diff --git a/gulpfile.js b/gulpfile.js index 6f82da83..25af23bf 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -93,8 +93,7 @@ gulp.task('browser-sync', function() { browserSync({ files: config.filesToWatch, proxy: 'http://localhost:4000', - port: 3000, - browser: "chromium-browser" + port: 3000 }); }); diff --git a/js/actions/whitelabel_actions.js b/js/actions/whitelabel_actions.js new file mode 100644 index 00000000..28d95cb9 --- /dev/null +++ b/js/actions/whitelabel_actions.js @@ -0,0 +1,25 @@ +'use strict'; + +import alt from '../alt'; +import WhitelabelFetcher from '../fetchers/whitelabel_fetcher'; + + +class WhitelabelActions { + constructor() { + this.generateActions( + 'updateWhitelabel' + ); + } + + fetchWhitelabel() { + WhitelabelFetcher.fetch() + .then((res) => { + this.actions.updateWhitelabel(res.whitelabel); + }) + .catch((err) => { + console.log(err); + }); + } +} + +export default alt.createActions(WhitelabelActions); diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index c2842e3c..378944f2 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -8,6 +8,7 @@ promise.polyfill(); import fetch from 'isomorphic-fetch'; import AppConstants from '../../constants/application_constants'; +import { getCookie } from '../../utils/fetch_api_utils'; import fineUploader from 'fineUploader'; import FileDragAndDrop from './file_drag_and_drop'; @@ -105,21 +106,22 @@ var ReactS3FineUploader = React.createClass({ } }, signature: { - endpoint: AppConstants.serverUrl + 's3/signature/' - //customHeaders: { - // 'Authorization': 'OAuth ' + getCookie('sessionid') - //} + endpoint: AppConstants.serverUrl + 's3/signature/', + customHeaders: { + 'X-CSRFToken': getCookie('csrftoken') + } }, deleteFile: { enabled: true, method: 'DELETE', - endpoint: AppConstants.serverUrl + 's3/delete' - //customHeaders: { - // 'X-CSRFToken': getCookie('csrftoken') - //} + endpoint: AppConstants.serverUrl + 's3/delete', + customHeaders: { + 'X-CSRFToken': getCookie('csrftoken') + } }, cors: { - expected: true + expected: true, + sendCredentials: true }, chunking: { enabled: true diff --git a/js/components/header.js b/js/components/header.js index 4699972c..b2e70f81 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -6,6 +6,9 @@ import Router from 'react-router'; import UserActions from '../actions/user_actions'; import UserStore from '../stores/user_store'; +import WhitelabelActions from '../actions/whitelabel_actions'; +import WhitelabelStore from '../stores/whitelabel_store'; + import Alt from '../alt'; import Nav from 'react-bootstrap/lib/Nav'; @@ -17,6 +20,7 @@ import MenuItemLink from 'react-router-bootstrap/lib/MenuItemLink'; import NavItemLink from 'react-router-bootstrap/lib/NavItemLink'; +import { mergeOptions } from '../utils/general_utils'; import { getLangText } from '../utils/lang_utils'; let Link = Router.Link; @@ -25,22 +29,47 @@ let Header = React.createClass({ mixins: [Router.Navigation], getInitialState() { - return UserStore.getState(); + return mergeOptions(WhitelabelStore.getState(), UserStore.getState()); }, componentDidMount() { UserActions.fetchCurrentUser(); UserStore.listen(this.onChange); + WhitelabelActions.fetchWhitelabel(); + WhitelabelStore.listen(this.onChange); }, componentWillUnmount() { UserStore.unlisten(this.onChange); + WhitelabelStore.unlisten(this.onChange); }, handleLogout(){ UserActions.logoutCurrentUser(); Alt.flush(); this.transitionTo('login'); }, + getLogo(){ + let logo = ( + + ascribe + + ); + if (this.state.whitelabel.logo){ + logo = ; + } + return logo; + }, + + getPoweredBy(){ + return ( +
+ + powered by + ascribe + + +
); + }, onChange(state) { this.setState(state); }, @@ -64,20 +93,24 @@ let Header = React.createClass({ account = LOGIN; signup = SIGNUP; } - let brand = ( - ascribe - - ); - return ( - - - - - + return ( +
+ + {this.getLogo()} + } + toggleNavKey={0}> + + + + + {this.getPoweredBy()} +
); } }); diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index e1e5d15e..aeb06d5a 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -37,7 +37,8 @@ let apiUrls = { 'users_password_reset_request': AppConstants.apiEndpoint + 'users/request_reset_password/', 'users_signup': AppConstants.apiEndpoint + 'users/', 'users_username': AppConstants.apiEndpoint + 'users/username/', - 'wallet_settings': AppConstants.apiEndpoint + 'users/wallet_settings/' + 'wallet_settings': AppConstants.apiEndpoint + 'users/wallet_settings/', + 'whitelabel_settings': AppConstants.apiEndpoint + 'whitelabel/settings/${subdomain}/' }; export default apiUrls; diff --git a/js/fetchers/whitelabel_fetcher.js b/js/fetchers/whitelabel_fetcher.js new file mode 100644 index 00000000..51f4ed0f --- /dev/null +++ b/js/fetchers/whitelabel_fetcher.js @@ -0,0 +1,14 @@ +'use strict'; + +import requests from '../utils/requests'; + +let WhitelabelFetcher = { + /** + * Fetch the custom whitelabel data from the API. + */ + fetch() { + return requests.get('whitelabel_settings', {'subdomain': window.location.host.split('.')[0]}); + } +}; + +export default WhitelabelFetcher; diff --git a/js/stores/whitelabel_store.js b/js/stores/whitelabel_store.js new file mode 100644 index 00000000..478b00a2 --- /dev/null +++ b/js/stores/whitelabel_store.js @@ -0,0 +1,18 @@ +'use strict'; + +import alt from '../alt'; +import WhitelabelActions from '../actions/whitelabel_actions'; + + +class WhitelabelStore { + constructor() { + this.whitelabel = {}; + this.bindActions(WhitelabelActions); + } + + onUpdateWhitelabel(whitelabel) { + this.whitelabel = whitelabel; + } +} + +export default alt.createStore(WhitelabelStore, 'WhitelabelStore'); diff --git a/sass/main.scss b/sass/main.scss index 3ea92fb2..eb5fd56f 100644 --- a/sass/main.scss +++ b/sass/main.scss @@ -60,6 +60,20 @@ body { color: $ascribe-color; } +.img-brand{ + height: 25px; +} + +.ascribe-subheader{ + padding-bottom: 10px; + margin-top: -10px; + a { + cursor: pointer; + font-size: 0.8em; + color: #222; + } +} + .tooltip-inner{ max-width: 300px; padding: 3px 8px; From ea770943f2852baf845bcfbe2844fdd324807550 Mon Sep 17 00:00:00 2001 From: diminator Date: Mon, 29 Jun 2015 16:15:41 +0200 Subject: [PATCH 2/2] editions and api_urls --- js/components/edition.js | 2 +- js/constants/api_urls.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/js/components/edition.js b/js/components/edition.js index bc95d391..abd35e4e 100644 --- a/js/components/edition.js +++ b/js/components/edition.js @@ -518,7 +518,7 @@ let FileUploader = React.createClass({ bitcoinId: this.props.edition.bitcoin_id }} createBlobRoutine={{ - url: apiUrls.blob_digitalworks + url: apiUrls.blob_otherdatas }} validation={{ itemLimit: 100000, diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index aeb06d5a..df3aac3f 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -6,6 +6,7 @@ let apiUrls = { 'applications': AppConstants.apiEndpoint + 'applications/', 'application_token_refresh': AppConstants.apiEndpoint + 'applications/refresh_token/', 'blob_digitalworks': AppConstants.apiEndpoint + 'blob/digitalworks/', + 'blob_otherdatas': AppConstants.apiEndpoint + 'blob/otherdatas/', 'coa': AppConstants.apiEndpoint + 'coa/${id}/', 'coa_create': AppConstants.apiEndpoint + 'coa/', 'coa_verify': AppConstants.apiEndpoint + 'coa/verify_coa/',