initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
function loginWithAppId(username, password, callback) {
|
||||
let jsonBody = {
|
||||
id_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcElkLTY4ZDI1ZDQ2LThmZGItNDhlMy1iODNkLTJhYzY2YzI5MTA2NC0yMDIwLTAxLTMxVDAwOjI5OjI4Ljg1NiIsInZlciI6NH0.eyJpc3MiOiJodHRwczovL3VzLXNvdXRoLmFwcGlkLmNsb3VkLmlibS5jb20vb2F1dGgvdjQvMTIzIiwiYXVkIjpbIjEyMyJdLCJleHAiOjAsInRlbmFudCI6IjY4ZDI1ZDQ2LThmZGItNDhlMy1iODNkLTJhYzY2YzI5MTA2NCIsImlhdCI6MCwiZW1haWwiOiJKb2huQFNtaXRoLm9yZyIsIm5hbWUiOiJKb2huIFNtaXRoIiwic3ViIjoiMTIzIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiTGl0YUNhdnJhayIsImdpdmVuX25hbWUiOiJKb2huIiwiZmFtaWx5X25hbWUiOiJTbWl0aCIsImlkZW50aXRpZXMiOlt7InByb3ZpZGVyIjoiY2xvdWRfZGlyZWN0b3J5IiwiaWQiOiIxMjMifV0sImFtciI6WyJjbG91ZF9kaXJlY3RvcnkiXX0.ABC",
|
||||
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImFwcElkLTY4ZDI1ZDQ2LThmZGItNDhlMy1iODNkLTJhYzY2YzI5MTA2NC0yMDIwLTAxLTMxVDAwOjI5OjI4Ljg1NiIsInZlciI6NH0.eyJpc3MiOiJodHRwczovL3VzLXNvdXRoLmFwcGlkLmNsb3VkLmlibS5jb20vb2F1dGgvdjQvMTIzIiwiZXhwIjowLCJhdWQiOlsiMTIzIl0sInN1YiI6IjEyMyIsImFtciI6WyJjbG91ZF9kaXJlY3RvcnkiXSwiaWF0IjowLCJ0ZW5hbnQiOiIxMjMiLCJzY29wZSI6Im9wZW5pZCBhcHBpZF9kZWZhdWx0IGFwcGlkX3JlYWR1c2VyYXR0ciBhcHBpZF9yZWFkcHJvZmlsZSBhcHBpZF93cml0ZXVzZXJhdHRyIGFwcGlkX2F1dGhlbnRpY2F0ZWQifQ.ABC"
|
||||
}
|
||||
|
||||
document.cookie = 'access_token=' + jsonBody.access_token + ';'
|
||||
document.cookie = 'id_token=' + jsonBody.id_token+ ';'
|
||||
callback(jsonBody)
|
||||
}
|
||||
|
||||
function getRandomUser(callback) {
|
||||
let text = "John Smith"
|
||||
let name = text.split(' ')
|
||||
let firstname = name[0]
|
||||
let surname = name[1]
|
||||
let password = name[0] + name[1]
|
||||
let email = name[0] + "@" + name[1] + ".org"
|
||||
callback(firstname, surname, password, email)
|
||||
}
|
||||
|
||||
function createAccountAppId(firstname, lastname, password, email, callback) {
|
||||
let json = {}
|
||||
json.status = "user created successfully"
|
||||
callback(json)
|
||||
}
|
||||
|
||||
function getAllUsers(callback) {
|
||||
callback(['JohnSmith'])
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
function loginWithAppId(username, password, callback) {
|
||||
let jsonBody = {username, password}
|
||||
|
||||
fetch("/demo/login", {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(jsonBody)
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
return response.json();
|
||||
}).then((json) => {
|
||||
console.log(json)
|
||||
callback(json)
|
||||
}).catch((error) => {
|
||||
callback(null)
|
||||
})
|
||||
}
|
||||
|
||||
function getRandomUser(callback) {
|
||||
fetch("/demo/random_user")
|
||||
.then((response) => {
|
||||
return response.text()
|
||||
})
|
||||
.then((text) => {
|
||||
let name = text.split(' ')
|
||||
let firstname = name[0]
|
||||
let surname = name[1]
|
||||
let password = name[0] + name[1]
|
||||
let email = name[0] + "@" + name[1] + ".org"
|
||||
callback(firstname, surname, password, email)
|
||||
})
|
||||
}
|
||||
|
||||
function createAccountAppId(firstname, lastname, password, email, callback) {
|
||||
let jsonRequestBody = {}
|
||||
jsonRequestBody.firstName = firstname
|
||||
jsonRequestBody.lastName = lastname
|
||||
jsonRequestBody.password = password
|
||||
jsonRequestBody.email = email
|
||||
|
||||
fetch('/demo/create_account', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(jsonRequestBody)
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
return response.json()
|
||||
}).then((json) => {
|
||||
callback(json)
|
||||
})
|
||||
}
|
||||
|
||||
function getAllUsers(callback) {
|
||||
fetch('/demo/get_all_users')
|
||||
.then((response) => {
|
||||
return response.json()
|
||||
}).then((users) => {
|
||||
callback(users)
|
||||
})
|
||||
}
|
||||
|
||||
// sample appid account
|
||||
// loginWithAppId("RolandeColla", "RolandeColla")
|
||||
@@ -0,0 +1,137 @@
|
||||
let SECURE_USER_BACKEND_URL='/proxy_user'
|
||||
let SECURE_EVENT_BACKEND_URL='/proxy_transaction'
|
||||
// DEVMODE
|
||||
let mode = 'INTEGRATED'
|
||||
function createProfile(access_token, callback) {
|
||||
callback(true)
|
||||
}
|
||||
|
||||
function deleteUserProfile(access_token, callback) {
|
||||
callback(true)
|
||||
}
|
||||
|
||||
function getTransactions(access_token, callback) {
|
||||
let testdata = [{
|
||||
"amount": 20,
|
||||
"category": "Cafe",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned": 20,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Starbucks",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
{
|
||||
"amount": 15,
|
||||
"category": "Carshare",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned":15,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Uber",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
{
|
||||
"amount": 70,
|
||||
"category": "Gas",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned": 100,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Esso",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
{
|
||||
"amount": 20,
|
||||
"category": "Meals",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned":20,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Sweetgreen",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},,
|
||||
{
|
||||
"amount": 127,
|
||||
"category": "Groceries",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned": 200,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Whole Foods",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
{
|
||||
"amount": 34,
|
||||
"category": "Meals",
|
||||
"date": "2020-04-17T22:09:39.183Z",
|
||||
"pointsEarned":34,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Shake Shack",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
,
|
||||
{
|
||||
"amount": 20,
|
||||
"category": "Meals",
|
||||
"date": "2020-04-18T22:09:39.183Z",
|
||||
"pointsEarned":20,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Sweetgreen",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},,
|
||||
{
|
||||
"amount": 127,
|
||||
"category": "Groceries",
|
||||
"date": "2020-04-27T22:09:39.183Z",
|
||||
"pointsEarned": 200,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Whole Foods",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
},
|
||||
{
|
||||
"amount": 5.75,
|
||||
"category": "Cafe",
|
||||
"date": "2020-04-28T22:09:39.183Z",
|
||||
"pointsEarned":34,
|
||||
"processed": true,
|
||||
"transactionId": "c2eb0fb9-2af0-43a3-820d-fa210203f698",
|
||||
"transactionName": "Starbucks",
|
||||
"userId": "60e67c81-1a27-4423-a890-db653941822a"
|
||||
}
|
||||
]
|
||||
callback(null, testdata)
|
||||
}
|
||||
|
||||
function getSpending(access_token, callback) {
|
||||
var data = [
|
||||
{
|
||||
"category": "Cafe",
|
||||
"amount": 45
|
||||
},
|
||||
{
|
||||
"category": "Groceries",
|
||||
"amount": 239
|
||||
},
|
||||
{
|
||||
"category": "Fuel",
|
||||
"amount": 75
|
||||
},
|
||||
{
|
||||
"category": "Ride Share",
|
||||
"amount": 35
|
||||
},
|
||||
{
|
||||
"category": "Restaurant",
|
||||
"amount": 90
|
||||
}
|
||||
];
|
||||
callback(null, data)
|
||||
}
|
||||
|
||||
function createTransaction(access_token, transactionName, category, amount, callback) {
|
||||
callback(true)
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
let SECURE_USER_BACKEND_URL='/proxy_user'
|
||||
let SECURE_EVENT_BACKEND_URL='/proxy_transaction'
|
||||
|
||||
function createProfile(access_token, callback) {
|
||||
let jsonRequestBody = {}
|
||||
jsonRequestBody.consentGiven = true
|
||||
|
||||
fetch(SECURE_USER_BACKEND_URL + '/bank/v1/users', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token,
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(jsonRequestBody)
|
||||
}).then((response) => {
|
||||
if (response.status == '204') {
|
||||
callback(true)
|
||||
} else {
|
||||
callback(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getUserStats(access_token, callback) {
|
||||
fetch(SECURE_USER_BACKEND_URL + '/bank/v1/userEvents/self/info', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((json) => {
|
||||
callback(null, json.eventCount, json.pointsEarned)
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(e, null, null)
|
||||
})
|
||||
}
|
||||
|
||||
function getUserEvents(access_token, callback) {
|
||||
fetch(SECURE_USER_BACKEND_URL + '/bank/v1/userEvents/self', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((events) => {
|
||||
callback(null, events)
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(e, null)
|
||||
})
|
||||
}
|
||||
|
||||
function getUserEventsWithData(access_token, callback) {
|
||||
getUserEvents(access_token, (err, events) => {
|
||||
let queryParams = ''
|
||||
|
||||
if (events.length == 0) {
|
||||
callback(null, events)
|
||||
} else {
|
||||
events.forEach(element => {
|
||||
queryParams += 'id=' + element + '&'
|
||||
});
|
||||
|
||||
fetch(SECURE_EVENT_BACKEND_URL + '/bank/v1/events?' + queryParams, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
console.log(response)
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((events) => {
|
||||
callback(null, events)
|
||||
}).catch(e => {
|
||||
callback(e, null)
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getEvents(access_token, callback) {
|
||||
fetch(SECURE_EVENT_BACKEND_URL + '/bank/v1/events', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((events) => {
|
||||
callback(null, events)
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(e, null)
|
||||
})
|
||||
}
|
||||
|
||||
function checkInEvent(access_token, eventId, callback) {
|
||||
let jsonRequestBody = {}
|
||||
jsonRequestBody.eventId = eventId
|
||||
|
||||
fetch(SECURE_USER_BACKEND_URL + '/bank/v1/userEvents', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token,
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(jsonRequestBody)
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
if (response.status == '204') {
|
||||
callback(true)
|
||||
} else {
|
||||
callback(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function deleteUserProfile(access_token, callback) {
|
||||
fetch(SECURE_USER_BACKEND_URL + '/bank/v1/users/self', {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
if (response.status == '204') {
|
||||
callback(true)
|
||||
} else {
|
||||
callback(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getTransactions(access_token, callback) {
|
||||
fetch(SECURE_EVENT_BACKEND_URL + '/bank/v1/transactions', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((transactions) => {
|
||||
callback(null, transactions)
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(e, null)
|
||||
})
|
||||
}
|
||||
|
||||
function getSpending(access_token, callback) {
|
||||
fetch(SECURE_EVENT_BACKEND_URL + '/bank/v1/transactions/spending', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token
|
||||
}
|
||||
}).then(async (response) => {
|
||||
if (response.status == '200') {
|
||||
return response.json()
|
||||
} else {
|
||||
let responsetext = await response.text()
|
||||
console.log(responsetext)
|
||||
throw responsetext
|
||||
}
|
||||
}).then((transactions) => {
|
||||
callback(null, transactions)
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(e, null)
|
||||
})
|
||||
}
|
||||
|
||||
function createTransaction(access_token, transactionName, category, amount, callback) {
|
||||
let jsonRequestBody = { transactionName, category, amount }
|
||||
|
||||
fetch(SECURE_EVENT_BACKEND_URL + '/bank/v1/transactions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + access_token,
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(jsonRequestBody)
|
||||
}).then(response => {
|
||||
console.log(response)
|
||||
if (response.status == '204') {
|
||||
callback(true)
|
||||
} else {
|
||||
callback(false)
|
||||
}
|
||||
}).catch(e => {
|
||||
console.log(e)
|
||||
callback(false)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
function attendEvent(userSubject, event) {
|
||||
let localStorageId = userSubject + '-events'
|
||||
let userEvents = localStorage.getItem(localStorageId)
|
||||
|
||||
if (userEvents == null || userEvents == "") {
|
||||
let events = []
|
||||
events.push(event)
|
||||
localStorage.setItem(userSubject + '-events', JSON.stringify(events))
|
||||
} else {
|
||||
let arrayOfEvents = JSON.parse(userEvents)
|
||||
if (arrayOfEvents.filter(e => e.eventId === event.eventId).length > 0) {
|
||||
console.log('event exists in local storage')
|
||||
} else {
|
||||
arrayOfEvents.push(event)
|
||||
}
|
||||
localStorage.setItem(localStorageId, JSON.stringify(arrayOfEvents))
|
||||
}
|
||||
}
|
||||
|
||||
function getStoredEvents(userSubject) {
|
||||
let storedEventsString = localStorage.getItem(userSubject + '-events')
|
||||
if (storedEventsString == null || storedEventsString == "") return null
|
||||
return JSON.parse(storedEventsString)
|
||||
}
|
||||
|
||||
function removeStoredEvent(userSubject, eventId) {
|
||||
let localStorageId = userSubject + '-events'
|
||||
let storedEvents = getStoredEvents(userSubject)
|
||||
storedEvents = storedEvents.filter(e => e.eventId != eventId)
|
||||
localStorage.setItem(localStorageId, JSON.stringify(storedEvents))
|
||||
}
|
||||
Reference in New Issue
Block a user