summaryrefslogtreecommitdiff
path: root/src/login/repo/logins.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-09-04 00:28:35 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-09-04 00:28:35 -0400
commit2965a788cfcf4a0386cb8832e0d96491bf54c1d3 (patch)
tree096b00f64b092396e99d04ebe124fa15d734f6c1 /src/login/repo/logins.rs
parent289e99ba977ebe6c4599141bc368c17f9905ffcc (diff)
Display a different / page depending on whether the current identity is valid or not.
This is mostly a proof of concept for the implementation of form login implemented in previous commits, but it _is_ useful as it controls whether the / page shows login, or shows logout. From here, chat is next!
Diffstat (limited to 'src/login/repo/logins.rs')
-rw-r--r--src/login/repo/logins.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/login/repo/logins.rs b/src/login/repo/logins.rs
index c6db86e..84b4bf8 100644
--- a/src/login/repo/logins.rs
+++ b/src/login/repo/logins.rs
@@ -16,19 +16,17 @@ impl<'c> Provider for Transaction<'c, Sqlite> {
}
}
+// This also implements FromRequestParts (see `src/login/extract/login.rs`). As
+// a result, it can be used as an extractor.
pub struct Logins<'t>(&'t mut SqliteConnection);
#[derive(Debug)]
pub struct Login {
pub id: Id,
- // Field unused (as of this writing), omitted to avoid warnings.
- // Feel free to add it:
- //
- // pub name: String,
-
- // However, the omission of the hashed password is deliberate, to minimize
- // the chance that it ends up tangled up in debug output or in some other
- // chunk of logic elsewhere.
+ pub name: String,
+ // The omission of the hashed password is deliberate, to minimize the
+ // chance that it ends up tangled up in debug output or in some other chunk
+ // of logic elsewhere.
}
impl<'c> Logins<'c> {
@@ -49,7 +47,7 @@ impl<'c> Logins<'c> {
insert or fail
into login (id, name, password_hash)
values ($1, $2, $3)
- returning id as "id: Id"
+ returning id as "id: Id", name
"#,
id,
name,
@@ -107,13 +105,22 @@ impl<'c> Logins<'c> {
r#"
select
id as "id: Id",
+ name,
password_hash as "password_hash: StoredHash"
from login
where name = $1
"#,
name,
)
- .map(|rec| (Login { id: rec.id }, rec.password_hash))
+ .map(|rec| {
+ (
+ Login {
+ id: rec.id,
+ name: rec.name,
+ },
+ rec.password_hash,
+ )
+ })
.fetch_optional(&mut *self.0)
.await?;