Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibreHomework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
HGEpro
LibreHomework
Commits
2e5213e7
Commit
2e5213e7
authored
3 years ago
by
HGEpro
Browse files
Options
Downloads
Patches
Plain Diff
added basic server abstraction for app
parent
8aa2b1d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/network.js
+119
-0
119 additions, 0 deletions
app/src/network.js
with
119 additions
and
0 deletions
app/src/network.js
0 → 100644
+
119
−
0
View file @
2e5213e7
class
Network
{
constructor
()
{
this
.
url
=
"
https://librehomework-api.herokuapp.com/
"
;
let
res
=
fetch
(
this
.
url
+
"
dailymessage
"
).
then
((
r
)
=>
{
if
(
r
.
status
==
200
)
{
return
[
true
,
r
.
json
()];
}
else
{
return
[
false
,
r
.
status
];
}
});
//should a different function for /dailymessage exist?
}
async
getUsers
(
page
=
0
)
{
let
res
=
await
fetch
(
this
.
url
+
"
users/
"
+
page
);
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
async
findUser
(
username
)
{
let
res
=
await
fetch
(
this
.
url
+
"
find/
"
+
username
);
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
async
login
(
username
,
password
)
{
let
res
=
await
fetch
(
this
.
url
+
"
login
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
username
:
username
,
password
:
password
})
});
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
async
register
(
username
,
password
,
email
,
discord
,
twitter
,
bio
)
{
let
res
=
await
fetch
(
this
.
url
+
"
register
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
username
:
username
,
password
:
password
,
email
:
email
,
discord
:
discord
,
twitter
:
twitter
,
bio
:
bio
})
});
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
async
deleteAccount
(
token
)
{
let
res
=
await
fetch
(
this
.
url
+
"
remove
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
token
:
token
})
});
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
//password or username cannot be changed, althought I might add a way to change it in the future
async
editProfile
(
token
,
email
,
discord
,
twitter
,
bio
)
{
let
res
=
await
fetch
(
this
.
url
+
"
edit
"
,
{
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
token
:
token
,
email
:
email
,
discord
:
discord
,
twitter
:
twitter
,
bio
:
bio
})
});
if
(
res
.
status
==
200
)
{
return
[
true
,
res
.
json
()];
}
else
{
return
[
false
,
res
.
status
];
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment