Display the list of registered clients
This commit is contained in:
@ -3,3 +3,6 @@ pub const STATE_KEY: &str = "oidc-state";
|
||||
|
||||
/// Session key for user information
|
||||
pub const USER_SESSION_KEY: &str = "user";
|
||||
|
||||
/// Token length
|
||||
pub const TOKEN_LEN: usize = 20;
|
||||
|
@ -34,6 +34,7 @@ pub async fn static_file(path: web::Path<String>) -> HttpResult {
|
||||
struct HomeTemplate {
|
||||
name: String,
|
||||
matrix_token: String,
|
||||
clients: Vec<APIClient>,
|
||||
success_message: Option<String>,
|
||||
error_message: Option<String>,
|
||||
}
|
||||
@ -122,6 +123,7 @@ pub async fn home(session: Session, form_req: Option<web::Form<FormRequest>>) ->
|
||||
HomeTemplate {
|
||||
name: user.name,
|
||||
matrix_token: config.obfuscated_matrix_token(),
|
||||
clients: config.clients,
|
||||
success_message,
|
||||
error_message,
|
||||
}
|
||||
|
25
src/user.rs
25
src/user.rs
@ -4,7 +4,8 @@ use s3::{Bucket, BucketConfiguration};
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::utils::{curr_time, rand_str};
|
||||
use crate::constants::TOKEN_LEN;
|
||||
use crate::utils::{curr_time, format_time, rand_str};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum UserError {
|
||||
@ -42,16 +43,34 @@ pub struct APIClient {
|
||||
|
||||
/// Client secret
|
||||
pub secret: String,
|
||||
|
||||
/// Client creation time
|
||||
pub created: u64,
|
||||
|
||||
/// Client last usage time
|
||||
pub used: u64,
|
||||
}
|
||||
|
||||
impl APIClient {
|
||||
pub fn fmt_created(&self) -> String {
|
||||
format_time(self.created).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn fmt_used(&self) -> String {
|
||||
format_time(self.used).unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
impl APIClient {
|
||||
/// Generate a new API client
|
||||
pub fn generate(description: String, network: Option<ipnet::IpNet>) -> Self {
|
||||
Self {
|
||||
id: Default::default(),
|
||||
id: uuid::Uuid::new_v4(),
|
||||
description,
|
||||
network,
|
||||
secret: rand_str(20),
|
||||
secret: rand_str(TOKEN_LEN),
|
||||
created: curr_time().unwrap(),
|
||||
used: curr_time().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,3 +12,9 @@ pub fn curr_time() -> anyhow::Result<u64> {
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|t| t.as_secs())?)
|
||||
}
|
||||
|
||||
/// Format time
|
||||
pub fn format_time(time: u64) -> Option<String> {
|
||||
let time = chrono::DateTime::from_timestamp(time as i64, 0)?;
|
||||
Some(time.naive_local().to_string())
|
||||
}
|
||||
|
Reference in New Issue
Block a user