summaryrefslogtreecommitdiff
path: root/public/bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/bundle.js')
-rw-r--r--public/bundle.js154
1 files changed, 103 insertions, 51 deletions
diff --git a/public/bundle.js b/public/bundle.js
index c6fe46a..5c65ffb 100644
--- a/public/bundle.js
+++ b/public/bundle.js
@@ -1938,9 +1938,10 @@ function render(pcm, sr, count, zip) {
Object.defineProperty(exports, "__esModule", {
value: true
});
-exports.setCurrentUser = exports.setError = exports.setToken = undefined;
+exports.setCurrentUser = exports.setError = exports.setReturnTo = exports.setToken = undefined;
exports.logout = logout;
-exports.authLoading = authLoading;
+exports.initialized = initialized;
+exports.loading = loading;
exports.InvalidCredentialsException = InvalidCredentialsException;
exports.login = login;
exports.signup = signup;
@@ -1957,6 +1958,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var setToken = exports.setToken = function setToken(data) {
return { type: _types2.default.auth.set_token, data: data };
};
+var setReturnTo = exports.setReturnTo = function setReturnTo(data) {
+ return { type: _types2.default.auth.set_return_to, data: data };
+};
var setError = exports.setError = function setError(data) {
return { type: _types2.default.auth.set_error, data: data };
};
@@ -1966,7 +1970,10 @@ var setCurrentUser = exports.setCurrentUser = function setCurrentUser(data) {
function logout() {
return { type: _types2.default.auth.logout_user };
}
-function authLoading() {
+function initialized() {
+ return { type: _types2.default.auth.initialized };
+}
+function loading() {
return { type: _types2.default.auth.loading };
}
@@ -1984,28 +1991,26 @@ var api = {
function login(username, password) {
return function (dispatch) {
- dispatch(authLoading());
+ dispatch(loading());
fetch(api.login, (0, _crud.put)({
username: username,
password: password
})).then(function (req) {
return req.json();
}).then(function (data) {
+ console.log(data);
dispatch(setToken(data.token));
dispatch(checkin());
}).catch(function (error) {
+ console.log(error);
dispatch(setError(true));
- if (error.response.status === 400) {
- throw new InvalidCredentialsException(error);
- }
- throw error;
});
};
}
function signup(data) {
return function (dispatch) {
- dispatch(authLoading());
+ dispatch(loading());
fetch(api.signup, (0, _crud.put)(data)).then(function (req) {
return req.json();
}).then(function (data) {
@@ -2013,29 +2018,24 @@ function signup(data) {
dispatch(login(data.username, data.password));
}).catch(function (error) {
console.log(error);
- if (error.response.status === 400) {
- // dispatch(accountError("There was an error creating your account."))
- throw new InvalidCredentialsException(error);
- }
- throw error;
+ dispatch(initialized());
});
};
}
-function checkin() {
+function checkin(history) {
return function (dispatch) {
- dispatch(authLoading());
- fetch(api.checkin).then(function (req) {
+ dispatch(loading());
+ fetch(api.checkin, (0, _crud.put)({})).then(function (req) {
return req.json();
}).then(function (data) {
console.log(data);
dispatch(setCurrentUser(data));
console.log('set current user');
}).catch(function (error) {
- if (error.response.status === 400) {
- throw new InvalidCredentialsException(error);
- }
- throw error;
+ console.log(error);
+ // history.go('/login')
+ dispatch(initialized(true));
});
};
}
@@ -2066,6 +2066,10 @@ var _redux = __webpack_require__(/*! redux */ "./node_modules/redux/es/redux.js"
var _reactRedux = __webpack_require__(/*! react-redux */ "./node_modules/react-redux/es/index.js");
+var _auth = __webpack_require__(/*! ./auth.actions */ "./app/client/auth/auth.actions.js");
+
+var authActions = _interopRequireWildcard(_auth);
+
var _login = __webpack_require__(/*! ./login.component */ "./app/client/auth/login.component.js");
var _login2 = _interopRequireDefault(_login);
@@ -2082,6 +2086,8 @@ var _math = __webpack_require__(/*! ../util/math */ "./app/client/util/math.js")
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -2090,37 +2096,76 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
// import PropTypes from 'prop-types';
-var AuthGate = function (_Component) {
- _inherits(AuthGate, _Component);
+var AuthRouter = function (_Component) {
+ _inherits(AuthRouter, _Component);
- function AuthGate() {
- _classCallCheck(this, AuthGate);
+ function AuthRouter() {
+ _classCallCheck(this, AuthRouter);
- return _possibleConstructorReturn(this, (AuthGate.__proto__ || Object.getPrototypeOf(AuthGate)).apply(this, arguments));
+ return _possibleConstructorReturn(this, (AuthRouter.__proto__ || Object.getPrototypeOf(AuthRouter)).apply(this, arguments));
}
- _createClass(AuthGate, [{
+ _createClass(AuthRouter, [{
key: 'render',
value: function render() {
- if (this.props.auth.isAuthenticated) return children;
return (0, _preact.h)(
_reactRouterDom.BrowserRouter,
null,
(0, _preact.h)(
'div',
null,
- (0, _preact.h)('div', { className: 'spinfx' }),
- (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/', component: _login2.default }),
- (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/login', component: _login2.default }),
- (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/logout', component: _logout2.default }),
- (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/signup', component: _signup2.default })
+ (0, _preact.h)('div', { className: 'diamond' }),
+ (0, _preact.h)(
+ _reactRouterDom.Switch,
+ null,
+ (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/', component: _login2.default }),
+ (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/login', component: _login2.default }),
+ (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/logout', component: _logout2.default }),
+ (0, _preact.h)(_reactRouterDom.Route, { exact: true, path: '/signup', component: _signup2.default }),
+ (0, _preact.h)(_reactRouterDom.Route, { component: function component() {
+ props.actions.setReturnTo(props.location.pathname);
+ return (0, _preact.h)(_reactRouterDom.Redirect, { to: '/login' });
+ } })
+ )
)
);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
- document.querySelector('.spinfx').style.backgroundImage = 'linear-gradient(' + ((0, _math.randint)(40) - 5) + 'deg, #fde, #ffe)';
+ document.querySelector('.diamond').style.backgroundImage = 'linear-gradient(' + ((0, _math.randint)(40) - 5) + 'deg, #fde, #ffe)';
+ }
+ }]);
+
+ return AuthRouter;
+}(_preact.Component);
+
+var AuthGate = function (_Component2) {
+ _inherits(AuthGate, _Component2);
+
+ function AuthGate() {
+ _classCallCheck(this, AuthGate);
+
+ return _possibleConstructorReturn(this, (AuthGate.__proto__ || Object.getPrototypeOf(AuthGate)).apply(this, arguments));
+ }
+
+ _createClass(AuthGate, [{
+ key: 'render',
+ value: function render() {
+ if (!this.props.auth.initialized) {
+ return (0, _preact.h)(
+ 'div',
+ { className: 'loading' },
+ 'Loading'
+ );
+ }
+ if (this.props.auth.isAuthenticated) return children;
+ return (0, _preact.h)(AuthRouter, this.props);
+ }
+ }, {
+ key: 'componentDidMount',
+ value: function componentDidMount() {
+ this.props.actions.checkin(history);
}
}]);
@@ -2134,7 +2179,9 @@ var mapStateToProps = function mapStateToProps(state) {
};
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
- return {};
+ return {
+ actions: (0, _redux.bindActionCreators)(authActions, dispatch)
+ };
};
exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(AuthGate);
@@ -2167,8 +2214,10 @@ var authInitialState = {
token: null,
user: {},
groups: {},
+ initialized: false,
loading: false,
- isAuthenticated: false
+ isAuthenticated: false,
+ returnTo: null
};
var auth = function auth() {
@@ -2184,6 +2233,13 @@ var auth = function auth() {
error: null
});
+ case _types2.default.auth.initialized:
+ return _extends({}, state, {
+ loading: false,
+ initialized: true,
+ error: null
+ });
+
case _types2.default.auth.loading:
return _extends({}, state, {
loading: true,
@@ -2191,22 +2247,16 @@ var auth = function auth() {
});
case _types2.default.auth.set_current_user:
- var groups = {};
- action.data.groups.forEach(function (g) {
- return groups[g.name.toLowerCase()] = true;
- });
- if (action.data.is_staff) {
- groups['staff'] = true;
- }
- if (action.data.is_superuser) {
- groups['superuser'] = true;
- }
return _extends({}, state, {
user: action.data,
- groups: groups,
error: null
});
+ case _types2.default.auth.set_return_to:
+ return _extends({}, state, {
+ returnTo: action.data
+ });
+
case _types2.default.auth.logout_user:
return _extends({}, authInitialState);
@@ -2359,6 +2409,7 @@ var Login = function (_Component) {
key: 'handleSubmit',
value: function handleSubmit(e) {
e.preventDefault();
+ if (this.props.auth.loading) return;
this.props.actions.login(this.state.username, this.state.password);
}
}, {
@@ -2596,7 +2647,8 @@ var Signup = function (_Component) {
key: 'handleSubmit',
value: function handleSubmit(e) {
e.preventDefault();
- if (!this.validate) {
+ if (this.props.auth.loading) return;
+ if (!this.validate()) {
return this.props.actions.setError('bad password');
}
@@ -2664,10 +2716,10 @@ var Signup = function (_Component) {
return (0, _preact.h)(
'div',
{ className: 'form-input-hint' },
- "Please doublecheck the form"
+ "Please doublecheck the form (o=_o~~)"
);
}
- return null;
+ return (0, _preact.h)('div', { className: 'form-input-hint' });
}
}]);
@@ -17247,7 +17299,7 @@ exports.default = {
folder: (0, _crud.crud_type)('folder', []),
file: (0, _crud.crud_type)('file', []),
task: (0, _crud.crud_type)('task', ['starting_task', 'stopping_task', 'task_begin', 'task_finish', 'start_queue', 'stop_queue', 'starting_queue', 'stopping_queue', 'progress', 'epoch']),
- auth: (0, _crud.crud_type)('auth', ['set_token', 'set_error', 'set_current_user', 'logout_user', 'loading']),
+ auth: (0, _crud.crud_type)('auth', ['set_token', 'set_error', 'set_current_user', 'logout_user', 'loading', 'initialized', 'set_return_to']),
socket: {
connect: 'SOCKET_CONNECT',
connect_error: 'SOCKET_CONNECT_ERROR',