summaryrefslogtreecommitdiffstats
path: root/adenosine-pds/src/db.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-03 18:19:22 -0700
committerBryan Newbold <bnewbold@robocracy.org>2022-11-03 18:19:22 -0700
commit95c05cc53c5b42b535cf70f8cee69c1a0be958b7 (patch)
treeafe00f175bf83228f319fbc214c0ba81f7cb6dfd /adenosine-pds/src/db.rs
parent2004d5ea148b8b21cd0cffeb82fd8f07f52d1ba7 (diff)
downloadadenosine-95c05cc53c5b42b535cf70f8cee69c1a0be958b7.tar.gz
adenosine-95c05cc53c5b42b535cf70f8cee69c1a0be958b7.zip
pds: various bugfixes
Diffstat (limited to 'adenosine-pds/src/db.rs')
-rw-r--r--adenosine-pds/src/db.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/adenosine-pds/src/db.rs b/adenosine-pds/src/db.rs
index 03f6c68..72f2a8d 100644
--- a/adenosine-pds/src/db.rs
+++ b/adenosine-pds/src/db.rs
@@ -1,5 +1,5 @@
-use crate::AtpSession;
/// ATP database (as distinct from blockstore)
+use crate::{AtpSession, KeyPair};
use anyhow::{anyhow, Result};
use lazy_static::lazy_static;
use log::debug;
@@ -110,19 +110,30 @@ impl AtpDatabase {
username: &str,
password: &str,
email: &str,
+ recovery_pubkey: &str,
) -> Result<()> {
debug!("bcrypt hashing password (can be slow)...");
let password_bcrypt = bcrypt::hash(password, bcrypt::DEFAULT_COST)?;
- let did = "did:TODO";
let mut stmt = self.conn.prepare_cached(
- "INSERT INTO account (username, password_bcrypt, email, did) VALUES (?1, ?2, ?3, ?4)",
+ "INSERT INTO account (username, password_bcrypt, email, did, recovery_pubkey) VALUES (?1, ?2, ?3, ?4, ?5)",
)?;
- stmt.execute(params!(username, password_bcrypt, email, did))?;
+ stmt.execute(params!(
+ username,
+ password_bcrypt,
+ email,
+ did,
+ recovery_pubkey
+ ))?;
Ok(())
}
/// Returns a JWT session token
- pub fn create_session(&mut self, username: &str, password: &str) -> Result<AtpSession> {
+ pub fn create_session(
+ &mut self,
+ username: &str,
+ password: &str,
+ keypair: &KeyPair,
+ ) -> Result<AtpSession> {
let mut stmt = self
.conn
.prepare_cached("SELECT did, password_bcrypt FROM account WHERE username = ?1")?;
@@ -131,9 +142,11 @@ impl AtpDatabase {
if !bcrypt::verify(password, &password_bcrypt)? {
return Err(anyhow!("password did not match"));
}
- // TODO: generate JWT
- // TODO: insert session with JWT
- let jwt = "jwt:BOGUS";
+ let jwt = keypair.ucan()?;
+ let mut stmt = self
+ .conn
+ .prepare_cached("INSERT INTO session (did, jwt) VALUES (?1, ?2)")?;
+ stmt.execute(params!(did, jwt))?;
Ok(AtpSession {
did,
name: username.to_string(),