From 33712c23eb3337e1d8d824148e570cf26d22e7b0 Mon Sep 17 00:00:00 2001 From: veypi Date: Sat, 16 Mar 2024 01:19:32 +0800 Subject: [PATCH] reset password --- README.md | 1 + oab/src/api/mod.rs | 1 + oab/src/api/user.rs | 45 +++++++++++++++++++++++++++++++++--- oab/src/cli.rs | 2 +- oaweb/src/boot/api/user.ts | 6 +++++ oaweb/src/pages/app/user.vue | 14 +++++++++++ oaweb/src/pages/user.vue | 5 ++++ 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 40b3da3..29656b2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # OneAuth +test 统一验证及应用管理服务 [Demo](https://oa.veypi.com) diff --git a/oab/src/api/mod.rs b/oab/src/api/mod.rs index 0c2d8b0..a70b3ee 100644 --- a/oab/src/api/mod.rs +++ b/oab/src/api/mod.rs @@ -25,6 +25,7 @@ pub fn routes(cfg: &mut web::ServiceConfig) { cfg.service(tsdb); cfg.service(upload::save_files); cfg.service(user::get) + .service(user::reset) .service(user::list) .service(user::register) .service(user::login) diff --git a/oab/src/api/user.rs b/oab/src/api/user.rs index 5c33f12..2b33f35 100644 --- a/oab/src/api/user.rs +++ b/oab/src/api/user.rs @@ -9,7 +9,7 @@ use std::fmt::Debug; use crate::{ libs, - models::{self, app_user, user, AUStatus, UserPlugin}, + models::{self, app_user, user, AUStatus, Token, UserPlugin}, AppState, Error, Result, }; use actix_web::{delete, get, head, http, patch, post, web, HttpResponse, Responder}; @@ -35,6 +35,47 @@ pub async fn get(id: web::Path, stat: web::Data) -> Result, +} + +#[get("/user/{id}/reset")] +#[access_read("user")] +pub async fn reset( + id: web::Path, + stat: web::Data, + t: web::ReqData, + query: web::Query, +) -> Result { + let id = id.into_inner(); + // default optx123 + let p = match query.into_inner().p { + Some(p) => p, + None => "b3B0eDEyMw==".to_string(), + }; + if t.can_delete("user", &id) || id == t.id { + let mut uobj = models::user::Entity::find_by_id(&id) + .one(stat.db()) + .await? + .ok_or("not found id")?; + let p = match base64::decode(p.as_bytes()) { + Err(_) => return Err(Error::ArgInvalid("password".to_string())), + Ok(p) => p, + }; + let p = match std::str::from_utf8(&p) { + Ok(p) => p, + Err(_) => return Err(Error::ArgInvalid("password".to_string())), + }; + let mut u: models::user::ActiveModel = uobj.clone().into(); + uobj.update_pass(&p)?; + u.real_code = sea_orm::Set(uobj.real_code); + u.check_code = sea_orm::Set(uobj.check_code); + u.update(stat.db()).await?; + } + Ok("") +} + #[derive(Debug, Deserialize, Serialize)] pub struct ListOptions { name: Option, @@ -221,7 +262,6 @@ pub struct UpdateOpt { pub nickname: Option, pub email: Option, pub phone: Option, - pub test: serde_json::Value, } #[patch("/user/{id}")] @@ -232,7 +272,6 @@ pub async fn update( stat: web::Data, data: web::Json, ) -> Result { - info!("{:#?}", data.test); Ok("") } diff --git a/oab/src/cli.rs b/oab/src/cli.rs index 058cd33..caf9b72 100644 --- a/oab/src/cli.rs +++ b/oab/src/cli.rs @@ -14,7 +14,7 @@ use tracing::info; #[clap(name = "oab")] #[clap(about = "oab", long_about = None)] pub struct AppCli { - #[clap(short = 'c', value_name = "cfg",default_value_t = String::from("~/.config/oa/oab.yml"), value_hint = clap::ValueHint::DirPath)] + #[clap(short = 'c', value_name = "cfg",default_value_t = String::from("/root/.config/oa/oab.yml"), value_hint = clap::ValueHint::DirPath)] pub cfg: String, #[clap(short = 'n', value_name = "name",default_value_t = String::from("v.oab"))] pub name: String, diff --git a/oaweb/src/boot/api/user.ts b/oaweb/src/boot/api/user.ts index 6ac709c..2b46a61 100644 --- a/oaweb/src/boot/api/user.ts +++ b/oaweb/src/boot/api/user.ts @@ -19,6 +19,12 @@ export default { }, prop) return ajax.post(this.local, data) }, + reset(id: string, p?: string) { + if (p) { + p = Base64.encode(p) + } + return ajax.get(this.local + id + '/reset', { p: p }) + }, login(username: string, password: string) { return ajax.head(this.local + username, { typ: 'username', diff --git a/oaweb/src/pages/app/user.vue b/oaweb/src/pages/app/user.vue index cd44d36..7227c83 100644 --- a/oaweb/src/pages/app/user.vue +++ b/oaweb/src/pages/app/user.vue @@ -48,6 +48,7 @@ import api from 'src/boot/api'; import msg from '@veypi/msg'; import { util } from 'src/libs'; import cfg from 'src/cfg'; +import { useQuasar } from 'quasar'; const auOpts: { [index: number]: any } = { [AUStatus.OK]: ['正常', 'positive'], @@ -55,6 +56,7 @@ const auOpts: { [index: number]: any } = { [AUStatus.Applying]: ['申请中', 'primary'], [AUStatus.Disabled]: ['禁用', 'warning'], } +let $q = useQuasar() let app = inject('app') as Ref const columns = [ { @@ -91,6 +93,18 @@ const update_status = (id: string, n: number, old: number) => { } const reset = (id: string) => { + $q.dialog({ + title: '是否重置密码', + message: '请谨慎操作', + cancel: true, + persistent: true + }).onOk(() => { + api.user.reset(id).then(e => { + msg.Info('重置成功 ') + }).catch(e => { + msg.Warn('失败 ' + e) + }) + }) } const sync = () => { diff --git a/oaweb/src/pages/user.vue b/oaweb/src/pages/user.vue index 9c8dd2a..712f35f 100644 --- a/oaweb/src/pages/user.vue +++ b/oaweb/src/pages/user.vue @@ -90,6 +90,11 @@ const reset = () => { msg.Warn('两次密码不一致') return } + api.user.reset(u.id, pass.value[0]).then((e) => { + msg.Info('密码重置成功') + }).catch(e => { + msg.Warn('密码重置失败 ' + e) + }) }