This commit is contained in:
Matthieu Bessat 2024-12-04 18:25:56 +01:00
parent 23f12904cc
commit 0ad436f6a3
11 changed files with 32 additions and 14 deletions

View file

@ -47,3 +47,6 @@
- [x] UserWebGUI: activate account with token
- [X] basic docker setup
- [ ] make `docker stop` working (handle SIGTERM/SIGINT)
- [ ] implement docker secrets. https://docs.docker.com/engine/swarm/secrets/

View file

@ -1,6 +1,6 @@
export RUST_BACKTRACE := "1"
export RUST_LOG := "trace"
export CONTEXT_ARGS := "--config ./config.toml --database ./tmp/dbs/minauthator.db --static-assets ./assets"
export CONTEXT_ARGS := "--config config.toml --database tmp/dbs/minauthator.db --static-assets ./assets"
watch-server:
cargo-watch -x "run --bin minauthator-server -- $CONTEXT_ARGS"

View file

@ -2,3 +2,4 @@ pub mod index;
pub mod oauth2;
pub mod read_user;
pub mod openid;
pub mod public_assets;

View file

@ -0,0 +1,11 @@
use axum::{extract::State, response::IntoResponse, Json};
use serde_json::json;
use crate::AppState;
pub async fn get_user_avatar(
State(app_state): State<AppState>,
) -> impl IntoResponse {
Json(json!({
}))
}

View file

@ -61,7 +61,7 @@ struct UserDetailsUpdateForm {
website: String,
#[form_data(limit = "5MiB")]
picture: FieldData<Bytes>
avatar: FieldData<Bytes>
}
@ -73,16 +73,19 @@ pub async fn me_perform_update_details(
) -> impl IntoResponse {
let template_path = "pages/me/details-form";
let update_res = sqlx::query("UPDATE users SET handle = $2, email = $3, full_name = $4, website = $5, picture = $6 WHERE id = $1")
let update_res = sqlx::query("UPDATE users SET handle = $2, email = $3, full_name = $4, website = $5 WHERE id = $1")
.bind(&token_claims.sub)
.bind(details_update.handle)
.bind(details_update.email)
.bind(details_update.full_name)
.bind(details_update.website)
.bind(details_update.picture.contents.to_vec())
.execute(&app_state.db.0)
.await;
dbg!(&details_update.avatar);
// let _res = sqlx::query("UPDATE users SET handle = $2, email = $3, full_name = $4, website = $5 WHERE id = $1")
// .bind(details_update.avatar.contents.to_vec())
let user_res = sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = $1")
.bind(&token_claims.sub)
.fetch_one(&app_state.db.0)

View file

@ -46,7 +46,7 @@ pub async fn perform_register(
email: Some(register.email),
handle: register.handle,
full_name: None,
picture: None,
avatar: None,
password_hash,
status: UserStatus::Active,

View file

@ -47,7 +47,8 @@ pub fn build_router(server_config: &ServerConfig, app_state: AppState) -> Router
let api_user_routes = Router::new()
.route("/api/user", get(api::read_user::read_user_basic))
.layer(middleware::from_fn_with_state(app_state.clone(), app_auth::enforce_jwt_auth_middleware))
.route("/api", get(api::index::get_index));
.route("/api", get(api::index::get_index))
.route("/api/user/{id}/avatar", get(api::public_assets::get_user_avatar));
let well_known_routes = Router::new()
.route("/.well-known/openid-configuration", get(api::openid::well_known::get_well_known_openid_configuration));

View file

@ -55,10 +55,9 @@
/>
</div>
<div class="mb-3">
<label for="picture">Profile picture</label>
<!-- for now, no JPEG -->
<label for="avatar">Profile picture</label>
<input
id="picture" name="picture"
id="avatar" name="avatar"
type="file"
accept="image/gif, image/png, image/jpeg"
class="form-control"

View file

@ -6,8 +6,8 @@
<a href="/me/authorizations">Manage authorizations.</a>
<p>
{% if user.picture %}
<img src="data:image/*;base64,{{ encode_b64str(user.picture) }}" style="width: 150px; height: 150px; object-fit: contain">
{% if user.avatar %}
<img src="data:image/*;base64,{{ encode_b64str(user.avatar) }}" style="width: 150px; height: 150px; object-fit: contain">
{% endif %}
<ul>
<li>

View file

@ -23,7 +23,7 @@ struct User {
full_name: Option<String>,
email: Option<String>,
website: Option<String>,
picture: Option<Vec<u8>>, // embeded blob to store profile pic
avatar: Option<Vec<u8>>, // embeded blob to store profile pic
password_hash: Option<String>, // argon2 password hash
status: UserStatus,
roles: Json<Vec<String>>,
@ -43,7 +43,7 @@ impl User {
full_name: None,
email: None,
website: None,
picture: None,
avatar: None,
password_hash: None,
status: UserStatus::Disabled,
roles: Json(Vec::new()),

View file

@ -5,7 +5,7 @@ CREATE TABLE users (
full_name TEXT,
email TEXT UNIQUE,
website TEXT,
picture BLOB,
avatar BLOB,
roles TEXT NOT NULL, -- json array of user roles
status TEXT CHECK(status IN ('Invited', 'Active', 'Disabled')) NOT NULL DEFAULT 'Disabled',