summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-08-07 13:30:10 +0200
committerErik Larkö <erik@mullvad.net>2017-08-07 13:30:10 +0200
commitdbd9843c12eef4828468fd9ea4500280ea5caa69 (patch)
treee2d93e9c150681522459e619bc2d7cff5e433695
parent0fd8de3cdfdf8957ad3362643fcd8e8ef9888794 (diff)
parent0990f4cfbe4df6675637b97df429d2155000d7ff (diff)
downloadmullvadvpn-dbd9843c12eef4828468fd9ea4500280ea5caa69.tar.xz
mullvadvpn-dbd9843c12eef4828468fd9ea4500280ea5caa69.zip
Merge branch 'autologin-actions'
-rw-r--r--app/lib/backend.js25
-rw-r--r--app/redux/account/actions.js4
-rw-r--r--app/redux/account/reducers.js1
-rw-r--r--test/autologin.spec.js4
-rw-r--r--test/mocks/ipc.js3
5 files changed, 11 insertions, 26 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index a58a12a0cd..d36fc36d41 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -182,11 +182,7 @@ export class Backend {
autologin() {
log.info('Attempting to log in automatically');
- this._store.dispatch(accountActions.loginChange({
- accountNumber: null,
- status: 'logging in',
- error: null,
- }));
+ this._store.dispatch(accountActions.startLogin());
return this._ipc.getAccount()
.then( accountNumber => {
@@ -194,34 +190,21 @@ export class Backend {
throw new Error('No account set in the backend, failing autologin');
}
log.debug('The backend had an account number stored:', accountNumber);
-
- this._store.dispatch(accountActions.loginChange({
- accountNumber: accountNumber,
- status: 'logging in',
- error: null,
- }));
+ this._store.dispatch(accountActions.startLogin(accountNumber));
return this._ipc.getAccountData(accountNumber);
})
.then( accountData => {
log.info('The stored account number still exists', accountData);
- this._store.dispatch(accountActions.loginChange({
- status: 'ok',
- paidUntil: accountData.paid_until,
- error: null,
- }));
+ this._store.dispatch(accountActions.loginSuccessful(accountData.paid_until));
this._store.dispatch(push('/connect'));
})
.catch( e => {
log.warn('Unable to autologin', e);
- this._store.dispatch(accountActions.loginChange({
- status: 'none',
- error: new BackendError('INVALID_ACCOUNT'),
- }));
-
+ this._store.dispatch(accountActions.loginFailed(new BackendError('INVALID_ACCOUNT')));
this._store.dispatch(push('/'));
});
}
diff --git a/app/redux/account/actions.js b/app/redux/account/actions.js
index 1be1d4c10d..288e06e857 100644
--- a/app/redux/account/actions.js
+++ b/app/redux/account/actions.js
@@ -5,7 +5,7 @@ import type { AccountReduxState } from './reducers.js';
type StartLoginAction = {
type: 'START_LOGIN',
- accountNumber: string,
+ accountNumber?: string,
};
type LoginSuccessfulAction = {
type: 'LOGIN_SUCCESSFUL',
@@ -26,7 +26,7 @@ export type AccountAction = StartLoginAction
| LoginFailedAction
| LoginChangeAction;
-function startLogin(accountNumber: string): StartLoginAction {
+function startLogin(accountNumber?: string): StartLoginAction {
return {
type: 'START_LOGIN',
accountNumber: accountNumber,
diff --git a/app/redux/account/reducers.js b/app/redux/account/reducers.js
index dedddd35b7..dc2c985285 100644
--- a/app/redux/account/reducers.js
+++ b/app/redux/account/reducers.js
@@ -38,6 +38,7 @@ export default function(state: AccountReduxState = initialState, action: ReduxAc
case 'LOGIN_FAILED':
return { ...state, ...{
status: 'failed',
+ accountNumber: null,
error: action.error,
}};
}
diff --git a/test/autologin.spec.js b/test/autologin.spec.js
index b8d4aa8356..628dc145eb 100644
--- a/test/autologin.spec.js
+++ b/test/autologin.spec.js
@@ -59,7 +59,7 @@ describe('autologin', () => {
.then( () => {
const state = store.getState().account;
- expect(state.status).to.equal('none');
+ expect(state.status).to.equal('failed');
expect(state.accountNumber).to.be.null;
expect(state.error).not.to.be.null;
});
@@ -75,7 +75,7 @@ describe('autologin', () => {
.then( () => {
const state = store.getState().account;
- expect(state.status).to.equal('none');
+ expect(state.status).to.equal('failed');
expect(state.error).not.to.be.null;
});
});
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index bd99b8d680..c182d45d21 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -15,8 +15,9 @@ export function newMockIpc() {
const mockIpc: IpcFacade & MockIpc = {
setConnectionString: (_str: string) => {},
- getAccountData: () => {
+ getAccountData: (accountNumber) => {
return new Promise(r => r({
+ accountNumber: accountNumber,
paid_until: '',
}));
},