From 531152d8212557e82d42b591c82a61c780e9530a Mon Sep 17 00:00:00 2001 From: monoid Date: Sun, 7 Feb 2021 02:01:37 +0900 Subject: [PATCH] reomte change pw --- src/client/page/profile.tsx | 36 ++++++++++++++++++++++++++---------- src/login.ts | 10 ++++++++++ src/route/manga.ts | 8 ++++---- src/server.ts | 10 +++++----- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/client/page/profile.tsx b/src/client/page/profile.tsx index b9fa9bb..3b03f6f 100644 --- a/src/client/page/profile.tsx +++ b/src/client/page/profile.tsx @@ -34,20 +34,36 @@ 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."}); - } + 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."}); - } - handle_close(); } + else{ + 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 ( diff --git a/src/login.ts b/src/login.ts index 2f3dce6..e662231 100644 --- a/src/login.ts +++ b/src/login.ts @@ -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) { diff --git a/src/route/manga.ts b/src/route/manga.ts index 8515a7f..04117e4 100644 --- a/src/route/manga.ts +++ b/src/route/manga.ts @@ -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(); diff --git a/src/server.ts b/src/server.ts index 4bc12f3..a9d95fb 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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()); - - router.post('/user/login',createLoginMiddleware(this.userController)); - router.post('/user/logout',LogoutMiddleware); - router.post('/user/refresh',createRefreshTokenMiddleware(this.userController)); + const login_router = createLoginRouter(this.userController); + router.use('/user',login_router.routes()); + router.use('/user',login_router.allowedMethods()); + if(setting.mode == "development"){ let mm_count = 0;