reomte change pw

This commit is contained in:
monoid 2021-02-07 02:01:37 +09:00
parent 405cb0c22a
commit 531152d821
4 changed files with 45 additions and 19 deletions

View File

@ -34,21 +34,37 @@ export function ProfilePage(){
setNewpw("");
setNewpwch("");
};
const handle_ok= ()=>{
const handle_ok= async ()=>{
if(newpw != newpwch){
set_msg_dialog({opened:true,msg:"password and password check is not equal."});
handle_close();
return;
}
if(isElectronContent){
const elec = window['electron'] as any;
if(newpw == newpwch){
const success = elec.passwordReset(userctx.username,newpw);
if(!success){
set_msg_dialog({opened:true,msg:"user not exist."});
}
}
else{
set_msg_dialog({opened:true,msg:"password and password check is not equal."});
const res = await fetch("/user/reset",{
method: 'POST',
body:JSON.stringify({
username:userctx.username,
oldpassword:oldpw,
newpassword:newpw,
}),
headers:{
"content-type":"application/json"
}
});
if(res.status != 200){
set_msg_dialog({opened:true,msg:"failed to change password."});
}
}
handle_close();
}
}
return (<Headline menu={menu}>
<Paper className={classes.paper}>
<Grid container direction="column" alignItems="center">

View File

@ -260,6 +260,16 @@ export const resetPasswordMiddleware = (cntr: UserAccessor) =>
ctx.body = {ok:true}
ctx.type = 'json';
}
export function createLoginRouter(userController: UserAccessor){
let router = new Router();
router.post('/login',createLoginMiddleware(userController));
router.post('/logout',LogoutMiddleware);
router.post('/refresh',createRefreshTokenMiddleware(userController));
router.post('/reset', resetPasswordMiddleware(userController));
return router;
}
export const getAdmin = async (cntr: UserAccessor) => {
const admin = await cntr.findUser("admin");
if (admin === undefined) {

View File

@ -20,14 +20,14 @@ async function acquireZip(path: string) {
const ret = await readZip(path);
if (ZipStreamCache[path] === undefined) {
ZipStreamCache[path] = [ret, 1];
console.log(`acquire ${path} 1`);
//console.log(`acquire ${path} 1`);
return ret;
}
ret.close();
}
const [ret, refCount] = ZipStreamCache[path];
ZipStreamCache[path] = [ret, refCount + 1];
console.log(`acquire ${path} ${refCount + 1}`);
//console.log(`acquire ${path} ${refCount + 1}`);
return ret;
}
@ -35,7 +35,7 @@ function releaseZip(path: string) {
const obj = ZipStreamCache[path];
if (obj === undefined) throw new Error("error! key invalid");
const [ref, refCount] = obj;
console.log(`release ${path} : ${refCount}`);
//console.log(`release ${path} : ${refCount}`);
if (refCount === 1) {
ref.close();
delete ZipStreamCache[path];
@ -46,7 +46,7 @@ function releaseZip(path: string) {
async function renderZipImage(ctx: Context, path: string, page: number) {
const image_ext = ["gif", "png", "jpeg", "bmp", "webp", "jpg"];
console.log(`opened ${page}`);
//console.log(`opened ${page}`);
let zip = await acquireZip(path);
const entries = entriesByNaturalOrder(zip).filter((x) => {
const ext = x.name.split(".").pop();

View File

@ -10,7 +10,7 @@ import getContentRouter from './route/contents';
import { createKnexDocumentAccessor, createKnexUserController } from './db/mod';
import bodyparser from 'koa-bodyparser';
import {error_handler} from './route/error_handler';
import {createUserMiddleWare,createLoginMiddleware, isAdminFirst, getAdmin, LogoutMiddleware, createRefreshTokenMiddleware} from './login';
import {createUserMiddleWare, createLoginRouter, isAdminFirst, getAdmin} from './login';
import {createInterface as createReadlineInterface} from 'readline';
import { DocumentAccessor, UserAccessor } from './model/mod';
@ -62,10 +62,10 @@ class ServerApplication{
const content_router = getContentRouter(this.documentController);
router.use('/api/doc',content_router.routes());
router.use('/api/doc',content_router.allowedMethods());
const login_router = createLoginRouter(this.userController);
router.use('/user',login_router.routes());
router.use('/user',login_router.allowedMethods());
router.post('/user/login',createLoginMiddleware(this.userController));
router.post('/user/logout',LogoutMiddleware);
router.post('/user/refresh',createRefreshTokenMiddleware(this.userController));
if(setting.mode == "development"){
let mm_count = 0;