summaryrefslogtreecommitdiff
path: root/src/login/repo/logins.rs
diff options
context:
space:
mode:
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?;