Compare commits
5 Commits
f588f3cf27
...
7514e98f1b
| Author | SHA1 | Date | |
|---|---|---|---|
| 7514e98f1b | |||
|
3f10b51da9
|
|||
|
947db47fdf
|
|||
|
f49fb9df6f
|
|||
|
252f7b164b
|
@@ -28,3 +28,4 @@ README.md
|
||||
readme
|
||||
**/*.db*
|
||||
**/*.db3*
|
||||
/mnemodata
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
/target
|
||||
.DS_Store
|
||||
/database
|
||||
/mnemodata
|
||||
*.db
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
|
||||
@@ -53,7 +53,7 @@ RUN adduser \
|
||||
--uid "${UID}" \
|
||||
appuser
|
||||
|
||||
RUN mkdir -p /app && chown appuser:appuser /app
|
||||
RUN mkdir -p /app/data && chown -R appuser:appuser /app
|
||||
USER appuser
|
||||
WORKDIR /app
|
||||
ENV IN_DOCKER=true
|
||||
|
||||
26
compose.yaml
Normal file
26
compose.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
services:
|
||||
mnemosyne:
|
||||
container_name: mnemosyne
|
||||
build:
|
||||
context: .
|
||||
target: final
|
||||
ports:
|
||||
- 39321:39321
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
# Mnemosyne would greatly enjoy not having an ephemeral database.
|
||||
# If you're okay with storing it side by side with the compose file,
|
||||
# a bind mount like this is one way to do it. Remember to mkdir!
|
||||
- ./mnemodata:/app/data
|
||||
# Another way is to use a docker volume.
|
||||
# - mnemodata:/app/data
|
||||
environment:
|
||||
# DATABASE_URL is crucial for Mnemosyne to work; it will fail without it.
|
||||
# Point it at where you'd like your database to be.
|
||||
- DATABASE_URL=/app/data/db.db
|
||||
# Mnemosyne uses port 39321 for HTTP by default;
|
||||
# - PORT=39321
|
||||
|
||||
# Declaring a volume for the docker volume example.
|
||||
# volumes:
|
||||
# mnemodata:
|
||||
@@ -1,18 +1,8 @@
|
||||
use axum::{
|
||||
Router,
|
||||
response::{IntoResponse, Response},
|
||||
routing::{delete, get, patch, post},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
database::DatabaseError,
|
||||
persons::PersonError,
|
||||
quotes::QuoteError,
|
||||
tags::TagError,
|
||||
users::{UserError, auth::AuthError, sessions::SessionError},
|
||||
web::RedirectViaError,
|
||||
};
|
||||
|
||||
mod auth;
|
||||
mod persons;
|
||||
mod quotes;
|
||||
@@ -58,32 +48,3 @@ pub fn api_router() -> Router {
|
||||
.route("/api/quotes", post(quotes::create))
|
||||
.route("/api/quotes/{id}", get(quotes::get_by_id))
|
||||
}
|
||||
|
||||
pub struct CompositeError(Response);
|
||||
impl IntoResponse for CompositeError {
|
||||
fn into_response(self) -> Response {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! composite_from {
|
||||
($($t:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl From<$t> for CompositeError {
|
||||
fn from(e: $t) -> Self {
|
||||
CompositeError(e.into_response())
|
||||
}
|
||||
}
|
||||
)+
|
||||
};
|
||||
}
|
||||
composite_from!(
|
||||
AuthError,
|
||||
UserError,
|
||||
SessionError,
|
||||
TagError,
|
||||
PersonError,
|
||||
QuoteError,
|
||||
DatabaseError,
|
||||
RedirectViaError,
|
||||
);
|
||||
|
||||
@@ -8,8 +8,8 @@ use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
persons::{Name, Person},
|
||||
users::{
|
||||
@@ -54,7 +54,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let p = Person::create(&tx, form.name, u.id)?;
|
||||
LogEntry::new(
|
||||
@@ -65,7 +65,7 @@ pub async fn create(
|
||||
pname: p.primary_name.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok((StatusCode::CREATED, Json(p)).into_response())
|
||||
}
|
||||
pub async fn add_name(
|
||||
@@ -75,7 +75,7 @@ pub async fn add_name(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let p = Person::get_by_id(&tx, id)?;
|
||||
let n = p.add_name(&tx, form.name, u.id)?;
|
||||
@@ -89,7 +89,7 @@ pub async fn add_name(
|
||||
nn: n.name.clone(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok((StatusCode::CREATED, Json(n)).into_response())
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ pub async fn n_setprimary(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::ChangePersonPrimaryName)? {
|
||||
return Ok((StatusCode::FORBIDDEN, CANT_SET_PRIMARYNAME).into_response());
|
||||
@@ -124,7 +124,7 @@ pub async fn n_setprimary(
|
||||
nn: n.name.clone(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok(Json(n).into_response())
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
persons::Name,
|
||||
quotes::Quote,
|
||||
@@ -50,7 +50,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let lines = form
|
||||
.lines
|
||||
@@ -69,6 +69,6 @@ pub async fn create(
|
||||
)?;
|
||||
|
||||
LogEntry::new(&tx, u, LogAction::CreateQuote { id: q.id })?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok((StatusCode::CREATED, Json(q)).into_response())
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use axum::{
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -43,7 +43,7 @@ pub async fn revoke_by_id(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let mut s = Session::get_by_id(&tx, id)?;
|
||||
match s.user_id == u.id
|
||||
@@ -53,7 +53,7 @@ pub async fn revoke_by_id(
|
||||
true => {
|
||||
s.revoke(&tx, Some(&u))?;
|
||||
LogEntry::new(&tx, u, LogAction::ManuallyRevokeSession { id })?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Json(s).into_response())
|
||||
}
|
||||
false => match u.has_permission(&tx, Permission::ListOthersSessions)? {
|
||||
|
||||
@@ -8,8 +8,8 @@ use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
tags::{Tag, TagName},
|
||||
users::{
|
||||
@@ -58,7 +58,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::CreateTags)? {
|
||||
return Ok((StatusCode::FORBIDDEN, CANT_MAKE_TAGS).into_response());
|
||||
@@ -73,7 +73,7 @@ pub async fn create(
|
||||
name: t.name.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Json(t).into_response())
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ pub async fn rename(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::RenameTags)? {
|
||||
return Ok((StatusCode::FORBIDDEN, CANT_RENAME_TAGS).into_response());
|
||||
@@ -101,7 +101,7 @@ pub async fn rename(
|
||||
nn: tag.name.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok(Json(tag).into_response())
|
||||
}
|
||||
@@ -109,7 +109,7 @@ pub async fn rename(
|
||||
pub async fn delete(Path(id): Path<Uuid>, headers: HeaderMap) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::DeleteTags)? {
|
||||
return Ok((StatusCode::FORBIDDEN, CANT_DEL_TAGS).into_response());
|
||||
@@ -118,7 +118,7 @@ pub async fn delete(Path(id): Path<Uuid>, headers: HeaderMap) -> Result<Response
|
||||
let name = t.name.as_str().to_string();
|
||||
t.delete(&tx)?;
|
||||
LogEntry::new(&tx, u, LogAction::DeleteTag { id, name })?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok((StatusCode::OK, TAG_DELETED).into_response())
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -63,7 +63,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::ManuallyCreateUsers)? {
|
||||
return Ok((StatusCode::FORBIDDEN, CANT_MANUALLY_MAKE_USERS).into_response());
|
||||
@@ -78,7 +78,7 @@ pub async fn create(
|
||||
handle: nu.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok(Json(nu).into_response())
|
||||
}
|
||||
@@ -89,7 +89,7 @@ pub async fn change_handle(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let mut target = if u.id == id {
|
||||
u.clone()
|
||||
@@ -111,7 +111,7 @@ pub async fn change_handle(
|
||||
new: target.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok(HANDLE_CHANGED_SUCCESS.into_response())
|
||||
}
|
||||
@@ -127,7 +127,7 @@ pub async fn change_password(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let mut target = if u.id == id {
|
||||
u.clone()
|
||||
@@ -144,7 +144,7 @@ pub async fn change_password(
|
||||
u,
|
||||
LogAction::ManuallyChangeUsersPassword { id: target.id },
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
|
||||
Ok(PASSW_CHANGED_SUCCESS.into_response())
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ CREATE TABLE users (
|
||||
id BLOB NOT NULL UNIQUE PRIMARY KEY, -- UUIDv7 as bytes
|
||||
handle TEXT NOT NULL UNIQUE COLLATE NOCASE,
|
||||
password TEXT, -- hashed, nullable in case of OAuth2-only login
|
||||
prof_pic TEXT -- link probably
|
||||
prof_pic TEXT -- serialized ProfilePic
|
||||
);
|
||||
CREATE TABLE sessions (
|
||||
id BLOB NOT NULL UNIQUE PRIMARY KEY, -- UUIDv7 as bytes
|
||||
@@ -8,7 +8,7 @@ macro_rules! migration {
|
||||
($name, include_str!(concat!("./migrations/", $name, ".sql")))
|
||||
};
|
||||
}
|
||||
const MIGRATIONS: &[(&str, &str)] = &[migration!("2026-03-07--01")];
|
||||
const MIGRATIONS: &[(&str, &str)] = &[migration!("2026-04-04--01")];
|
||||
|
||||
pub static DB_URL: LazyLock<String> =
|
||||
LazyLock::new(|| env::var("DATABASE_URL").expect("DATABASE_URL is not set"));
|
||||
|
||||
45
src/error.rs
Normal file
45
src/error.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use axum::response::{IntoResponse, Response};
|
||||
|
||||
use crate::{
|
||||
database::DatabaseError,
|
||||
persons::PersonError,
|
||||
quotes::QuoteError,
|
||||
tags::TagError,
|
||||
users::{UserError, auth::AuthError, sessions::SessionError},
|
||||
web::RedirectViaError,
|
||||
};
|
||||
|
||||
pub struct CompositeError(Response);
|
||||
impl IntoResponse for CompositeError {
|
||||
fn into_response(self) -> Response {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! composite_from {
|
||||
($($t:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl From<$t> for CompositeError {
|
||||
fn from(e: $t) -> Self {
|
||||
CompositeError(e.into_response())
|
||||
}
|
||||
}
|
||||
)+
|
||||
};
|
||||
}
|
||||
composite_from!(
|
||||
AuthError,
|
||||
UserError,
|
||||
SessionError,
|
||||
TagError,
|
||||
PersonError,
|
||||
QuoteError,
|
||||
DatabaseError,
|
||||
RedirectViaError,
|
||||
);
|
||||
|
||||
impl From<rusqlite::Error> for CompositeError {
|
||||
fn from(e: rusqlite::Error) -> Self {
|
||||
CompositeError(DatabaseError::from(e).into_response())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::fmt::format;
|
||||
|
||||
use rusqlite::Connection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoStaticStr;
|
||||
|
||||
@@ -6,6 +6,7 @@ use tokio::net::TcpListener;
|
||||
mod api;
|
||||
mod config;
|
||||
mod database;
|
||||
mod error;
|
||||
mod logs;
|
||||
mod persons;
|
||||
mod quotes;
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
use axum::{
|
||||
Router,
|
||||
http::header,
|
||||
response::{IntoResponse, Redirect, Response},
|
||||
routing::get,
|
||||
};
|
||||
use tower_http::services::ServeFile;
|
||||
|
||||
mod components;
|
||||
mod icons;
|
||||
mod pages;
|
||||
|
||||
pub const STYLES_CSS: &str = include_str!("./styles.css");
|
||||
|
||||
pub fn web_router() -> Router {
|
||||
Router::new()
|
||||
.route_service("/styles.css", ServeFile::new("src/web/styles.css"))
|
||||
.route(
|
||||
"/styles.css",
|
||||
get(|| async { ([(header::CONTENT_TYPE, "text/css")], STYLES_CSS) }),
|
||||
)
|
||||
.merge(pages::pages())
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ use maud::{Markup, PreEscaped, html};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
persons::{Name, Person},
|
||||
quotes::{Quote, QuoteLine},
|
||||
tags::Tag,
|
||||
@@ -25,7 +25,7 @@ const LINKS: &[(&str, &str, &str)] = &[
|
||||
pub async fn page(req: Request) -> Result<Markup, CompositeError> {
|
||||
let u = User::authenticate(req.headers()).ok().flatten();
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
Ok(base(
|
||||
"Dashboard | Mnemosyne",
|
||||
|
||||
@@ -5,8 +5,8 @@ use axum::{
|
||||
use maud::{PreEscaped, html};
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::LogEntry,
|
||||
users::{User, auth::UserAuthenticate, permissions::Permission},
|
||||
web::{RedirectViaError, components::nav::nav, icons, pages::base},
|
||||
@@ -16,7 +16,7 @@ pub async fn page(req: Request) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(req.headers())?
|
||||
.ok_or(RedirectViaError(Redirect::to("/login?re=/logs")))?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
let logs = LogEntry::get_all(&tx)?;
|
||||
|
||||
Ok(base(
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
persons::Person,
|
||||
users::{
|
||||
@@ -100,7 +100,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let p = Person::create(&tx, form.primary_name, u.id)?;
|
||||
LogEntry::new(
|
||||
@@ -111,6 +111,6 @@ pub async fn create(
|
||||
pname: p.primary_name,
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/persons").into_response())
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
tags::{Tag, TagName},
|
||||
users::{
|
||||
@@ -99,7 +99,7 @@ pub async fn create(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let t = Tag::create(&tx, form.tagname)?;
|
||||
LogEntry::new(
|
||||
@@ -110,6 +110,6 @@ pub async fn create(
|
||||
name: t.name.to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/tags").into_response())
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -73,8 +73,8 @@ pub async fn create_user(
|
||||
Form(form): Form<CreateUserWithPasswordForm>,
|
||||
) -> Result<Response, CompositeError> {
|
||||
let u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
if !u.has_permission(&tx, Permission::ManuallyCreateUsers)? {
|
||||
return Ok((StatusCode::FORBIDDEN).into_response());
|
||||
@@ -89,6 +89,6 @@ pub async fn create_user(
|
||||
handle: nu.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/users").into_response())
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ use maud::{PreEscaped, html};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
persons::Name,
|
||||
quotes::{Quote, QuoteLine},
|
||||
users::{User, UserError, auth::UserAuthenticate},
|
||||
@@ -24,8 +24,8 @@ pub async fn page(Path(id): Path<Uuid>, req: Request) -> Result<Response, Compos
|
||||
Some(u) => u,
|
||||
None => return Ok(Redirect::to("/users").into_response()),
|
||||
};
|
||||
let mut conn = database::conn().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let user = match User::get_by_id(&tx, id) {
|
||||
Ok(u) => u,
|
||||
|
||||
@@ -8,8 +8,8 @@ use maud::{PreEscaped, html};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
api::CompositeError,
|
||||
database::{self, DatabaseError},
|
||||
database::{self},
|
||||
error::CompositeError,
|
||||
logs::{LogAction, LogEntry},
|
||||
users::{
|
||||
User,
|
||||
@@ -83,7 +83,7 @@ pub async fn change_handle(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let mut u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
let oldhandle = u.handle.as_str().to_string();
|
||||
u.set_handle(&tx, form.handle)?;
|
||||
@@ -96,7 +96,7 @@ pub async fn change_handle(
|
||||
new: u.handle.as_str().to_string(),
|
||||
},
|
||||
)?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/user-settings").into_response())
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ pub async fn change_password(
|
||||
) -> Result<Response, CompositeError> {
|
||||
let mut u = User::authenticate(&headers)?.required()?;
|
||||
let mut conn = database::conn()?;
|
||||
let tx = conn.transaction().map_err(DatabaseError::from)?;
|
||||
let tx = conn.transaction()?;
|
||||
u.set_password(&tx, Some(&form.password))?;
|
||||
tx.commit().map_err(DatabaseError::from)?;
|
||||
tx.commit()?;
|
||||
Ok(Redirect::to("/user-settings").into_response())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user