daemon: setting foundation for client creation
This commit is contained in:
@@ -4,11 +4,14 @@ use diesel::prelude::*;
|
||||
use crate::repository::Repository;
|
||||
use crate::settings::Settings;
|
||||
|
||||
pub use kordophone::api::TokenManagement;
|
||||
use kordophone::model::JwtToken;
|
||||
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
pub struct Database {
|
||||
connection: SqliteConnection,
|
||||
pub connection: SqliteConnection,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
@@ -39,4 +42,22 @@ impl Database {
|
||||
let mut settings = Settings::new(&mut self.connection);
|
||||
f(&mut settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static TOKEN_KEY: &str = "token";
|
||||
|
||||
impl TokenManagement for Database {
|
||||
fn get_token(&mut self) -> Option<JwtToken> {
|
||||
self.with_settings(|settings| {
|
||||
let token: Result<Option<JwtToken>> = settings.get(TOKEN_KEY);
|
||||
match token {
|
||||
Ok(data) => data,
|
||||
Err(_) => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn set_token(&mut self, token: JwtToken) {
|
||||
self.with_settings(|settings| settings.put(TOKEN_KEY, &token).unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user