summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/ops.rs6
-rw-r--r--src/api/users.rs4
2 files changed, 10 insertions, 0 deletions
diff --git a/src/api/ops.rs b/src/api/ops.rs
index 9bebc2d..018743c 100644
--- a/src/api/ops.rs
+++ b/src/api/ops.rs
@@ -6,12 +6,15 @@ use thiserror::Error;
use crate::services::db;
+/// A request to login
#[derive(Debug, Clone, Deserialize)]
struct LoginRequest {
username: Box<str>,
password: Box<str>,
}
+/// An error occurred when authenticating, because either the username or
+/// password was invalid.
#[derive(Debug, Clone, Error)]
enum LoginFailure {
#[error("No user found with the given username")]
@@ -29,6 +32,9 @@ impl ResponseError for LoginFailure {
}
}
+/// Returns `200` if login was successful.
+/// Returns `404` if the username is invalid.
+/// Returns `401` if the password was invalid.
#[post("/login")]
async fn login(
body: web::Json<LoginRequest>,
diff --git a/src/api/users.rs b/src/api/users.rs
index d62cc27..863d99e 100644
--- a/src/api/users.rs
+++ b/src/api/users.rs
@@ -10,14 +10,17 @@ use crate::models::User;
use crate::services::crypto::PasswordHash;
use crate::services::{db, id};
+/// Just a username. No password hash, because that'd be tempting fate.
#[derive(Debug, Clone, Serialize)]
struct UserResponse {
+ id: Uuid,
username: Box<str>,
}
impl From<User> for UserResponse {
fn from(user: User) -> Self {
Self {
+ id: user.id,
username: user.username,
}
}
@@ -107,6 +110,7 @@ async fn get_username(
Ok(response)
}
+/// A request to create or update user information
#[derive(Debug, Clone, Deserialize)]
struct UserRequest {
username: Box<str>,