reset password

master
veypi 8 months ago
parent 3e955243b7
commit 33712c23eb

@ -1,5 +1,6 @@
# OneAuth # OneAuth
test
统一验证及应用管理服务 统一验证及应用管理服务
[Demo](https://oa.veypi.com) [Demo](https://oa.veypi.com)

@ -25,6 +25,7 @@ pub fn routes(cfg: &mut web::ServiceConfig) {
cfg.service(tsdb); cfg.service(tsdb);
cfg.service(upload::save_files); cfg.service(upload::save_files);
cfg.service(user::get) cfg.service(user::get)
.service(user::reset)
.service(user::list) .service(user::list)
.service(user::register) .service(user::register)
.service(user::login) .service(user::login)

@ -9,7 +9,7 @@ use std::fmt::Debug;
use crate::{ use crate::{
libs, libs,
models::{self, app_user, user, AUStatus, UserPlugin}, models::{self, app_user, user, AUStatus, Token, UserPlugin},
AppState, Error, Result, AppState, Error, Result,
}; };
use actix_web::{delete, get, head, http, patch, post, web, HttpResponse, Responder}; use actix_web::{delete, get, head, http, patch, post, web, HttpResponse, Responder};
@ -35,6 +35,47 @@ pub async fn get(id: web::Path<String>, stat: web::Data<AppState>) -> Result<imp
} }
} }
#[derive(Debug, Deserialize, Serialize)]
pub struct ResetOptions {
p: Option<String>,
}
#[get("/user/{id}/reset")]
#[access_read("user")]
pub async fn reset(
id: web::Path<String>,
stat: web::Data<AppState>,
t: web::ReqData<Token>,
query: web::Query<ResetOptions>,
) -> Result<impl Responder> {
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)] #[derive(Debug, Deserialize, Serialize)]
pub struct ListOptions { pub struct ListOptions {
name: Option<String>, name: Option<String>,
@ -221,7 +262,6 @@ pub struct UpdateOpt {
pub nickname: Option<String>, pub nickname: Option<String>,
pub email: Option<String>, pub email: Option<String>,
pub phone: Option<String>, pub phone: Option<String>,
pub test: serde_json::Value,
} }
#[patch("/user/{id}")] #[patch("/user/{id}")]
@ -232,7 +272,6 @@ pub async fn update(
stat: web::Data<AppState>, stat: web::Data<AppState>,
data: web::Json<UpdateOpt>, data: web::Json<UpdateOpt>,
) -> Result<impl Responder> { ) -> Result<impl Responder> {
info!("{:#?}", data.test);
Ok("") Ok("")
} }

@ -14,7 +14,7 @@ use tracing::info;
#[clap(name = "oab")] #[clap(name = "oab")]
#[clap(about = "oab", long_about = None)] #[clap(about = "oab", long_about = None)]
pub struct AppCli { 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, pub cfg: String,
#[clap(short = 'n', value_name = "name",default_value_t = String::from("v.oab"))] #[clap(short = 'n', value_name = "name",default_value_t = String::from("v.oab"))]
pub name: String, pub name: String,

@ -19,6 +19,12 @@ export default {
}, prop) }, prop)
return ajax.post(this.local, data) 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) { login(username: string, password: string) {
return ajax.head(this.local + username, { return ajax.head(this.local + username, {
typ: 'username', typ: 'username',

@ -48,6 +48,7 @@ import api from 'src/boot/api';
import msg from '@veypi/msg'; import msg from '@veypi/msg';
import { util } from 'src/libs'; import { util } from 'src/libs';
import cfg from 'src/cfg'; import cfg from 'src/cfg';
import { useQuasar } from 'quasar';
const auOpts: { [index: number]: any } = { const auOpts: { [index: number]: any } = {
[AUStatus.OK]: ['正常', 'positive'], [AUStatus.OK]: ['正常', 'positive'],
@ -55,6 +56,7 @@ const auOpts: { [index: number]: any } = {
[AUStatus.Applying]: ['申请中', 'primary'], [AUStatus.Applying]: ['申请中', 'primary'],
[AUStatus.Disabled]: ['禁用', 'warning'], [AUStatus.Disabled]: ['禁用', 'warning'],
} }
let $q = useQuasar()
let app = inject('app') as Ref<modelsApp> let app = inject('app') as Ref<modelsApp>
const columns = [ const columns = [
{ {
@ -91,6 +93,18 @@ const update_status = (id: string, n: number, old: number) => {
} }
const reset = (id: string) => { 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 = () => { const sync = () => {

@ -90,6 +90,11 @@ const reset = () => {
msg.Warn('两次密码不一致') msg.Warn('两次密码不一致')
return return
} }
api.user.reset(u.id, pass.value[0]).then((e) => {
msg.Info('密码重置成功')
}).catch(e => {
msg.Warn('密码重置失败 ' + e)
})
} }
</script> </script>

Loading…
Cancel
Save