mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
cleanup user code
This commit is contained in:
parent
fdcc48f8be
commit
ceb2646502
1 changed files with 14 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::definitions::Referenceable;
|
use crate::definitions::system::User;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use rbtag::BuildInfo;
|
use rbtag::BuildInfo;
|
||||||
|
@ -60,25 +60,24 @@ pub fn routes() -> Router<AppState> {
|
||||||
.route("/session", post(session_handler))
|
.route("/session", post(session_handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_user(name: String, users: Vec<User>) -> Option<User> {
|
||||||
|
for u in users {
|
||||||
|
if u.name == name {
|
||||||
|
return Some(u);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
async fn login_handler(
|
async fn login_handler(
|
||||||
cookies: Cookies,
|
cookies: Cookies,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(payload): Json<LoginParameters>,
|
Json(payload): Json<LoginParameters>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
if state
|
if let Some(user) = get_user(
|
||||||
.config_manager
|
payload.username.to_string(),
|
||||||
.get_current_config()
|
state.config_manager.get_current_config().system.users,
|
||||||
.system
|
) {
|
||||||
.users
|
|
||||||
.named_exists(payload.username.to_string())
|
|
||||||
{
|
|
||||||
let user = state
|
|
||||||
.config_manager
|
|
||||||
.get_current_config()
|
|
||||||
.system
|
|
||||||
.users
|
|
||||||
.named_get(payload.username.to_string());
|
|
||||||
|
|
||||||
if sha512_crypt::verify(payload.password, &user.hash) {
|
if sha512_crypt::verify(payload.password, &user.hash) {
|
||||||
let mut sessions = state.session_state.sessions.write().unwrap();
|
let mut sessions = state.session_state.sessions.write().unwrap();
|
||||||
let id = Uuid::new_v4().to_string();
|
let id = Uuid::new_v4().to_string();
|
||||||
|
|
Loading…
Add table
Reference in a new issue