Update Dependencies

Fixes #6
Fixes #7

Signed-off-by: trivernis <trivernis@protonmail.com>
develop
trivernis 4 years ago
parent b1c027bf7a
commit dcafde35fa
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

408
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,6 +1,6 @@
[package] [package]
name = "flotte-user-management" name = "flotte-user-management"
version = "0.3.0" version = "0.3.1"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
license = "GPL-3.0" license = "GPL-3.0"

@ -10,7 +10,7 @@ use zeroize::{Zeroize, Zeroizing};
use crate::database::models::{Permission, UserInformation, UserRecord}; use crate::database::models::{Permission, UserInformation, UserRecord};
use crate::database::tokens::{SessionTokens, TokenStore}; use crate::database::tokens::{SessionTokens, TokenStore};
use crate::database::user_roles::UserRoles; use crate::database::user_roles::UserRoles;
use crate::database::{DatabaseResult, PostgresPool, Table}; use crate::database::{DatabaseResult, PostgresPool, Table, DEFAULT_ADMIN_EMAIL};
use crate::utils::error::DBError; use crate::utils::error::DBError;
use crate::utils::{create_salt, hash_password}; use crate::utils::{create_salt, hash_password};
use serde_json::Value; use serde_json::Value;
@ -81,6 +81,7 @@ impl Users {
Ok(UserRecord::from_row(row)) Ok(UserRecord::from_row(row))
} }
/// Updates a user
pub fn update_user( pub fn update_user(
&self, &self,
old_email: &String, old_email: &String,
@ -147,6 +148,7 @@ impl Users {
Ok(UserInformation::from_row(result)) Ok(UserInformation::from_row(result))
} }
/// Returns the user record by email
pub fn get_user_by_email(&self, email: &String) -> DatabaseResult<UserInformation> { pub fn get_user_by_email(&self, email: &String) -> DatabaseResult<UserInformation> {
log::trace!("Looking up entry for user with email {}", email); log::trace!("Looking up entry for user with email {}", email);
let mut connection = self.pool.get()?; let mut connection = self.pool.get()?;
@ -160,6 +162,7 @@ impl Users {
Ok(UserInformation::from_row(result)) Ok(UserInformation::from_row(result))
} }
/// Returns all users
pub fn get_users(&self) -> DatabaseResult<Vec<UserInformation>> { pub fn get_users(&self) -> DatabaseResult<Vec<UserInformation>> {
log::trace!("Returning a list of all users..."); log::trace!("Returning a list of all users...");
let mut connection = self.pool.get()?; let mut connection = self.pool.get()?;
@ -173,8 +176,14 @@ impl Users {
Ok(users) Ok(users)
} }
/// Deletes a user if it's not the admin user
pub fn delete_user(&self, email: &String) -> DatabaseResult<()> { pub fn delete_user(&self, email: &String) -> DatabaseResult<()> {
log::trace!("Deleting user with email {}", email); log::trace!("Deleting user with email {}", email);
if email == DEFAULT_ADMIN_EMAIL {
return Err(DBError::GenericError(
"the admin user can't be deleted".to_string(),
));
}
let mut connection = self.pool.get()?; let mut connection = self.pool.get()?;
let exists = connection.query_opt("SELECT id FROM users WHERE email = $1", &[email])?; let exists = connection.query_opt("SELECT id FROM users WHERE email = $1", &[email])?;
if exists.is_none() { if exists.is_none() {

@ -3,12 +3,12 @@
// See LICENSE for more information // See LICENSE for more information
use std::error::Error; use std::error::Error;
use std::fmt::Formatter;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::io::Read; use std::io::Read;
use regex::Regex; use regex::Regex;
use rouille::{Request, Response, Server}; use rouille::{Request, Response, Server};
use serde::export::Formatter;
use serde::Serialize; use serde::Serialize;
use crate::database::models::{Permission, Role, UserFullInformation, UserInformation}; use crate::database::models::{Permission, Role, UserFullInformation, UserInformation};

@ -6,13 +6,11 @@ use std::error::Error;
use std::fmt; use std::fmt;
use std::fmt::Display; use std::fmt::Display;
use serde::export::Formatter;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
use zeroize::Zeroize; use zeroize::Zeroize;
use crate::database::models::{ use crate::database::models::{CreatePermissionsEntry, Permission, UserFullInformation};
CreatePermissionsEntry, Permission, UserFullInformation, UserInformation,
};
use crate::utils::error::DBError; use crate::utils::error::DBError;
use serde_json::Value; use serde_json::Value;

Loading…
Cancel
Save