reomte change pw
This commit is contained in:
parent
405cb0c22a
commit
531152d821
@ -34,20 +34,36 @@ export function ProfilePage(){
|
|||||||
setNewpw("");
|
setNewpw("");
|
||||||
setNewpwch("");
|
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){
|
if(isElectronContent){
|
||||||
const elec = window['electron'] as any;
|
const elec = window['electron'] as any;
|
||||||
if(newpw == newpwch){
|
const success = elec.passwordReset(userctx.username,newpw);
|
||||||
const success = elec.passwordReset(userctx.username,newpw);
|
if(!success){
|
||||||
if(!success){
|
set_msg_dialog({opened:true,msg:"user not exist."});
|
||||||
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 (<Headline menu={menu}>
|
return (<Headline menu={menu}>
|
||||||
<Paper className={classes.paper}>
|
<Paper className={classes.paper}>
|
||||||
|
10
src/login.ts
10
src/login.ts
@ -260,6 +260,16 @@ export const resetPasswordMiddleware = (cntr: UserAccessor) =>
|
|||||||
ctx.body = {ok:true}
|
ctx.body = {ok:true}
|
||||||
ctx.type = 'json';
|
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) => {
|
export const getAdmin = async (cntr: UserAccessor) => {
|
||||||
const admin = await cntr.findUser("admin");
|
const admin = await cntr.findUser("admin");
|
||||||
if (admin === undefined) {
|
if (admin === undefined) {
|
||||||
|
@ -20,14 +20,14 @@ async function acquireZip(path: string) {
|
|||||||
const ret = await readZip(path);
|
const ret = await readZip(path);
|
||||||
if (ZipStreamCache[path] === undefined) {
|
if (ZipStreamCache[path] === undefined) {
|
||||||
ZipStreamCache[path] = [ret, 1];
|
ZipStreamCache[path] = [ret, 1];
|
||||||
console.log(`acquire ${path} 1`);
|
//console.log(`acquire ${path} 1`);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret.close();
|
ret.close();
|
||||||
}
|
}
|
||||||
const [ret, refCount] = ZipStreamCache[path];
|
const [ret, refCount] = ZipStreamCache[path];
|
||||||
ZipStreamCache[path] = [ret, refCount + 1];
|
ZipStreamCache[path] = [ret, refCount + 1];
|
||||||
console.log(`acquire ${path} ${refCount + 1}`);
|
//console.log(`acquire ${path} ${refCount + 1}`);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ function releaseZip(path: string) {
|
|||||||
const obj = ZipStreamCache[path];
|
const obj = ZipStreamCache[path];
|
||||||
if (obj === undefined) throw new Error("error! key invalid");
|
if (obj === undefined) throw new Error("error! key invalid");
|
||||||
const [ref, refCount] = obj;
|
const [ref, refCount] = obj;
|
||||||
console.log(`release ${path} : ${refCount}`);
|
//console.log(`release ${path} : ${refCount}`);
|
||||||
if (refCount === 1) {
|
if (refCount === 1) {
|
||||||
ref.close();
|
ref.close();
|
||||||
delete ZipStreamCache[path];
|
delete ZipStreamCache[path];
|
||||||
@ -46,7 +46,7 @@ function releaseZip(path: string) {
|
|||||||
|
|
||||||
async function renderZipImage(ctx: Context, path: string, page: number) {
|
async function renderZipImage(ctx: Context, path: string, page: number) {
|
||||||
const image_ext = ["gif", "png", "jpeg", "bmp", "webp", "jpg"];
|
const image_ext = ["gif", "png", "jpeg", "bmp", "webp", "jpg"];
|
||||||
console.log(`opened ${page}`);
|
//console.log(`opened ${page}`);
|
||||||
let zip = await acquireZip(path);
|
let zip = await acquireZip(path);
|
||||||
const entries = entriesByNaturalOrder(zip).filter((x) => {
|
const entries = entriesByNaturalOrder(zip).filter((x) => {
|
||||||
const ext = x.name.split(".").pop();
|
const ext = x.name.split(".").pop();
|
||||||
|
@ -10,7 +10,7 @@ import getContentRouter from './route/contents';
|
|||||||
import { createKnexDocumentAccessor, createKnexUserController } from './db/mod';
|
import { createKnexDocumentAccessor, createKnexUserController } from './db/mod';
|
||||||
import bodyparser from 'koa-bodyparser';
|
import bodyparser from 'koa-bodyparser';
|
||||||
import {error_handler} from './route/error_handler';
|
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 {createInterface as createReadlineInterface} from 'readline';
|
||||||
import { DocumentAccessor, UserAccessor } from './model/mod';
|
import { DocumentAccessor, UserAccessor } from './model/mod';
|
||||||
@ -62,10 +62,10 @@ class ServerApplication{
|
|||||||
const content_router = getContentRouter(this.documentController);
|
const content_router = getContentRouter(this.documentController);
|
||||||
router.use('/api/doc',content_router.routes());
|
router.use('/api/doc',content_router.routes());
|
||||||
router.use('/api/doc',content_router.allowedMethods());
|
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"){
|
if(setting.mode == "development"){
|
||||||
let mm_count = 0;
|
let mm_count = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user