summaryrefslogtreecommitdiffhomepage
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/backend-redux-actions.js15
-rw-r--r--app/lib/backend.js24
2 files changed, 29 insertions, 10 deletions
diff --git a/app/lib/backend-redux-actions.js b/app/lib/backend-redux-actions.js
index 5718278dde..3fff1e1127 100644
--- a/app/lib/backend-redux-actions.js
+++ b/app/lib/backend-redux-actions.js
@@ -29,23 +29,24 @@ export default function mapBackendEventsToReduxActions(backend, store) {
}));
};
- const onLoggingIn = (account) => {
- store.dispatch(userActions.loginChange({
+ const onLoggingIn = (info) => {
+ store.dispatch(userActions.loginChange(Object.assign({
status: LoginState.connecting,
- error: null,
- account
- }));
+ error: null
+ }, info)));
};
- const onLogin = (account, error) => {
+ const onLogin = (info, error) => {
const status = error ? LoginState.failed : LoginState.ok;
- store.dispatch(userActions.loginChange({ status, error }));
+ const paidUntil = info.paidUntil ? info.paidUntil : null;
+ store.dispatch(userActions.loginChange({ paidUntil, status, error }));
};
const onLogout = () => {
store.dispatch(userActions.loginChange({
status: LoginState.none,
account: null,
+ paidUntil: null,
error: null
}));
};
diff --git a/app/lib/backend.js b/app/lib/backend.js
index 2a608e52a1..601b0e7b64 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -1,3 +1,4 @@
+import moment from 'moment';
import Enum from './enum';
import { EventEmitter } from 'events';
import { servers } from '../config';
@@ -19,6 +20,7 @@ export default class Backend extends EventEmitter {
constructor() {
super();
this._account = null;
+ this._paidUntil = null;
this._serverAddress = null;
this._connStatus = ConnectionState.disconnected;
this._cancellationHandler = null;
@@ -30,6 +32,7 @@ export default class Backend extends EventEmitter {
// Accessors
get account() { return this._account; }
+ get paidUntil() { return this._paidUntil; }
get serverAddress() { return this._serverAddress; }
// Public methods
@@ -66,6 +69,10 @@ export default class Backend extends EventEmitter {
this._account = user.account;
}
+ if(user.paidUntil) {
+ this._paidUntil = user.paidUntil;
+ }
+
this._connStatus = mapConnStatus(connect.status);
}
@@ -99,23 +106,34 @@ export default class Backend extends EventEmitter {
login(account) {
this._account = account;
+ this._paidUntil = null;
// emit: logging in
- this.emit(EventType.logging, account, null);
+ this.emit(EventType.logging, { account, paidUntil: this._paidUntil }, null);
// @TODO: Add login call
setTimeout(() => {
let err = null;
- if(!account.startsWith('1111')) {
+ let res = { account };
+
+ if(account.startsWith('1111')) { // accounts starting with 1111 expire in one month
+ res.paidUntil = moment().add(1, 'month').millisecond(0).toISOString();
+ } else if(account.startsWith('2222')) { // expired in 2013
+ res.paidUntil = moment('2013-01-01').toISOString();
+ } else if(account.startsWith('3333')) { // expire in 2038
+ res.paidUntil = moment('2038-01-01').toISOString();
+ } else {
err = new Error('Invalid account number.');
}
+
// emit: login
- this.emit(EventType.login, account, err);
+ this.emit(EventType.login, res, err);
}, 2000);
}
logout() {
this._account = null;
+ this._paidUntil = null;
// emit event
this.emit(EventType.logout);