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
cabce21f
Commit
cabce21f
authored
3 years ago
by
HGEpro
Browse files
Options
Downloads
Patches
Plain Diff
switched to form instead of body and fixed server error
parent
60661fbe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/src-tauri/src/network.rs
+5
-4
5 additions, 4 deletions
app/src-tauri/src/network.rs
app/src/main.js
+1
-0
1 addition, 0 deletions
app/src/main.js
app/src/network.js
+11
-10
11 additions, 10 deletions
app/src/network.js
server/db.py
+2
-0
2 additions, 0 deletions
server/db.py
with
19 additions
and
14 deletions
app/src-tauri/src/network.rs
+
5
−
4
View file @
cabce21f
use
reqwest
;
use
serde
::{
Serialize
,
Deserialize
};
use
s
erde_json
;
use
s
td
::
collections
::
HashMap
;
const
APIURL
:
&
str
=
"https://librehomework-api.herokuapp.com/"
;
...
...
@@ -22,16 +22,17 @@ impl std::convert::From<reqwest::Error> for ApiResponse {
#[tauri::command]
pub
async
fn
request
(
url
:
&
str
,
method
:
Option
<&
str
>
,
body
:
Option
<
String
>
)
->
Result
<
(
ApiResponse
,
u16
),
String
>
{
pub
async
fn
request
(
url
:
&
str
,
method
:
Option
<&
str
>
,
form
:
Option
<
HashMap
<
String
,
String
>
>
)
->
Result
<
(
ApiResponse
,
u16
),
String
>
{
let
mut
_url
=
url
.to_string
();
let
client
=
reqwest
::
Client
::
new
();
if
&
url
.
len
()
>
&
8
&&
&
url
[
0
..
8
]
!=
"https://"
{
if
!
url
.
contains
(
"https://"
)
{
_url
=
APIURL
.to_owned
()
+
&
_url
;
}
println!
(
"{}"
,
&
_url
);
let
res
=
match
method
{
Some
(
m
)
=>
if
m
==
"POST"
{
client
.post
(
_url
)
.
json
(
&
body
)
.send
()
.await
client
.post
(
_url
)
.
form
(
&
form
)
.send
()
.await
}
else
{
client
.get
(
_url
)
.send
()
.await
},
...
...
This diff is collapsed.
Click to expand it.
app/src/main.js
+
1
−
0
View file @
cabce21f
...
...
@@ -53,5 +53,6 @@ String.prototype.capitalize = function() {
let
net
=
new
ServerAPI
()
console
.
log
(
net
)
net
.
getDailyMessage
().
then
((
d
)
=>
console
.
log
(
d
))
net
.
login
(
"
username
"
,
"
password
"
).
then
((
d
)
=>
console
.
log
(
d
))
export
default
svapp
;
This diff is collapsed.
Click to expand it.
app/src/network.js
+
11
−
10
View file @
cabce21f
...
...
@@ -2,9 +2,11 @@ import { invoke } from "@tauri-apps/api";
class
ApiResponse
{
constructor
(
payload
)
{
this
.
status
=
payload
[
1
];
this
.
data
=
data
[
0
];
this
.
data
=
payload
[
0
].
data
;
this
.
error
=
payload
[
0
].
error
;
}
}
...
...
@@ -25,39 +27,38 @@ class ServerAPI {
}
async
login
(
username
,
password
)
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
login
"
,
"
method
"
:
"
POST
"
,
"
body
"
:
JSON
.
stringify
(
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
login
"
,
"
method
"
:
"
POST
"
,
"
form
"
:
{
"
username
"
:
username
,
"
password
"
:
password
}
)
}));
}}));
}
async
signup
(
username
,
password
,
email
=
null
,
discord
=
null
,
twitter
=
null
,
bio
=
null
)
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
signup
"
,
"
method
"
:
"
POST
"
,
"
body
"
:
JSON
.
stringify
(
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
signup
"
,
"
method
"
:
"
POST
"
,
"
form
"
:
{
"
username
"
:
username
,
"
password
"
:
password
,
"
email
"
:
email
,
"
discord
"
:
discord
,
"
twitter
"
:
twitter
,
"
bio
"
:
bio
}
)
}));
}}));
}
async
deleteAccount
(
token
)
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
remove
"
,
"
method
"
:
"
POST
"
,
"
body
"
:
JSON
.
stringify
(
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
remove
"
,
"
method
"
:
"
POST
"
,
"
form
"
:
{
"
token
"
:
token
}
)
}));
}}));
}
//password or username cannot be changed, althought I might add a way to change it in the future
//server should handle the optional fields but check if at least one param is not null
async
editProfile
(
token
,
email
=
null
,
discord
=
null
,
twitter
=
null
,
bio
=
null
)
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
remove
"
,
"
method
"
:
"
POST
"
,
"
body
"
:
JSON
.
stringify
(
{
return
new
ApiResponse
(
await
invoke
(
"
request
"
,
{
"
url
"
:
"
remove
"
,
"
method
"
:
"
POST
"
,
"
form
"
:
{
"
token
"
:
token
}
)
}));
}}));
}
}
export
default
ServerAPI
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server/db.py
+
2
−
0
View file @
cabce21f
...
...
@@ -66,6 +66,8 @@ async def login(db, username, password):
SELECT username FROM users where password = $1 and username = $2
"""
,
utils
.
hash
(
password
.
encode
(
"
utf8
"
)),
username
)
if
not
db_username
:
return
False
,
None
if
db_username
[
"
username
"
]
==
username
:
return
True
,
authtoken
.
generate_token
(
username
,
15
)
#15 minutes
else
:
...
...
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