diff options
author | yigit sever | 2021-04-16 13:40:17 +0000 |
---|---|---|
committer | yigit sever | 2021-04-16 13:40:17 +0000 |
commit | c6b90ff7abe2122fbac8f9e1066bd8cecbf135cd (patch) | |
tree | 9835fb758c15d1ed36b95b950e23bf883da87738 | |
parent | 9a9bc6522810d49a46f6762cca68daf81ba60390 (diff) | |
parent | e7cd705175abb820cd4bfdb28693615ef2171597 (diff) | |
download | gradecoin-c6b90ff7abe2122fbac8f9e1066bd8cecbf135cd.tar.gz gradecoin-c6b90ff7abe2122fbac8f9e1066bd8cecbf135cd.tar.bz2 gradecoin-c6b90ff7abe2122fbac8f9e1066bd8cecbf135cd.zip |
Merge pull request 'Add existing user get support' (#1) from usershow into main
Reviewed-on: https://git.yigitsever.com/yigit/gradecoin/pulls/1
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | src/handlers.rs | 29 | ||||
-rw-r--r-- | src/routes.rs | 9 | ||||
-rw-r--r-- | templates/css.html | 27 | ||||
-rw-r--r-- | templates/header.html | 5 | ||||
-rw-r--r-- | templates/list.html | 15 |
6 files changed, 68 insertions, 19 deletions
@@ -442,7 +442,7 @@ dependencies = [ | |||
442 | 442 | ||
443 | [[package]] | 443 | [[package]] |
444 | name = "gradecoin" | 444 | name = "gradecoin" |
445 | version = "0.1.0" | 445 | version = "0.2.0" |
446 | dependencies = [ | 446 | dependencies = [ |
447 | "aes", | 447 | "aes", |
448 | "askama", | 448 | "askama", |
diff --git a/src/handlers.rs b/src/handlers.rs index ee0fbf0..c2c8aca 100644 --- a/src/handlers.rs +++ b/src/handlers.rs | |||
@@ -712,17 +712,28 @@ fn authorize_proposer(jwt_token: String, user_pem: &str) -> Result<TokenData<Cla | |||
712 | } | 712 | } |
713 | 713 | ||
714 | #[derive(Template)] | 714 | #[derive(Template)] |
715 | #[template(path = "welcome.html")] | 715 | #[template(path = "list.html")] |
716 | struct WelcomeTemplate<'a> { | 716 | struct UserTemplate<'a> { |
717 | title: &'a str, | 717 | users: &'a Vec<DisplayUsers>, |
718 | body: &'a str, | ||
719 | } | 718 | } |
720 | 719 | ||
721 | pub async fn welcome_handler() -> Result<impl warp::Reply, warp::Rejection> { | 720 | struct DisplayUsers { |
722 | let template = WelcomeTemplate { | 721 | fingerprint: String, |
723 | title: "Welcome", | 722 | balance: i32, |
724 | body: "To The Bookstore!", | 723 | } |
725 | }; | 724 | |
725 | pub async fn user_list_handler(db: Db) -> Result<impl warp::Reply, warp::Rejection> { | ||
726 | let users = db.users.read(); | ||
727 | let mut sane_users = Vec::new(); | ||
728 | |||
729 | for (fingerprint, user) in users.iter() { | ||
730 | sane_users.push(DisplayUsers { | ||
731 | fingerprint: fingerprint.to_owned(), | ||
732 | balance: user.balance, | ||
733 | }); | ||
734 | } | ||
735 | |||
736 | let template = UserTemplate { users: &sane_users }; | ||
726 | let res = template.render().unwrap(); | 737 | let res = template.render().unwrap(); |
727 | Ok(warp::reply::html(res)) | 738 | Ok(warp::reply::html(res)) |
728 | } | 739 | } |
diff --git a/src/routes.rs b/src/routes.rs index 52d357a..211f832 100644 --- a/src/routes.rs +++ b/src/routes.rs | |||
@@ -18,10 +18,19 @@ pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rej | |||
18 | .or(register_user(db.clone())) | 18 | .or(register_user(db.clone())) |
19 | .or(auth_transaction_propose(db.clone())) | 19 | .or(auth_transaction_propose(db.clone())) |
20 | .or(auth_block_propose(db.clone())) | 20 | .or(auth_block_propose(db.clone())) |
21 | .or(list_users(db.clone())) | ||
21 | .or(block_list(db)) | 22 | .or(block_list(db)) |
22 | .or(static_route) | 23 | .or(static_route) |
23 | } | 24 | } |
24 | 25 | ||
26 | /// GET /user warp route | ||
27 | pub fn list_users(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
28 | warp::path!("user") | ||
29 | .and(warp::get()) | ||
30 | .and(custom_filters::with_db(db)) | ||
31 | .and_then(handlers::user_list_handler) | ||
32 | } | ||
33 | |||
25 | /// POST /register warp route | 34 | /// POST /register warp route |
26 | pub fn register_user(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 35 | pub fn register_user(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
27 | warp::path!("register") | 36 | warp::path!("register") |
diff --git a/templates/css.html b/templates/css.html index c9d54e3..a918a4b 100644 --- a/templates/css.html +++ b/templates/css.html | |||
@@ -1,8 +1,23 @@ | |||
1 | <style> | 1 | <style> |
2 | td, th { | 2 | table, th, td { |
3 | padding: 8px; | 3 | border: 1px solid black; |
4 | } | 4 | border-collapse: collapse; |
5 | th { | 5 | } |
6 | text-align: left; | 6 | th, td { |
7 | } | 7 | padding: 15px; |
8 | } | ||
9 | #t01 { | ||
10 | width: 100%; | ||
11 | background-color: #fbf1c7; | ||
12 | } | ||
13 | #t01 tr:nth-child(even) { | ||
14 | background-color: #a89984; | ||
15 | } | ||
16 | #t01 tr:nth-child(odd) { | ||
17 | background-color: #f9f5d7; | ||
18 | } | ||
19 | #t01 th { | ||
20 | color: #fbf1c7; | ||
21 | background-color: #282828; | ||
22 | } | ||
8 | </style> | 23 | </style> |
diff --git a/templates/header.html b/templates/header.html index fffbefe..a142fad 100644 --- a/templates/header.html +++ b/templates/header.html | |||
@@ -1,11 +1,10 @@ | |||
1 | <html> | 1 | <html> |
2 | <head> | 2 | <head> |
3 | <title>Bookstore</title> | 3 | <title>Gradecoin</title> |
4 | {% include "css.html" %} | 4 | {% include "css.html" %} |
5 | </head> | 5 | </head> |
6 | <body> | 6 | <body> |
7 | <div> | 7 | <div> |
8 | <h1>Bookstore</h1> | 8 | <h1>Registered Users</h1> |
9 | </div> | 9 | </div> |
10 | {% include "menu.html" %} | ||
11 | <hr /> | 10 | <hr /> |
diff --git a/templates/list.html b/templates/list.html new file mode 100644 index 0000000..e63c6be --- /dev/null +++ b/templates/list.html | |||
@@ -0,0 +1,15 @@ | |||
1 | {% include "header.html" %} | ||
2 | |||
3 | <table id="t01"> | ||
4 | <tr> | ||
5 | <th>Fingerprint</td> | ||
6 | <th>Balance</td> | ||
7 | </tr> | ||
8 | {% for user in users %} | ||
9 | <tr> | ||
10 | <td>{{ user.fingerprint }}</td> | ||
11 | <td>{{ user.balance }}</td> | ||
12 | <?tr> | ||
13 | {% endfor %} | ||
14 | </table> | ||
15 | {% include "footer.html" %} | ||