Can change user password
This commit is contained in:
@ -3,3 +3,4 @@ pub mod entity_manager;
|
||||
pub mod service;
|
||||
pub mod session_identity;
|
||||
pub mod user;
|
||||
pub mod remote_ip;
|
28
src/data/remote_ip.rs
Normal file
28
src/data/remote_ip.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::net::IpAddr;
|
||||
|
||||
use actix_web::{Error, FromRequest, HttpRequest, web};
|
||||
use actix_web::dev::Payload;
|
||||
use futures_util::future::{Ready, ready};
|
||||
|
||||
use crate::data::app_config::AppConfig;
|
||||
use crate::utils::network_utils::get_remote_ip;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct RemoteIP(pub IpAddr);
|
||||
|
||||
impl Into<IpAddr> for RemoteIP {
|
||||
fn into(self) -> IpAddr {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRequest for RemoteIP {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<RemoteIP, Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
let config: &web::Data<AppConfig> = req.app_data().expect("AppData undefined!");
|
||||
ready(Ok(RemoteIP(get_remote_ip(req, config.proxy_ip.as_deref()))))
|
||||
}
|
||||
}
|
@ -21,6 +21,12 @@ pub struct User {
|
||||
pub authorized_services: Option<Vec<ServiceID>>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn verify_password<P: AsRef<[u8]>>(&self, pass: P) -> bool {
|
||||
verify_password(pass, &self.password)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for User {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.uid.eq(&other.uid)
|
||||
@ -81,8 +87,8 @@ impl EntityManager<User> {
|
||||
|
||||
/// Update user information
|
||||
fn update_user<F>(&mut self, id: &UserID, update: F) -> bool
|
||||
where
|
||||
F: FnOnce(User) -> User,
|
||||
where
|
||||
F: FnOnce(User) -> User,
|
||||
{
|
||||
let user = match self.find_by_user_id(id) {
|
||||
None => return false,
|
||||
|
Reference in New Issue
Block a user