Skip to content

Commit

Permalink
Fixed error in login, upgraded axum
Browse files Browse the repository at this point in the history
  • Loading branch information
sganis committed Jan 24, 2024
1 parent a7e6f73 commit 1f34154
Show file tree
Hide file tree
Showing 11 changed files with 948 additions and 703 deletions.
1,547 changes: 875 additions & 672 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ version = "0.1.0"
edition = "2021"

[dependencies]
axum = { version = "0.6.18", features = ["headers"] }
shuttle-axum = "0.27.0"
shuttle-runtime = "0.27.0"
shuttle-secrets = "0.27.0"
shuttle-shared-db = { version = "0.27.0", features = ["postgres"] }
axum = { version = "0.7.4" }
axum-extra = { version = "0.9", features = ["typed-header"] }
shuttle-axum = "0.36"
shuttle-runtime = "0.36"
shuttle-secrets = "0.36"
shuttle-shared-db = { version = "0.36.0", features = ["postgres"] }
sqlx = { version = "0.7.2", features = ["macros", "postgres", "chrono","json"] }
tokio = "1.28.2"
tower = "0.4.13"
tower-http = { version = "0.4.0", features = ["cors", "fs", "trace"] }
tower-http = { version = "0.5.1", features = ["cors", "fs", "trace"] }
chrono = { version = "0.4.24", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["raw_value","arbitrary_precision"] }
jsonwebtoken = "8.3"
jsonwebtoken = "9.2"
once_cell = "1.18"
dotenvy = "0.15.7"
argon2 = "0.5.2"
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pyme</title>
<script type="module" crossorigin src="/assets/index-e15f27fd.js"></script>
<script type="module" crossorigin src="/assets/index-4ff464d1.js"></script>
<link rel="stylesheet" href="/assets/index-983efeb8.css">
</head>
<body>
Expand Down
16 changes: 8 additions & 8 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion frontend/src/lib/ItemTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
</tr>
</thead>
<tbody>
{#if items}
{#each items as o, i}
<tr class="clickable" on:click={()=>showModify(o)}>
{#each table.columns as col, index}
Expand All @@ -98,7 +99,8 @@
{/each}
</tr>
{/each}
</tbody>
{/if}
</tbody>
</table>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
error = manager.error;
result = manager.result;
});
const refresh = async () => {
await manager.search();
error = manager.error;
result = manager.result;
}
const searchLater = async (e) => {
const searchText = e.detail;
manager.searchText = searchText
Expand Down
7 changes: 5 additions & 2 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use axum::http::{request::Parts, StatusCode};
use axum::{
async_trait,
extract::FromRequestParts,
headers::{authorization::Bearer, Authorization},
response::{IntoResponse, Response},
Json, RequestPartsExt, TypedHeader,
Json, RequestPartsExt,
};
use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use jsonwebtoken::{decode, DecodingKey, EncodingKey, Validation};
use once_cell::sync::Lazy;
Expand Down
31 changes: 31 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ use sqlx::{query_builder::QueryBuilder, Execute};
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};


pub async fn wakeup(
State(state): State<Arc<AppState>>,
) -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
let query = sqlx::query(
"SELECT username FROM public.user WHERE username = 'san'",
)
.fetch_one(&state.db)
.await;

if let Err(e) = query {
println!("error: {:?}", e);
let error = json!({
"detail": format!("error: {:?}", e)
});
return Err((StatusCode::SERVICE_UNAVAILABLE, Json(error)));
}
let result: String = query.unwrap().get(0);
if result != "san" {
let error = json!({
"detail": "invalid result"
});
return Err((StatusCode::SERVICE_UNAVAILABLE, Json(error)));
}
Ok(Json(json!({
"result": "ok"
})))
}



pub async fn token(
State(state): State<Arc<AppState>>,
Json(authdata): Json<AuthData>,
Expand Down
5 changes: 4 additions & 1 deletion src/route.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::{
handler::{
create_item, delete_item, get_customers, get_item, get_items, get_products,
get_stat_customer, get_stat_product, get_stat_quarter, get_stat_year, password, token,
get_stat_customer, get_stat_product, get_stat_quarter, get_stat_year,
password, token,
update_item,
wakeup,
},
test::{fibi, fibr, ping},
AppState,
Expand All @@ -19,6 +21,7 @@ pub fn create_router(state: Arc<AppState>) -> Router {
.not_found_service(ServeFile::new("frontend/dist/index.html"));
Router::new()
.route("/ping", get(ping))
.route("/wakeup", get(wakeup))
.route("/fibr/:n", get(fibr))
.route("/fibi/:n", get(fibi))
.route("/token", post(token))
Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
use serde_json::json;

pub async fn ping() -> Result<impl IntoResponse, (StatusCode, Json<serde_json::Value>)> {
Ok(Json(json!({"ping":"pong!"})))
Ok(Json(json!({"result":"pong"})))
}

fn fib_recursive(n: u32) -> u128 {
Expand Down

0 comments on commit 1f34154

Please sign in to comment.