|
|
@ -5,19 +5,17 @@ import * as EteSync from '../api/EteSync';
|
|
|
|
import { CredentialsData, EntriesType } from './';
|
|
|
|
import { CredentialsData, EntriesType } from './';
|
|
|
|
|
|
|
|
|
|
|
|
export const { fetchCredentials, logout } = createActions({
|
|
|
|
export const { fetchCredentials, logout } = createActions({
|
|
|
|
FETCH_CREDENTIALS: (username: string, password: string, encryptionPassword: string, server: string) => {
|
|
|
|
FETCH_CREDENTIALS: (username: string, password: string, server: string) => {
|
|
|
|
const authenticator = new EteSync.Authenticator(server);
|
|
|
|
const authenticator = new EteSync.Authenticator(server);
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
authenticator.getAuthToken(username, password).then(
|
|
|
|
authenticator.getAuthToken(username, password).then(
|
|
|
|
(authToken) => {
|
|
|
|
(authToken) => {
|
|
|
|
const creds = new EteSync.Credentials(username, authToken);
|
|
|
|
const creds = new EteSync.Credentials(username, authToken);
|
|
|
|
const derived = EteSync.deriveKey(username, encryptionPassword);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const context = {
|
|
|
|
const context = {
|
|
|
|
serviceApiUrl: server,
|
|
|
|
serviceApiUrl: server,
|
|
|
|
credentials: creds,
|
|
|
|
credentials: creds,
|
|
|
|
encryptionKey: derived,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
resolve(context);
|
|
|
|
resolve(context);
|
|
|
@ -31,13 +29,20 @@ export const { fetchCredentials, logout } = createActions({
|
|
|
|
LOGOUT: () => undefined,
|
|
|
|
LOGOUT: () => undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: This is duplicating behaviour from the fetchCredentials above
|
|
|
|
|
|
|
|
export const { deriveKey } = createActions({
|
|
|
|
export const { deriveKey } = createActions({
|
|
|
|
DERIVE_KEY: (username: string, encryptionPassword: string) => {
|
|
|
|
DERIVE_KEY: (username: string, encryptionPassword: string) => {
|
|
|
|
return EteSync.deriveKey(username, encryptionPassword);
|
|
|
|
return EteSync.deriveKey(username, encryptionPassword);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const login = (username: string, password: string, encryptionPassword: string, server: string) => {
|
|
|
|
|
|
|
|
return (dispatch: any) => {
|
|
|
|
|
|
|
|
dispatch(fetchCredentials(username, password, server)).then(() =>
|
|
|
|
|
|
|
|
dispatch(deriveKey(username, encryptionPassword))
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const { fetchJournals } = createActions({
|
|
|
|
export const { fetchJournals } = createActions({
|
|
|
|
FETCH_JOURNALS: (etesync: CredentialsData) => {
|
|
|
|
FETCH_JOURNALS: (etesync: CredentialsData) => {
|
|
|
|
const creds = etesync.credentials;
|
|
|
|
const creds = etesync.credentials;
|
|
|
|