-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: suit module auth to new api generator
- Loading branch information
1 parent
88b1228
commit 89541fb
Showing
14 changed files
with
149 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,100 @@ | ||
import {AppFuncTs} from "@/logic/app_func"; | ||
import {LoginArg, VerifyTokenArg} from "@/logic/commu/api_caller"; | ||
import {_PaUtilTs} from "@/3rd/pa_util_ts"; | ||
import {ElNotification} from "element-plus"; | ||
|
||
export class AuthorityMan{ | ||
private verified=false; | ||
verify_token_when_first_load(){ | ||
let token=window.localStorage["panote_token"] | ||
if(token&&_PaUtilTs._JudgeType.is_string(token)){ | ||
this.ctx.api_caller | ||
.verify_token(new VerifyTokenArg(token),(r)=>{ | ||
if(r.if_success){ | ||
this.verified=true | ||
this.ctx.app.showlogbtn=false | ||
window.localStorage["panote_token"]=r.new_token | ||
ElNotification({ | ||
title: 'Success', | ||
message: 'token 已更新', | ||
type: 'success', | ||
}) | ||
}else{ | ||
delete window.localStorage["panote_token"] | ||
} | ||
}) | ||
} | ||
} | ||
is_logged_in(){ | ||
return this.verified | ||
} | ||
login(id:string,pw:string,cb:(succ:boolean)=>void){ | ||
this.ctx.api_caller | ||
.login(new LoginArg(id,pw),(r)=>{ | ||
if(r.if_success==1){ | ||
this.verified=true | ||
this.ctx.app.showlogbtn=false | ||
window.localStorage["panote_token"]=r.token | ||
import { AppFuncTs } from "@/logic/app_func"; | ||
import { LoginArg, VerifyTokenArg } from "@/logic/commu/api_caller"; | ||
import { _PaUtilTs } from "@/3rd/pa_util_ts"; | ||
import { ElNotification } from "element-plus"; | ||
import { LoginReq, VerifyTokenReq, apis } from "./gen_api_auth"; | ||
|
||
export class AuthorityMan { | ||
private verified = false; | ||
verify_token_when_first_load() { | ||
let token = window.localStorage["panote_token"] | ||
if (token && _PaUtilTs._JudgeType.is_string(token)) { | ||
apis.verify_token(new VerifyTokenReq(token)).then(r => { | ||
let succ = r.succ() | ||
let fail = r.fail() | ||
if (succ) { | ||
this.verified = true | ||
this.ctx.app.showlogbtn = false | ||
window.localStorage["panote_token"] = succ.new_token | ||
ElNotification({ | ||
title: 'Success', | ||
message: '登录成功', | ||
message: 'token 已更新', | ||
type: 'success', | ||
}) | ||
cb(true) | ||
}else{ | ||
cb(false) | ||
} else { | ||
console.warn("token 已过期", fail) | ||
ElNotification({ | ||
title: 'Fail', | ||
message: 'token 已过期', | ||
type: 'fail', | ||
}) | ||
delete window.localStorage["panote_token"] | ||
} | ||
}) | ||
// this.ctx.api_caller | ||
// .verify_token(new VerifyTokenArg(token), (r) => { | ||
// if (r.if_success) { | ||
// this.verified = true | ||
// this.ctx.app.showlogbtn = false | ||
// window.localStorage["panote_token"] = r.new_token | ||
// ElNotification({ | ||
// title: 'Success', | ||
// message: 'token 已更新', | ||
// type: 'success', | ||
// }) | ||
// } else { | ||
// delete window.localStorage["panote_token"] | ||
// } | ||
// }) | ||
} | ||
} | ||
is_logged_in() { | ||
return this.verified | ||
} | ||
login(id: string, pw: string, cb: (succ: boolean) => void) { | ||
apis.login(new LoginReq(id, pw)).then(r => { | ||
let succ = r.succ() | ||
let fail = r.fail() | ||
if (succ) { | ||
this.verified = true | ||
this.ctx.app.showlogbtn = false | ||
window.localStorage["panote_token"] = succ.token | ||
ElNotification({ | ||
title: 'Success', | ||
message: '登录成功', | ||
type: 'success', | ||
}) | ||
cb(true) | ||
} else { | ||
ElNotification({ | ||
title: 'Fail', | ||
message: '登录失败', | ||
type: 'error', | ||
}) | ||
cb(false) | ||
} | ||
}).catch(e => { | ||
console.log(e) | ||
cb(false) | ||
}) | ||
// this.ctx.api_caller | ||
// .login(new LoginArg(id,pw),(r)=>{ | ||
// if(r.if_success==1){ | ||
// this.verified=true | ||
// this.ctx.app.showlogbtn=false | ||
// window.localStorage["panote_token"]=r.token | ||
|
||
// ElNotification({ | ||
// title: 'Success', | ||
// message: '登录成功', | ||
// type: 'success', | ||
// }) | ||
// cb(true) | ||
// }else{ | ||
// cb(false) | ||
// } | ||
// }) | ||
} | ||
constructor(private ctx:AppFuncTs.Context) { | ||
constructor(private ctx: AppFuncTs.Context) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use self::authority::AuthorityMan; | ||
use crate::gen_api::{ApiHandler, LoginReq, LoginResp, VerifyTokenReq, VerifyTokenResp}; | ||
use crate::*; | ||
|
||
mod authority; | ||
|
||
impl ApiHandler for Impl { | ||
fn handle_login(&self, req: LoginReq) -> LoginResp { | ||
let auth_man = AuthorityMan::new(); | ||
if let Ok(_) = auth_man.check_id_and_pw(&*(req.id), &*(req.pw)) { | ||
LoginResp::Succ { | ||
token: auth_man.gen_token(), | ||
} | ||
} else { | ||
LoginResp::Fail { msg: "".to_owned() } | ||
} | ||
} | ||
fn handle_verify_token(&self, req: VerifyTokenReq) -> VerifyTokenResp { | ||
let auth_man = AuthorityMan::new(); | ||
if auth_man.check_token(req.token).is_ok() { | ||
VerifyTokenResp::Succ { | ||
new_token: auth_man.gen_token(), | ||
} | ||
} else { | ||
VerifyTokenResp::Fail { msg: "".to_owned() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.