Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Dec 22, 2023
1 parent 936629d commit 18c4e27
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 54 deletions.
14 changes: 7 additions & 7 deletions src/common/constant.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub const APP_VERSION: &'static str = "0.4.0-beta.4";
pub const APP_VERSION: &str = "0.4.0-beta.4";

pub const EMPTY_STR: &'static str = "";
pub const EMPTY_STR: &str = "";

pub const HTTP_METHOD_GET: &'static str = "GET";
//pub const HTTP_METHOD_PUT:&'static str= "PUT";
//pub const HTTP_METHOD_POST:&'static str= "POST";
//pub const HTTP_METHOD_DELETE:&'static str= "DELETE";
pub const HTTP_METHOD_ALL: &'static str = EMPTY_STR;
pub const HTTP_METHOD_GET: &str = "GET";
//pub const HTTP_METHOD_PUT:&str= "PUT";
//pub const HTTP_METHOD_POST:&str= "POST";
//pub const HTTP_METHOD_DELETE:&str= "DELETE";
pub const HTTP_METHOD_ALL: &str = EMPTY_STR;
2 changes: 1 addition & 1 deletion src/console/login_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn login(
let captcha_check_result = if let Ok(Ok(CacheManagerResult::Value(CacheValue::String(v)))) =
app.cache_manager.send(cache_req).await
{
v.as_str() == &captcha_code
&captcha_code == v.as_ref()
} else {
false
};
Expand Down
9 changes: 2 additions & 7 deletions src/console/model/user_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ impl UpdateUserInfoParam {
if roles.is_empty() {
return None;
}
Some(
roles
.split(',')
.map(|e| UserRoleHelper::get_role(e))
.collect(),
)
Some(roles.split(',').map(UserRoleHelper::get_role).collect())
} else {
None
}
Expand All @@ -56,7 +51,7 @@ impl From<UpdateUserInfoParam> for UserDto {
nickname: value.nickname,
password: value.password,
enable: value.enable,
roles: roles,
roles,
..Default::default()
}
}
Expand Down
65 changes: 34 additions & 31 deletions src/console/user_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,43 +72,46 @@ pub async fn reset_password(
app: Data<Arc<AppShareData>>,
web::Form(param): web::Form<ResetPasswordParam>,
) -> actix_web::Result<impl Responder> {
if let Some(session) = req.extensions().get::<Arc<UserSession>>() {
let (msg, username) = if let Some(session) = req.extensions().get::<Arc<UserSession>>() {
let username = Arc::new(session.username.to_string());
let msg = UserManagerReq::CheckUser {
name: username.clone(),
password: param.old_password,
};
if let Ok(Ok(v)) = app.user_manager.send(msg).await {
match v {
UserManagerResult::CheckUserResult(valid, _user) => {
if valid {
let msg = UserManagerReq::UpdateUser {
user: UserDto {
username: username,
password: Some(param.new_password),
..Default::default()
},
};
if let Ok(Ok(_r)) = app.user_manager.send(msg).await {
return Ok(HttpResponse::Ok().json(ApiResult::success(Some(true))));
}
(
UserManagerReq::CheckUser {
name: username.clone(),
password: param.old_password,
},
username,
)
} else {
return Ok(HttpResponse::Ok().json(ApiResult::<()>::error(
"NOT_FOUND_USER_SESSION".to_owned(),
None,
)));
};
if let Ok(Ok(v)) = app.user_manager.send(msg).await {
match v {
UserManagerResult::CheckUserResult(valid, _user) => {
if valid {
let msg = UserManagerReq::UpdateUser {
user: UserDto {
username,
password: Some(param.new_password),
..Default::default()
},
};
if let Ok(Ok(_r)) = app.user_manager.send(msg).await {
return Ok(HttpResponse::Ok().json(ApiResult::success(Some(true))));
}
}
_ => {
return Ok(HttpResponse::Ok().json(ApiResult::<()>::error(
"OLD_PASSWORD_INVALID".to_owned(),
None,
)))
}
}
_ => {
return Ok(HttpResponse::Ok().json(ApiResult::<()>::error(
"OLD_PASSWORD_INVALID".to_owned(),
None,
)))
}
}
Ok(HttpResponse::Ok().json(ApiResult::<()>::error("SYSTEM_ERROR".to_owned(), None)))
} else {
Ok(HttpResponse::Ok().json(ApiResult::<()>::error(
"NOT_FOUND_USER_SESSION".to_owned(),
None,
)))
}
Ok(HttpResponse::Ok().json(ApiResult::<()>::error("SYSTEM_ERROR".to_owned(), None)))
}

pub async fn get_user_page_list(
Expand Down
5 changes: 1 addition & 4 deletions src/middle/login_middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ async fn get_user_session(
req: CacheManagerReq,
) -> anyhow::Result<Option<Arc<UserSession>>> {
match cache_manager.send(req).await?? {
CacheManagerResult::Value(v) => match v {
CacheValue::UserSession(session) => Ok(Some(session)),
_ => Ok(None),
},
CacheManagerResult::Value(CacheValue::UserSession(session)) => Ok(Some(session)),
_ => Ok(None),
}
}
8 changes: 4 additions & 4 deletions src/user/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl UserRole {
.unwrap()
.web_resources
.iter()
.map(|e| *e)
.copied()
.collect();
}
let mut set = HashSet::new();
Expand All @@ -321,12 +321,12 @@ impl UserRole {
set.insert(*item);
}
}
set.into_iter().map(|e| e).collect()
set.into_iter().collect()
}

pub fn get_web_resources_by_roles(role_values: Vec<&str>) -> Vec<&'static str> {
//log::info!("get_web_resources_by_roles {:?}", &role_values);
let roles: Vec<Self> = role_values.into_iter().map(|e| Self::new(e)).collect();
let roles: Vec<Self> = role_values.into_iter().map(Self::new).collect();
if roles.len() == 1 {
return roles.first().unwrap().get_web_resources();
}
Expand All @@ -338,7 +338,7 @@ impl UserRole {
}
}
}
set.into_iter().map(|e| e).collect()
set.into_iter().collect()
}
}

Expand Down

0 comments on commit 18c4e27

Please sign in to comment.