Use empty struct for Authenticated
This commit is contained in:
parent
6605af7bed
commit
0d23307f86
|
@ -4,13 +4,12 @@
|
||||||
//!
|
//!
|
||||||
//! The configuration file is located at: "/var/lib/peachcloud/config.yml"
|
//! The configuration file is located at: "/var/lib/peachcloud/config.yml"
|
||||||
|
|
||||||
use fslock::{LockFile, IntoOsString};
|
use fslock::{LockFile};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::error::PeachError;
|
use crate::error::PeachError;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::password_utils::hash_password;
|
|
||||||
|
|
||||||
// main configuration file
|
// main configuration file
|
||||||
pub const YAML_PATH: &str = "/var/lib/peachcloud/config.yml";
|
pub const YAML_PATH: &str = "/var/lib/peachcloud/config.yml";
|
||||||
|
|
|
@ -2,14 +2,11 @@ use crate::config_manager::{get_peachcloud_domain, load_peach_config,
|
||||||
set_admin_password_hash, get_admin_password_hash,
|
set_admin_password_hash, get_admin_password_hash,
|
||||||
get_temporary_password_hash, set_temporary_password_hash};
|
get_temporary_password_hash, set_temporary_password_hash};
|
||||||
use crate::error::PeachError;
|
use crate::error::PeachError;
|
||||||
use crate::error::StdIoError;
|
|
||||||
use crate::sbot_client;
|
use crate::sbot_client;
|
||||||
use log::info;
|
use log::info;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use snafu::ResultExt;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::process::Command;
|
|
||||||
use crypto::digest::Digest;
|
use crypto::digest::Digest;
|
||||||
use crypto::sha3::Sha3;
|
use crypto::sha3::Sha3;
|
||||||
|
|
||||||
|
@ -52,7 +49,7 @@ pub fn set_new_password(new_password: &str) -> Result<(), PeachError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a hash from a password string
|
/// Creates a hash from a password string
|
||||||
pub fn hash_password(password: &String) -> String {
|
pub fn hash_password(password: &str) -> String {
|
||||||
let mut hasher = Sha3::sha3_256();
|
let mut hasher = Sha3::sha3_256();
|
||||||
hasher.input_str(password);
|
hasher.input_str(password);
|
||||||
hasher.result_str()
|
hasher.result_str()
|
||||||
|
|
|
@ -24,9 +24,11 @@ use rocket::http::{Cookie, CookieJar, Status};
|
||||||
pub const AUTH_COOKIE_KEY: &str = "peachweb_auth";
|
pub const AUTH_COOKIE_KEY: &str = "peachweb_auth";
|
||||||
pub const ADMIN_USERNAME: &str = "admin";
|
pub const ADMIN_USERNAME: &str = "admin";
|
||||||
|
|
||||||
pub struct Authenticated {
|
/// Note: Currently we use an empty struct for the Authenticated request guard
|
||||||
is_authenticated: bool,
|
/// because there is only one user to be authenticated, and no data needs to be stored here.
|
||||||
}
|
/// In a multi-user authentication scheme, we would store the user_id in this struct,
|
||||||
|
/// and retrieve the correct user via the user_id stored in the cookie.
|
||||||
|
pub struct Authenticated;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum LoginError {
|
pub enum LoginError {
|
||||||
|
@ -47,7 +49,7 @@ impl<'r> FromRequest<'r> for Authenticated {
|
||||||
.cookies()
|
.cookies()
|
||||||
.get_private(AUTH_COOKIE_KEY)
|
.get_private(AUTH_COOKIE_KEY)
|
||||||
.and_then(|cookie| cookie.value().parse().ok())
|
.and_then(|cookie| cookie.value().parse().ok())
|
||||||
.map(|_value: String| { Authenticated { is_authenticated: true } });
|
.map(|_value: String| { Authenticated { } });
|
||||||
match authenticated {
|
match authenticated {
|
||||||
Some(auth) => {
|
Some(auth) => {
|
||||||
request::Outcome::Success(auth)
|
request::Outcome::Success(auth)
|
||||||
|
|
Loading…
Reference in New Issue