@@ -1,113 +0,0 @@ | |||||
let landingPage = null; | |||||
export function getLandingPage () { return landingPage; } | |||||
export function setLandingPage (page) { landingPage = page; } | |||||
export function resetLandingPage () { landingPage = null; } | |||||
export function currentUser() { | |||||
let userJson = localStorage.getItem('user'); | |||||
return userJson ? JSON.parse(userJson) : null; | |||||
} | |||||
export function userLoggedIn() { return !!currentUser(); } | |||||
export function authHeader() { | |||||
// return authorization header with jwt token | |||||
let user = currentUser(); | |||||
if (user && user.token) { | |||||
return { 'X-Bubble-Session': user.token }; | |||||
} else { | |||||
return {}; | |||||
} | |||||
} | |||||
export function getWithAuth() { | |||||
return { | |||||
method: 'GET', | |||||
headers: authHeader() | |||||
}; | |||||
} | |||||
function entityWithAuth(method, obj) { | |||||
if (typeof obj === 'undefined' || obj === null || obj === 'undefined') { | |||||
return { | |||||
method: method, | |||||
headers: { ...authHeader(), 'Content-Type': 'application/json' } | |||||
}; | |||||
} else { | |||||
return { | |||||
method: method, | |||||
headers: { ...authHeader(), 'Content-Type': 'application/json' }, | |||||
body: JSON.stringify(obj) | |||||
}; | |||||
} | |||||
} | |||||
export function postWithAuth(obj) { return entityWithAuth('POST', obj); } | |||||
export function putWithAuth(obj) { return entityWithAuth('PUT', obj); } | |||||
export function deleteWithAuth() { | |||||
return { | |||||
method: 'DELETE', | |||||
headers: authHeader() | |||||
}; | |||||
} | |||||
export function handleBasicResponse(response) { | |||||
return response.text().then(text => { | |||||
const data = text && JSON.parse(text); | |||||
if (!response.ok) { | |||||
const error = (data && data.message) || response.statusText; | |||||
return Promise.reject(error); | |||||
} | |||||
return data; | |||||
}); | |||||
} | |||||
export function handleCrudResponse(messages, errors) { | |||||
return function (response) { | |||||
return response.text().then(text => { | |||||
const data = text && JSON.parse(text); | |||||
if (!response.ok) { | |||||
if (response.status === 404) { | |||||
// todo: show nicer error message | |||||
console.log('handleCrudResponse: received 404: ' + JSON.stringify(data)); | |||||
} else if (response.status === 422) { | |||||
console.log('handleCrudResponse: received 422, error: ' + JSON.stringify(data)); | |||||
setValidationErrors(data, messages, errors); | |||||
} | |||||
const error = (data && data.message) || response.statusText; | |||||
return Promise.reject(error); | |||||
} | |||||
return data; | |||||
}); | |||||
} | |||||
} | |||||
export function setValidationErrors(data, messages, errors) { | |||||
for (let i=0; i<data.length; i++) { | |||||
if (data[i].messageTemplate) { | |||||
const parts = data[i].messageTemplate.split(/[._]+/); | |||||
if (parts.length === 3 && parts[0] === 'err') { | |||||
const field = parts[1]; | |||||
const messageTemplate = data[i].messageTemplate.replace(/\./g, '_'); | |||||
const message = messages.hasOwnProperty(messageTemplate) ? messages[messageTemplate] : '???'+messageTemplate; | |||||
errors.add({field: field, msg: message}); | |||||
console.log('>>>>> field '+field+' added error: '+message+', errors='+JSON.stringify(errors)); | |||||
} | |||||
} | |||||
// todo: else add "global" error message for unrecognized/non-field error | |||||
} | |||||
} | |||||
export function checkLoading(loadingArray) { | |||||
return function() { | |||||
for (const key in loadingArray) { | |||||
if (key === true) return true; | |||||
} | |||||
return false; | |||||
}; | |||||
} |
@@ -1,2 +1,2 @@ | |||||
export * from './util'; | |||||
export * from './router'; | export * from './router'; | ||||
export * from './api-util'; |
@@ -17,7 +17,7 @@ import AccountsPage from '../admin/AccountsPage' | |||||
import StripePayment from "../account/payment/StripePayment"; | import StripePayment from "../account/payment/StripePayment"; | ||||
import InviteCodePayment from "../account/payment/InviteCodePayment"; | import InviteCodePayment from "../account/payment/InviteCodePayment"; | ||||
import UnknownPayment from "../account/payment/UnknownPayment"; | import UnknownPayment from "../account/payment/UnknownPayment"; | ||||
import { currentUser, setLandingPage } from '../_helpers' | |||||
import { util } from '../_helpers' | |||||
Vue.use(Router); | Vue.use(Router); | ||||
@@ -79,12 +79,12 @@ export const router = new Router({ | |||||
router.beforeEach((to, from, next) => { | router.beforeEach((to, from, next) => { | ||||
const publicPages = ['/login', '/logout', '/register', '/auth']; | const publicPages = ['/login', '/logout', '/register', '/auth']; | ||||
const authRequired = !publicPages.includes(to.path); | const authRequired = !publicPages.includes(to.path); | ||||
const user = currentUser(); | |||||
const user = util.currentUser(); | |||||
if (authRequired) { | if (authRequired) { | ||||
// redirect to login page if not logged in and trying to access a restricted page | // redirect to login page if not logged in and trying to access a restricted page | ||||
if (!user) { | if (!user) { | ||||
setLandingPage(to); | |||||
util.setLandingPage(to); | |||||
return next('/login'); | return next('/login'); | ||||
} | } | ||||
@@ -0,0 +1,120 @@ | |||||
let landingPage = null; | |||||
export const util = { | |||||
getLandingPage: function () { return landingPage; }, | |||||
setLandingPage: function (page) { landingPage = page; }, | |||||
resetLandingPage: function () { landingPage = null; }, | |||||
currentUser: function() { | |||||
let userJson = localStorage.getItem('user'); | |||||
return userJson ? JSON.parse(userJson) : null; | |||||
}, | |||||
userLoggedIn: function() { return !!util.currentUser(); }, | |||||
authHeader: function() { | |||||
// return authorization header with jwt token | |||||
let user = util.currentUser(); | |||||
if (user && user.token) { | |||||
return { 'X-Bubble-Session': user.token }; | |||||
} else { | |||||
return {}; | |||||
} | |||||
}, | |||||
getWithAuth: function() { | |||||
return { | |||||
method: 'GET', | |||||
headers: authHeader() | |||||
}; | |||||
}, | |||||
entityWithAuth: function(method, obj) { | |||||
if (typeof obj === 'undefined' || obj === null || obj === 'undefined') { | |||||
return { | |||||
method: method, | |||||
headers: { ...authHeader(), 'Content-Type': 'application/json' } | |||||
}; | |||||
} else { | |||||
return { | |||||
method: method, | |||||
headers: { ...authHeader(), 'Content-Type': 'application/json' }, | |||||
body: JSON.stringify(obj) | |||||
}; | |||||
} | |||||
}, | |||||
postWithAuth: function(obj) { return entityWithAuth('POST', obj); }, | |||||
putWithAuth: function(obj) { return entityWithAuth('PUT', obj); }, | |||||
deleteWithAuth: function() { | |||||
return { | |||||
method: 'DELETE', | |||||
headers: authHeader() | |||||
}; | |||||
}, | |||||
handleBasicResponse: function(response) { | |||||
return response.text().then(text => { | |||||
const data = text && JSON.parse(text); | |||||
if (!response.ok) { | |||||
const error = (data && data.message) || response.statusText; | |||||
return Promise.reject(error); | |||||
} | |||||
return data; | |||||
}); | |||||
}, | |||||
handleCrudResponse: function(messages, errors) { | |||||
return function (response) { | |||||
return response.text().then(text => { | |||||
const data = text && JSON.parse(text); | |||||
if (!response.ok) { | |||||
if (response.status === 404) { | |||||
// todo: show nicer error message | |||||
console.log('handleCrudResponse: received 404: ' + JSON.stringify(data)); | |||||
} else if (response.status === 422) { | |||||
console.log('handleCrudResponse: received 422, error: ' + JSON.stringify(data)); | |||||
setValidationErrors(data, messages, errors); | |||||
} | |||||
const error = (data && data.message) || response.statusText; | |||||
return Promise.reject(error); | |||||
} | |||||
return data; | |||||
}); | |||||
} | |||||
}, | |||||
setValidationErrors: function(data, messages, errors) { | |||||
for (let i=0; i<data.length; i++) { | |||||
if (data[i].messageTemplate) { | |||||
const parts = data[i].messageTemplate.split(/[._]+/); | |||||
if (parts.length === 3 && parts[0] === 'err') { | |||||
const field = parts[1]; | |||||
const messageTemplate = data[i].messageTemplate.replace(/\./g, '_'); | |||||
const message = messages.hasOwnProperty(messageTemplate) ? messages[messageTemplate] : '???'+messageTemplate; | |||||
errors.add({field: field, msg: message}); | |||||
console.log('>>>>> field '+field+' added error: '+message+', errors='+JSON.stringify(errors)); | |||||
} | |||||
} | |||||
// todo: else add "global" error message for unrecognized/non-field error | |||||
} | |||||
}, | |||||
checkLoading: function(loadingObject) { | |||||
return function() { | |||||
for (const key in loadingObject) { | |||||
if (loadingObject.hasOwnProperty(key)) { | |||||
if (loadingObject[key] === true) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
}; | |||||
}, | |||||
}; |
@@ -1,5 +1,6 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, putWithAuth, handleCrudResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
// import { util.getWithAuth, util.putWithAuth, util.handleCrudResponse } from '../_helpers'; | |||||
export const accountPlanService = { | export const accountPlanService = { | ||||
getAll, | getAll, | ||||
@@ -8,13 +9,13 @@ export const accountPlanService = { | |||||
}; | }; | ||||
function getAll(userId, messages, errors) { | function getAll(userId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(userId, accountPlanId, messages, errors) { | function getById(userId, accountPlanId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans/${accountPlanId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans/${accountPlanId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function newAccountPlan(userId, accountPlan, messages, errors) { | function newAccountPlan(userId, accountPlan, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans`, putWithAuth(accountPlan)).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${userId}/accountPlans`, util.putWithAuth(accountPlan)).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import {currentUser, getWithAuth, handleCrudResponse} from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const domainService = { | export const domainService = { | ||||
getAll, | getAll, | ||||
@@ -7,9 +7,9 @@ export const domainService = { | |||||
}; | }; | ||||
function getAll(messages, errors) { | function getAll(messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/domains`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/domains`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(domainId, messages, errors) { | function getById(domainId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/domains/${domainId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/domains/${domainId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, handleCrudResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const footprintService = { | export const footprintService = { | ||||
getAll, | getAll, | ||||
@@ -7,9 +7,9 @@ export const footprintService = { | |||||
}; | }; | ||||
function getAll(messages, errors) { | function getAll(messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/footprints`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/footprints`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(footprintId, messages, errors) { | function getById(footprintId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/footprints/${footprintId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/footprints/${footprintId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, handleCrudResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const networkService = { | export const networkService = { | ||||
getAll, | getAll, | ||||
@@ -7,14 +7,14 @@ export const networkService = { | |||||
}; | }; | ||||
function getAll(userId, messages, errors) { | function getAll(userId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${userId}/networks`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${userId}/networks`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(userId, networkId, messages, errors) { | function getById(userId, networkId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${userId}/networks/${networkId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getNearestRegions(userId, footprint, messages, errors) { | function getNearestRegions(userId, footprint, messages, errors) { | ||||
const footprintParam = (typeof footprint === "undefined" || footprint === null || footprint === '') ? "" : `?footprint=${footprint}`; | const footprintParam = (typeof footprint === "undefined" || footprint === null || footprint === '') ? "" : `?footprint=${footprint}`; | ||||
return fetch(`${config.apiUrl}/me/regions/closest${footprintParam}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/regions/closest${footprintParam}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, putWithAuth, handleCrudResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const paymentMethodService = { | export const paymentMethodService = { | ||||
getAll, | getAll, | ||||
@@ -10,22 +10,22 @@ export const paymentMethodService = { | |||||
}; | }; | ||||
function getAll(messages, errors) { | function getAll(messages, errors) { | ||||
return fetch(`${config.apiUrl}/paymentMethods`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/paymentMethods`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(paymentMethodId, messages, errors) { | function getById(paymentMethodId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/paymentMethods/${paymentMethodId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/paymentMethods/${paymentMethodId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getAllByAccount(messages, errors) { | function getAllByAccount(messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/paymentMethods`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/paymentMethods`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getByAccountAndId(paymentMethodId, messages, errors) { | function getByAccountAndId(paymentMethodId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/me/paymentMethods/${paymentMethodId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/paymentMethods/${paymentMethodId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function addAccountPaymentMethod(paymentMethod, messages, errors) { | function addAccountPaymentMethod(paymentMethod, messages, errors) { | ||||
console.log("pmService: paymentMethod="+JSON.stringify(paymentMethod)); | console.log("pmService: paymentMethod="+JSON.stringify(paymentMethod)); | ||||
return fetch(`${config.apiUrl}/me/paymentMethods`, putWithAuth(paymentMethod)).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/me/paymentMethods`, util.putWithAuth(paymentMethod)).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, handleCrudResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const planService = { | export const planService = { | ||||
getAll, | getAll, | ||||
@@ -7,9 +7,9 @@ export const planService = { | |||||
}; | }; | ||||
function getAll(messages, errors) { | function getAll(messages, errors) { | ||||
return fetch(`${config.apiUrl}/plans`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/plans`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(planId, messages, errors) { | function getById(planId, messages, errors) { | ||||
return fetch(`${config.apiUrl}/plans/${planId}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/plans/${planId}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, userLoggedIn, handleBasicResponse } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const systemService = { | export const systemService = { | ||||
loadSystemConfigs, | loadSystemConfigs, | ||||
@@ -10,37 +10,37 @@ export const systemService = { | |||||
}; | }; | ||||
function loadSystemConfigs() { | function loadSystemConfigs() { | ||||
const requestOptions = userLoggedIn() ? getWithAuth() : { method: 'GET' }; | |||||
const requestOptions = util.userLoggedIn() ? util.getWithAuth() : { method: 'GET' }; | |||||
return fetch(`${config.apiUrl}/auth/configs`, requestOptions) | return fetch(`${config.apiUrl}/auth/configs`, requestOptions) | ||||
.then(handleBasicResponse) | |||||
.then(util.handleBasicResponse) | |||||
.then(configs => { return configs; }); | .then(configs => { return configs; }); | ||||
} | } | ||||
function loadMessages(group, locale) { | function loadMessages(group, locale) { | ||||
const requestOptions = userLoggedIn() ? getWithAuth() : { method: 'GET' }; | |||||
const requestOptions = util.userLoggedIn() ? util.getWithAuth() : { method: 'GET' }; | |||||
if (!locale || locale === '') locale = 'detect'; | if (!locale || locale === '') locale = 'detect'; | ||||
return fetch(`${config.apiUrl}/messages/${locale}/${group}`, requestOptions) | return fetch(`${config.apiUrl}/messages/${locale}/${group}`, requestOptions) | ||||
.then(handleBasicResponse) | |||||
.then(util.handleBasicResponse) | |||||
.then(messages => { return messages; }); | .then(messages => { return messages; }); | ||||
} | } | ||||
function loadTimezones() { | function loadTimezones() { | ||||
const requestOptions = userLoggedIn() ? getWithAuth() : { method: 'GET' }; | |||||
const requestOptions = util.userLoggedIn() ? util.getWithAuth() : { method: 'GET' }; | |||||
return fetch(`${config.apiUrl}/timezones`, requestOptions) | return fetch(`${config.apiUrl}/timezones`, requestOptions) | ||||
.then(handleBasicResponse) | |||||
.then(util.handleBasicResponse) | |||||
.then(timezones => { return timezones; }); | .then(timezones => { return timezones; }); | ||||
} | } | ||||
function detectTimezone() { | function detectTimezone() { | ||||
const requestOptions = userLoggedIn() ? getWithAuth() : { method: 'GET' }; | |||||
const requestOptions = util.userLoggedIn() ? util.getWithAuth() : { method: 'GET' }; | |||||
return fetch(`${config.apiUrl}/detect/timezone`, requestOptions) | return fetch(`${config.apiUrl}/detect/timezone`, requestOptions) | ||||
.then(handleBasicResponse) | |||||
.then(util.handleBasicResponse) | |||||
.then(timezone => { return timezone; }); | .then(timezone => { return timezone; }); | ||||
} | } | ||||
function detectLocale () { | function detectLocale () { | ||||
const requestOptions = userLoggedIn() ? getWithAuth() : { method: 'GET' }; | |||||
const requestOptions = util.userLoggedIn() ? util.getWithAuth() : { method: 'GET' }; | |||||
return fetch(`${config.apiUrl}/detect/locale`, requestOptions) | return fetch(`${config.apiUrl}/detect/locale`, requestOptions) | ||||
.then(handleBasicResponse) | |||||
.then(util.handleBasicResponse) | |||||
.then(locales => { return locales; }); | .then(locales => { return locales; }); | ||||
} | } |
@@ -1,5 +1,5 @@ | |||||
import config from 'config'; | import config from 'config'; | ||||
import { getWithAuth, postWithAuth, deleteWithAuth, handleCrudResponse, setValidationErrors } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
export const userService = { | export const userService = { | ||||
login, | login, | ||||
@@ -56,61 +56,61 @@ function register(user, messages, errors) { | |||||
} | } | ||||
function getAll(messages, errors) { | function getAll(messages, errors) { | ||||
return fetch(`${config.apiUrl}/users`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getById(id, messages, errors) { | function getById(id, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function getPolicyById(id, messages, errors) { | function getPolicyById(id, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}/policy`, getWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}/policy`, util.getWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function updatePolicyById(id, policy, messages, errors) { | function updatePolicyById(id, policy, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}/policy`, postWithAuth(policy)).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}/policy`, util.postWithAuth(policy)).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function addPolicyContactById(id, contact, messages, errors) { | function addPolicyContactById(id, contact, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts`, postWithAuth(contact)).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts`, util.postWithAuth(contact)).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function removePolicyContactByUuid(id, uuid, messages, errors) { | function removePolicyContactByUuid(id, uuid, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts/${uuid}`, deleteWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts/${uuid}`, util.deleteWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function approveAction(id, code, messages, errors) { | function approveAction(id, code, messages, errors) { | ||||
return fetch(`${config.apiUrl}/auth/approve/${code}`, postWithAuth([{'name': 'account', 'value': id}])) | |||||
.then(handleCrudResponse(messages, errors)) | |||||
return fetch(`${config.apiUrl}/auth/approve/${code}`, util.postWithAuth([{'name': 'account', 'value': id}])) | |||||
.then(util.handleCrudResponse(messages, errors)) | |||||
.then(setSessionUser); | .then(setSessionUser); | ||||
} | } | ||||
function sendAuthenticatorCode(id, code, verifyOnly, messages, errors) { | function sendAuthenticatorCode(id, code, verifyOnly, messages, errors) { | ||||
return fetch(`${config.apiUrl}/auth/authenticator`, postWithAuth({ | |||||
return fetch(`${config.apiUrl}/auth/authenticator`, util.postWithAuth({ | |||||
account: id, | account: id, | ||||
token: code, | token: code, | ||||
verify: verifyOnly | verify: verifyOnly | ||||
})) | })) | ||||
.then(handleCrudResponse(messages, errors)) | |||||
.then(util.handleCrudResponse(messages, errors)) | |||||
.then(setSessionUser); | .then(setSessionUser); | ||||
} | } | ||||
function resendVerificationCode(id, contact, messages, errors) { | function resendVerificationCode(id, contact, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts/verify`, postWithAuth(contact)) | |||||
.then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}/policy/contacts/verify`, util.postWithAuth(contact)) | |||||
.then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function denyAction(id, code, messages, errors) { | function denyAction(id, code, messages, errors) { | ||||
return fetch(`${config.apiUrl}/auth/deny/${code}`, postWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/auth/deny/${code}`, util.postWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function update(user, messages, errors) { | function update(user, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${user.uuid}`, postWithAuth(user)).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${user.uuid}`, util.postWithAuth(user)).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
// prefixed function name with underscore because delete is a reserved word in javascript | // prefixed function name with underscore because delete is a reserved word in javascript | ||||
function _delete(id, messages, errors) { | function _delete(id, messages, errors) { | ||||
return fetch(`${config.apiUrl}/users/${id}`, deleteWithAuth()).then(handleCrudResponse(messages, errors)); | |||||
return fetch(`${config.apiUrl}/users/${id}`, util.deleteWithAuth()).then(util.handleCrudResponse(messages, errors)); | |||||
} | } | ||||
function handleAuthResponse(messages, errors) { | function handleAuthResponse(messages, errors) { | ||||
@@ -129,7 +129,7 @@ function handleAuthResponse(messages, errors) { | |||||
console.log('handleAuthResponse: received 404, user not found: '+JSON.stringify(data)); | console.log('handleAuthResponse: received 404, user not found: '+JSON.stringify(data)); | ||||
} else if (response.status === 422) { | } else if (response.status === 422) { | ||||
setValidationErrors(data, messages, errors); | |||||
util.setValidationErrors(data, messages, errors); | |||||
} | } | ||||
const error = (data && data.message) || response.statusText; | const error = (data && data.message) || response.statusText; | ||||
return Promise.reject(error); | return Promise.reject(error); | ||||
@@ -1,5 +1,5 @@ | |||||
import { userService } from '../_services'; | import { userService } from '../_services'; | ||||
import { router, getLandingPage, resetLandingPage } from '../_helpers'; | |||||
import { router, util } from '../_helpers'; | |||||
// todo: why can't we import currentUser from api-util and use that here? | // todo: why can't we import currentUser from api-util and use that here? | ||||
// when I try to do that, webpack succeeds but then an error occurs loading any page, with the | // when I try to do that, webpack succeeds but then an error occurs loading any page, with the | ||||
@@ -22,11 +22,11 @@ const actions = { | |||||
user => { | user => { | ||||
commit('loginSuccess', user); | commit('loginSuccess', user); | ||||
if (user.token) { | if (user.token) { | ||||
const landing = getLandingPage(); | |||||
const landing = util.getLandingPage(); | |||||
if (landing === null) { | if (landing === null) { | ||||
router.replace('/'); | router.replace('/'); | ||||
} else { | } else { | ||||
resetLandingPage(); | |||||
util.resetLandingPage(); | |||||
router.replace(landing.fullPath); | router.replace(landing.fullPath); | ||||
} | } | ||||
} else if (user.multifactorAuth) { | } else if (user.multifactorAuth) { | ||||
@@ -1,6 +1,6 @@ | |||||
import { accountPlanService } from '../_services'; | import { accountPlanService } from '../_services'; | ||||
import { account } from '../_store/account.module'; | import { account } from '../_store/account.module'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: {plans: false, plan: false, deleting: false}, | loading: {plans: false, plan: false, deleting: false}, | ||||
@@ -82,7 +82,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const accountPlans = { | export const accountPlans = { | ||||
@@ -1,5 +1,5 @@ | |||||
import { domainService } from '../_services'; | import { domainService } from '../_services'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: { | loading: { | ||||
@@ -56,7 +56,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const domains = { | export const domains = { | ||||
@@ -1,5 +1,5 @@ | |||||
import { footprintService } from '../_services'; | import { footprintService } from '../_services'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: { footprints: false, footprint: false }, | loading: { footprints: false, footprint: false }, | ||||
@@ -54,7 +54,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const footprints = { | export const footprints = { | ||||
@@ -1,6 +1,6 @@ | |||||
import { networkService } from '../_services'; | import { networkService } from '../_services'; | ||||
import { account } from '../_store/account.module'; | import { account } from '../_store/account.module'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: { | loading: { | ||||
@@ -107,7 +107,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const networks = { | export const networks = { | ||||
@@ -1,5 +1,5 @@ | |||||
import { paymentMethodService } from '../_services'; | import { paymentMethodService } from '../_services'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: { | loading: { | ||||
@@ -149,7 +149,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const paymentMethods = { | export const paymentMethods = { | ||||
@@ -1,5 +1,5 @@ | |||||
import { planService } from '../_services'; | import { planService } from '../_services'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: {plans: false, plan: false, deleting: false}, | loading: {plans: false, plan: false, deleting: false}, | ||||
@@ -78,7 +78,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const plans = { | export const plans = { | ||||
@@ -1,6 +1,6 @@ | |||||
import { userService } from '../_services'; | import { userService } from '../_services'; | ||||
import { account } from '../_store/account.module'; | import { account } from '../_store/account.module'; | ||||
import { checkLoading } from "../_helpers"; | |||||
import { util } from '../_helpers'; | |||||
const state = { | const state = { | ||||
loading: { | loading: { | ||||
@@ -249,7 +249,7 @@ const mutations = { | |||||
}; | }; | ||||
const getters = { | const getters = { | ||||
loading: checkLoading(state.loading) | |||||
loading: util.checkLoading(state.loading) | |||||
}; | }; | ||||
export const users = { | export const users = { | ||||
@@ -164,7 +164,7 @@ | |||||
<script> | <script> | ||||
import { mapState, mapActions, mapGetters } from 'vuex' | import { mapState, mapActions, mapGetters } from 'vuex' | ||||
import { currentUser } from '../_helpers' | |||||
import { util } from '../_helpers' | |||||
// convenience methods | // convenience methods | ||||
import { isAuthenticator, isNotAuthenticator } from '../_store/users.module'; | import { isAuthenticator, isNotAuthenticator } from '../_store/users.module'; | ||||
@@ -172,10 +172,10 @@ | |||||
window.isNotAuthenticator = isNotAuthenticator; | window.isNotAuthenticator = isNotAuthenticator; | ||||
function initDefaults(comp) { | function initDefaults(comp) { | ||||
comp.getPolicyByUuid({uuid: currentUser().uuid, messages: comp.messages, errors: comp.errors}); | |||||
comp.getPolicyByUuid({uuid: util.currentUser().uuid, messages: comp.messages, errors: comp.errors}); | |||||
comp.detectTimezone(); | comp.detectTimezone(); | ||||
comp.detectLocale(); | comp.detectLocale(); | ||||
comp.loadDomains(currentUser().uuid, comp.messages, comp.errors); | |||||
comp.loadDomains(util.currentUser().uuid, comp.messages, comp.errors); | |||||
comp.loadPlans(comp.messages, comp.errors); | comp.loadPlans(comp.messages, comp.errors); | ||||
comp.loadFootprints(comp.messages, comp.errors); | comp.loadFootprints(comp.messages, comp.errors); | ||||
comp.loadPaymentMethods(comp.messages, comp.errors); | comp.loadPaymentMethods(comp.messages, comp.errors); | ||||
@@ -213,7 +213,7 @@ | |||||
footprint: 'Worldwide', | footprint: 'Worldwide', | ||||
region: '' | region: '' | ||||
}, | }, | ||||
user: currentUser(), | |||||
user: util.currentUser(), | |||||
submitted: false, | submitted: false, | ||||
status: { | status: { | ||||
creating: false | creating: false | ||||
@@ -357,7 +357,7 @@ | |||||
if (code === null || code === '') return; | if (code === null || code === '') return; | ||||
this.errors.clear(); | this.errors.clear(); | ||||
this.approveAction({ | this.approveAction({ | ||||
uuid: currentUser().uuid, | |||||
uuid: util.currentUser().uuid, | |||||
code: code, | code: code, | ||||
messages: this.messages, | messages: this.messages, | ||||
errors: this.errors | errors: this.errors | ||||
@@ -368,7 +368,7 @@ | |||||
}, | }, | ||||
resendVerification(contact) { | resendVerification(contact) { | ||||
this.resendVerificationCode({ | this.resendVerificationCode({ | ||||
uuid: currentUser().uuid, | |||||
uuid: util.currentUser().uuid, | |||||
contact: contact, | contact: contact, | ||||
messages: this.messages, | messages: this.messages, | ||||
errors: this.errors | errors: this.errors | ||||
@@ -33,7 +33,7 @@ | |||||
<script> | <script> | ||||
import { mapState, mapActions } from 'vuex' | import { mapState, mapActions } from 'vuex' | ||||
import { getLandingPage, resetLandingPage } from '../_helpers'; | |||||
import { util } from '../_helpers'; | |||||
// convenience methods | // convenience methods | ||||
import { isAuthenticator, isNotAuthenticator } from '../_store/users.module'; | import { isAuthenticator, isNotAuthenticator } from '../_store/users.module'; | ||||
@@ -57,8 +57,8 @@ | |||||
]), | ]), | ||||
isAuthenticator(val) { return window.isAuthenticator(val); }, | isAuthenticator(val) { return window.isAuthenticator(val); }, | ||||
isNotAuthenticator(val) { return window.isNotAuthenticator(val); }, | isNotAuthenticator(val) { return window.isNotAuthenticator(val); }, | ||||
getLandingPage() { return getLandingPage(); }, | |||||
resetLandingPage() { return resetLandingPage(); }, | |||||
getLandingPage() { return util.getLandingPage(); }, | |||||
resetLandingPage() { return util.resetLandingPage(); }, | |||||
submitVerification(auth) { | submitVerification(auth) { | ||||
const uuid = auth.uuid; | const uuid = auth.uuid; | ||||
const type = auth.type; | const type = auth.type; | ||||