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] 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_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"
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@ pub mod index;
|
|||
pub mod oauth2;
|
||||
pub mod read_user;
|
||||
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,
|
||||
|
||||
#[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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue