WIP
This commit is contained in:
parent
23f12904cc
commit
0ad436f6a3
11 changed files with 32 additions and 14 deletions
3
TODO.md
3
TODO.md
|
|
@ -47,3 +47,6 @@
|
||||||
|
|
||||||
- [x] UserWebGUI: activate account with token
|
- [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/
|
||||||
|
|
|
||||||
2
justfile
2
justfile
|
|
@ -1,6 +1,6 @@
|
||||||
export RUST_BACKTRACE := "1"
|
export RUST_BACKTRACE := "1"
|
||||||
export RUST_LOG := "trace"
|
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:
|
watch-server:
|
||||||
cargo-watch -x "run --bin minauthator-server -- $CONTEXT_ARGS"
|
cargo-watch -x "run --bin minauthator-server -- $CONTEXT_ARGS"
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ pub mod index;
|
||||||
pub mod oauth2;
|
pub mod oauth2;
|
||||||
pub mod read_user;
|
pub mod read_user;
|
||||||
pub mod openid;
|
pub mod openid;
|
||||||
|
pub mod public_assets;
|
||||||
|
|
|
||||||
11
lib/http_server/src/controllers/api/public_assets.rs
Normal file
11
lib/http_server/src/controllers/api/public_assets.rs
Normal 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!({
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
@ -61,7 +61,7 @@ struct UserDetailsUpdateForm {
|
||||||
website: String,
|
website: String,
|
||||||
|
|
||||||
#[form_data(limit = "5MiB")]
|
#[form_data(limit = "5MiB")]
|
||||||
picture: FieldData<Bytes>
|
avatar: FieldData<Bytes>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -73,16 +73,19 @@ pub async fn me_perform_update_details(
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let template_path = "pages/me/details-form";
|
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(&token_claims.sub)
|
||||||
.bind(details_update.handle)
|
.bind(details_update.handle)
|
||||||
.bind(details_update.email)
|
.bind(details_update.email)
|
||||||
.bind(details_update.full_name)
|
.bind(details_update.full_name)
|
||||||
.bind(details_update.website)
|
.bind(details_update.website)
|
||||||
.bind(details_update.picture.contents.to_vec())
|
|
||||||
.execute(&app_state.db.0)
|
.execute(&app_state.db.0)
|
||||||
.await;
|
.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")
|
let user_res = sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = $1")
|
||||||
.bind(&token_claims.sub)
|
.bind(&token_claims.sub)
|
||||||
.fetch_one(&app_state.db.0)
|
.fetch_one(&app_state.db.0)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ pub async fn perform_register(
|
||||||
email: Some(register.email),
|
email: Some(register.email),
|
||||||
handle: register.handle,
|
handle: register.handle,
|
||||||
full_name: None,
|
full_name: None,
|
||||||
picture: None,
|
avatar: None,
|
||||||
|
|
||||||
password_hash,
|
password_hash,
|
||||||
status: UserStatus::Active,
|
status: UserStatus::Active,
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@ pub fn build_router(server_config: &ServerConfig, app_state: AppState) -> Router
|
||||||
let api_user_routes = Router::new()
|
let api_user_routes = Router::new()
|
||||||
.route("/api/user", get(api::read_user::read_user_basic))
|
.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))
|
.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()
|
let well_known_routes = Router::new()
|
||||||
.route("/.well-known/openid-configuration", get(api::openid::well_known::get_well_known_openid_configuration));
|
.route("/.well-known/openid-configuration", get(api::openid::well_known::get_well_known_openid_configuration));
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,9 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="picture">Profile picture</label>
|
<label for="avatar">Profile picture</label>
|
||||||
<!-- for now, no JPEG -->
|
|
||||||
<input
|
<input
|
||||||
id="picture" name="picture"
|
id="avatar" name="avatar"
|
||||||
type="file"
|
type="file"
|
||||||
accept="image/gif, image/png, image/jpeg"
|
accept="image/gif, image/png, image/jpeg"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
<a href="/me/authorizations">Manage authorizations.</a>
|
<a href="/me/authorizations">Manage authorizations.</a>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% if user.picture %}
|
{% if user.avatar %}
|
||||||
<img src="data:image/*;base64,{{ encode_b64str(user.picture) }}" style="width: 150px; height: 150px; object-fit: contain">
|
<img src="data:image/*;base64,{{ encode_b64str(user.avatar) }}" style="width: 150px; height: 150px; object-fit: contain">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ struct User {
|
||||||
full_name: Option<String>,
|
full_name: Option<String>,
|
||||||
email: Option<String>,
|
email: Option<String>,
|
||||||
website: 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
|
password_hash: Option<String>, // argon2 password hash
|
||||||
status: UserStatus,
|
status: UserStatus,
|
||||||
roles: Json<Vec<String>>,
|
roles: Json<Vec<String>>,
|
||||||
|
|
@ -43,7 +43,7 @@ impl User {
|
||||||
full_name: None,
|
full_name: None,
|
||||||
email: None,
|
email: None,
|
||||||
website: None,
|
website: None,
|
||||||
picture: None,
|
avatar: None,
|
||||||
password_hash: None,
|
password_hash: None,
|
||||||
status: UserStatus::Disabled,
|
status: UserStatus::Disabled,
|
||||||
roles: Json(Vec::new()),
|
roles: Json(Vec::new()),
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ CREATE TABLE users (
|
||||||
full_name TEXT,
|
full_name TEXT,
|
||||||
email TEXT UNIQUE,
|
email TEXT UNIQUE,
|
||||||
website TEXT,
|
website TEXT,
|
||||||
picture BLOB,
|
avatar BLOB,
|
||||||
roles TEXT NOT NULL, -- json array of user roles
|
roles TEXT NOT NULL, -- json array of user roles
|
||||||
|
|
||||||
status TEXT CHECK(status IN ('Invited', 'Active', 'Disabled')) NOT NULL DEFAULT 'Disabled',
|
status TEXT CHECK(status IN ('Invited', 'Active', 'Disabled')) NOT NULL DEFAULT 'Disabled',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue