https://nico-oas.github.io/mps/
This Documentation describes the usage of our self implemented and self hosted WEB-API. The easiest und most secure way to use this API is to make use of the wrapper/abstraction layer that is provided in the 'backend.js' file. The following abstract describes the correct usage of this wrapper.
Function that handles the login of a user, using his username or email (-> login_ID) and his correspoding password.
login(login_id, password).then(ans => {
if (ans) {
/*
code after user is succesfully logged in
*/
}
else {
/*
wrong user data
*/
}
});
registration(username, mail, birthdate, region, password, real_name, gender).then(ans => {
if (ans) {
/*
code after user is succefully registered and logged in
*/
}
else {
/*
username or usermail already existed
*/
}
});
check_login().then(ans => {
if (ans) {
/*
code when logged in
*/
}
else {
/*
code when not logged in (could also be ignore if wanted)
*/
}
});
logout();
Function that should be used when a user is logged in and his specific user information (eg. Name, Birthdate...) are needed.
user_information().then(ans => {
if (ans) {
ans = JSON.parse(ans);
/*
The JSON-Object ans contains all user information:
username, mail, birthdate, gender, real_name, region, leaderboard_consent
*/
}
else {
/*
error (probably not logged in => should never happy with correct logic)
can be ignored (main purpose is debugging)
*/
}
});
change_pw(akt_pw, new_pw).then(ans => {
if (ans) {
/*
code when the given password was correct and the old password has been replaced with the new one.
*/
}
else {
/*
code when the current password (akt_pw) was not correct
*/
}
});
delete_all_items().then(ans => {
if (ans) {
/*
code after all items have been delete from the database
*/
}
else {
/*
error (probably not logged in => logic error)
can be ignored (main purpose is debugging)
*/
}
});
Function that is used to delete the whole user account (can only succeed when the user is logged in AND the password is correct).
delete_account(password).then(ans => {
if (ans) {
/*
code when user is logged in and the his correct password was given
*/
}
else {
/*
code when no one is logged in on this device, or the password was incorrect, or both
*/
}
});
add_item(category, name, carbon).then(ans => {
if (ans) {
/*
code after item was added
*/
}
else {
/*
error (probably not logged in => logic error)
can be ignored (main purpose is debugging)
*/
}
});
retrieve_items().then(ans => {
if (ans == false) {
/*
error (probably not logged in => logic error)
can be ignored (main purpose is debugging)
*/ }
else {
items = JSON.parse(items);
/*
'items' is a list of JSON-Objects containg the users items
Each Item is a JSON-Object which contains the following Keys:
- category
- name
- carbon (in kg)
*/
}
});
retrieve_ranking().then(ans => {
if (ans) {
rankings = JSON.parse(ans);
/*
'rankings' is a JSON-Object that contains the 5 best users in ascending order (username, toatl carbon)
*/
}
else {
/*
error (probably not logged in => logic error)
can be ignored (main purpose is debugging)
*/
}
});
Function that checks whether the currently logged in user has already accomplished his daily deed. SHOULD ONLY BE CALLED INSIDE OF A 'check_login()' BLOCK!
deed_check().then(ans => {
if (ans) {
/*
code when deed was accomplished
*/
}
else {
/*
code when deed was not yet accomplished
*/
}
});
deed_mark().then(ans => {
if (ans) {
/*
code after deed was marked as accomplished
*/
}
else {
/*
error (probably not logged in => logic error)
can be ignored (main purpose is debugging)
*/
}
});