@yongdall/authenticator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/style.css +13 -0
- package/assets/style.css.map +1 -0
- package/assets/style.mjs +0 -0
- package/assets/web.mjs +2 -0
- package/assets/web.mjs.map +1 -0
- package/assets.yongdall.mjs +4 -0
- package/hooks.yongdall.mjs +9 -0
- package/hooks.yongdall.mjs.map +1 -0
- package/package.json +19 -0
- package/routers.yongdall.mjs +57 -0
- package/routers.yongdall.mjs.map +1 -0
package/assets/style.css
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.yongdall-authenticator {
|
|
2
|
+
max-inline-size: 300px;
|
|
3
|
+
margin: auto;
|
|
4
|
+
padding-block-start: 50px;
|
|
5
|
+
}
|
|
6
|
+
.yongdall-authenticator > .NeeloongForm {
|
|
7
|
+
background-color: var(--color-canvas);
|
|
8
|
+
border-radius: var(--border-radius);
|
|
9
|
+
margin-inline: 8px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/*# sourceMappingURL=style.css.map*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.css","names":[],"sources":["../../../packages/authenticator/style.css"],"sourcesContent":[".yongdall-authenticator {\n\tmax-inline-size: 300px;\n\tmargin: auto;\n\tpadding-block-start: 50px;\n}\n.yongdall-authenticator > .NeeloongForm {\n\tbackground-color: var(--color-canvas);\n\tborder-radius: var(--border-radius);\n\tmargin-inline: 8px;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/assets/style.mjs
ADDED
|
File without changes
|
package/assets/web.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Store as e,createStoreField as t,renderStore as n}from"@yongdall/web";import r from"@yongdall/web/plugin";const i=[/[a-z]/,/[A-Z]/,/[0-9]/,/[~!@#$%^&*()_+{}|<>?,./:";'\\\[\]-]/];function*a(e){e.length<8&&(yield`密码不足 8 位`),i.filter(t=>t.test(e)).length<3&&(yield`密码至少包含小写字母、大写字母、数字、符号中的 3 种`),e.toLowerCase().includes(`admin`)&&(yield`密码不能包含admin`),[...e].find((e,t,n)=>n[t-1]===e&&n[t+1]===e)&&(yield`密码不能包含三位以上的相同的字母或数字`),[...e].find((e,t,n)=>{let r=n[t-1],i=n[t+1];if(!r||!i)return!1;let a=r.charCodeAt(0),o=e.charCodeAt(0),s=i.charCodeAt(0),c=a-o,l=o-s;if(c===l&&(l===1||l===-1))return!0})&&(yield`密码不能包含三位以上的连续的字母或数字`)}const o={resetPassword:{type:`bool`},username:{type:`string`,label:`用户名`,validators:{blur(e){let t=e.value;if(!t||typeof t!=`string`)return`请填写用户名`}}},password:{type:`password`,label:`密码`,validators:{blur(e){let t=e.value;if(!t||typeof t!=`string`)return`请填写密码`}}},newPassword:{type:{password1:{type:`password`,label:`新密码`,validator:e=>{if(!e.root.child(`resetPassword`)?.value)return;let t=e.value;return!t||typeof t!=`string`?`请填写新密码`:[...a(t)]}},password2:{type:`password`,label:`重复密码`,validator:e=>{if(!e.root.child(`resetPassword`)?.value)return;let t=e.value;if(!t)return`请填写重复密码`;if(t!==e.parent?.child(`password1`)?.value)return`重复密码与新密码不一致`}}},label:`重置密码`,hidden:e=>!e.root.child(`resetPassword`)?.value}},s={fields:[{field:`username`},{field:`password`},{field:`newPassword`,fields:[{field:`password1`},{field:`password2`}]}]};function c(i,a){let c=document.createElement(`form`),l=c.appendChild(document.createElement(`h2`));l.textContent=`用户登录`,c.appendChild(l);let u=e.create(o);if(u.reset(),i.aborted)return null;let d=n(u,(e,n)=>t(e,{},n),c,s,{editable:!0});i.addEventListener(`abort`,d,{once:!0});let f=c.appendChild(document.createElement(`button`));return f.type=`submit`,f.textContent=`登录`,c.addEventListener(`submit`,async e=>{if(e.preventDefault(),!f.disabled)try{f.disabled=!0;let{username:e,password:t,resetPassword:n,newPassword:{password1:i}}=u.value;if((await u.validate())?.length)return;let o=await r.request.clone().put().body({login:e,password:t,newPassword:n&&i||``}).result();if(!o||typeof o==`object`){a();return}if(o===408){let e=u.child(`resetPassword`);e&&(e.value=!0);return}if(o===404){alert(`用户名错误`);let e=u.child(`resetPassword`);e&&(e.value=!1);return}if(o===403){alert(`用户名或密码错误`);let e=u.child(`resetPassword`);e&&(e.value=!1);return}}catch(e){e instanceof Response&&(e.status===404?alert(`用户名错误`):e.status===403?alert(`密码错误`):e.status)}finally{f.disabled=!1}}),c}const l=document.createElement(`div`);l.classList.add(`yongdall-authenticator`);const u={styleFiles:[`style.css`],classNames:[],elements:l,async login(e){let{promise:t,resolve:n}=Promise.withResolvers(),r=new Promise(t=>{if(e.aborted){t();return}e.addEventListener(`abort`,()=>t(),{once:!0})}),i=c(e,n);i&&(l.appendChild(i),await Promise.race([t,r]).finally(()=>{i.remove()}))}};export{u as authenticator};
|
|
2
|
+
//# sourceMappingURL=web.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.mjs","names":[],"sources":["../../../packages/authenticator/verifyNewPassword.mjs","../../../packages/authenticator/createLogin.mjs","../../../packages/authenticator/web.mjs"],"sourcesContent":["const signTypeRegex = [\n\t/[a-z]/,\n\t/[A-Z]/,\n\t/[0-9]/,\n\t/[~!@#$%^&*()_+{}|<>?,./:\";'\\\\\\[\\]-]/,\n]\n/**\n * \n * @param {string} password \n */\nexport function* verifyNewPassword(password) {\n\tif (password.length < 8) { yield '密码不足 8 位'; }\n\t\n\tif (signTypeRegex.filter(r => r.test(password)).length < 3) {\n\t\tyield `密码至少包含小写字母、大写字母、数字、符号中的 3 种`;\n\t}\n\tif (password.toLowerCase().includes('admin')) {\n\t\tyield `密码不能包含admin`;\n\t}\n\tif ([...password].find((a,index, list) => list[index - 1] === a && list[index + 1] === a)) {\n\t\tyield `密码不能包含三位以上的相同的字母或数字`;\n\t}\n\tif ([...password].find((a,index, list) => {\n\t\tconst p = list[index - 1];\n\t\tconst n = list[index + 1];\n\t\tif (!p || !n) { return false; }\n\t\tconst x = p.charCodeAt(0);\n\t\tconst y = a.charCodeAt(0);\n\t\tconst z = n.charCodeAt(0);\n\t\tconst u = x - y;\n\t\tconst v = y - z;\n\t\tif (u === v && (v === 1 || v === -1)) { return true}\n\t})) {\n\t\tyield `密码不能包含三位以上的连续的字母或数字`;\n\t}\n}\n","/** @import { Schema, StoreLayout } from '@yongdall/web' */\n\nimport { createStoreField, renderStore, Store } from '@yongdall/web';\nimport Plugin from '@yongdall/web/plugin';\nimport { verifyNewPassword } from './verifyNewPassword.mjs';\n\n/** @type {Schema} */\nconst schema = {\n\tresetPassword: { type: 'bool' },\n\tusername: {\n\t\ttype: 'string', label: '用户名', validators: {\n\t\t\tblur(store) {\n\t\t\t\tconst value = store.value;\n\t\t\t\tif (!value || typeof value !== 'string') { return '请填写用户名'; }\n\t\t\t},\n\t\t}\n\t},\n\n\tpassword: {\n\t\ttype: 'password', label: '密码',\n\t\tvalidators: {\n\t\t\tblur(store) {\n\t\t\t\tconst value = store.value;\n\t\t\t\tif (!value || typeof value !== 'string') { return '请填写密码'; }\n\t\t\t},\n\t\t}\n\t},\n\tnewPassword: {\n\t\ttype: {\n\t\t\tpassword1: {\n\t\t\t\ttype: 'password', label: '新密码',\n\t\t\t\tvalidator: store => {\n\t\t\t\t\tif (!store.root.child('resetPassword')?.value) { return; }\n\t\t\t\t\tconst value = store.value;\n\t\t\t\t\tif (!value || typeof value !== 'string') { return '请填写新密码'; }\n\n\t\t\t\t\treturn [...verifyNewPassword(value)];\n\t\t\t\t},\n\t\t\t},\n\t\t\tpassword2: {\n\t\t\t\ttype: 'password', label: '重复密码',\n\t\t\t\tvalidator: store => {\n\t\t\t\t\tif (!store.root.child('resetPassword')?.value) { return; }\n\t\t\t\t\tconst value = store.value;\n\t\t\t\t\tif (!value) { return '请填写重复密码'; }\n\t\t\t\t\tif (value !== store.parent?.child('password1')?.value) {\n\t\t\t\t\t\treturn '重复密码与新密码不一致';\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t}, label: '重置密码', hidden: s => !s.root.child('resetPassword')?.value\n\t}\n};\n\n/** @type {StoreLayout} */\nconst StoreLayout = {\n\tfields: [\n\t\t{ field: 'username' },\n\t\t{ field: 'password' },\n\t\t{\n\t\t\tfield: 'newPassword',\n\t\t\tfields: [\n\t\t\t\t{ field: 'password1' },\n\t\t\t\t{ field: 'password2' },\n\t\t\t],\n\t\t},\n\t],\n};\n/**\n * \n * @param {AbortSignal} signal \n * @param {() => void} resolve \n */\nexport default function createLogin(signal, resolve) {\n\t// 创建表单\n\tconst form = document.createElement('form');\n\tconst title = form.appendChild(document.createElement('h2'));\n\ttitle.textContent = '用户登录';\n\tform.appendChild(title);\n\tconst store = Store.create(schema);\n\tstore.reset();\n\tif (signal.aborted) {\n\t\treturn null;\n\t}\n\n\n\tconst destroy = renderStore(\n\t\tstore,\n\t\t(store, options) => createStoreField(store, {}, options),\n\t\tform,\n\t\tStoreLayout,\n\t\t{ editable: true },\n\t);\n\tsignal.addEventListener('abort', destroy, { once: true });\n\n\t// 创建提交按钮\n\tconst submitButton = form.appendChild(document.createElement('button'));\n\tsubmitButton.type = 'submit';\n\tsubmitButton.textContent = '登录';\n\n\t// 添加事件监听器\n\tform.addEventListener('submit', async event => {\n\t\tevent.preventDefault();\n\t\tif (submitButton.disabled) { return; }\n\t\ttry {\n\t\t\tsubmitButton.disabled = true;\n\t\t\tconst { username, password, resetPassword, newPassword: { password1: newPassword } } = store.value;\n\t\t\tconst r = await store.validate();\n\t\t\tif (r?.length) { return; }\n\t\t\tconst result = await Plugin.request.clone().put().body({\n\t\t\t\tlogin: username, password, newPassword: resetPassword && newPassword || '',\n\t\t\t}).result();\n\t\t\tif (!result || typeof result === 'object') {\n\t\t\t\tresolve();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (result === 408) {\n\t\t\t\tconst resetPassword = store.child('resetPassword');\n\t\t\t\tif (resetPassword) { resetPassword.value = true; }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (result === 404) {\n\t\t\t\talert('用户名错误');\n\t\t\t\tconst resetPassword = store.child('resetPassword');\n\t\t\t\tif (resetPassword) { resetPassword.value = false; }\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (result === 403) {\n\t\t\t\talert('用户名或密码错误');\n\t\t\t\tconst resetPassword = store.child('resetPassword');\n\t\t\t\tif (resetPassword) { resetPassword.value = false; }\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t} catch (e) {\n\t\t\tif (e instanceof Response) {\n\t\t\t\tif (e.status === 404) {\n\t\t\t\t\talert('用户名错误');\n\t\t\t\t} else if (e.status === 403) {\n\t\t\t\t\talert('密码错误');\n\t\t\t\t} else if (e.status === 408) {\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tsubmitButton.disabled = false;\n\t\t}\n\t});\n\n\treturn form;\n}\n","/** @import {Authenticator} from '@yongdall/web' */\nimport createLogin from './createLogin.mjs';\n\nconst root = document.createElement('div');\nroot.classList.add('yongdall-authenticator');\n\n/**@type {Partial<Authenticator>} */\nexport const authenticator = {\n\tstyleFiles: ['style.css'],\n\tclassNames: [],\n\telements: root,\n\tasync login(signal) {\n\t\t/** @type {PromiseWithResolvers<void>} */\n\t\tconst { promise, resolve } = Promise.withResolvers();\n\t\t/*** @type {Promise<void>} */\n\t\tconst signalPromise = new Promise(r => {\n\t\t\tif (signal.aborted) { r(); return; }\n\t\t\tsignal.addEventListener('abort', () => r(), { once: true });\n\t\t});\n\t\tconst form = createLogin(signal, resolve);\n\t\tif (!form) { return; }\n\t\troot.appendChild(form);\n\t\tawait Promise.race([promise, signalPromise])\n\t\t\t.finally(() => { form.remove(); });\n\t},\n};\n"],"mappings":"iHAAA,MAAM,EAAgB,CACrB,QACA,QACA,QACA,sCACA,CAKD,SAAiB,EAAkB,EAAU,CACxC,EAAS,OAAS,IAAK,KAAM,YAE7B,EAAc,OAAO,GAAK,EAAE,KAAK,EAAS,CAAC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Ae,GACxE,CAAC,CAAC,QAAQ,CACX,GAAI,CAAC,GAAU,OAAO,GAAW,SAAU,CAC1C,GAAS,CACT,OAED,GAAI,IAAW,IAAK,CACnB,IAAM,EAAgB,EAAM,MAAM,gBAAgB,CAC9C,IAAiB,EAAc,MAAQ,IAC3C,OAED,GAAI,IAAW,IAAK,CACnB,MAAM,QAAQ,CACd,IAAM,EAAgB,EAAM,MAAM,gBAAgB,CAC9C,IAAiB,EAAc,MAAQ,IAC3C,OAED,GAAI,IAAW,IAAK,CACnB,MAAM,WAAW,CACjB,IAAM,EAAgB,EAAM,MAAM,gBAAgB,CAC9C,IAAiB,EAAc,MAAQ,IAC3C,cAGO,EAAG,CACP,aAAa,WACZ,EAAE,SAAW,IAChB,MAAM,QAAQ,CACJ,EAAE,SAAW,IACvB,MAAM,OAAO,CACH,EAAE,eAGL,CACT,EAAa,SAAW,KAExB,CAEK,ECjJR,MAAM,EAAO,SAAS,cAAc,MAAM,CAC1C,EAAK,UAAU,IAAI,yBAAyB,CAG5C,MAAa,EAAgB,CAC5B,WAAY,CAAC,YAAY,CACzB,WAAY,EAAE,CACd,SAAU,EACV,MAAM,MAAM,EAAQ,CAEnB,GAAM,CAAE,UAAS,WAAY,QAAQ,eAAe,CAE9C,EAAgB,IAAI,QAAQ,GAAK,CACtC,GAAI,EAAO,QAAS,CAAE,GAAG,CAAE,OAC3B,EAAO,iBAAiB,YAAe,GAAG,CAAE,CAAE,KAAM,GAAM,CAAC,EAC1D,CACI,EAAO,EAAY,EAAQ,EAAQ,CACpC,IACL,EAAK,YAAY,EAAK,CACtB,MAAM,QAAQ,KAAK,CAAC,EAAS,EAAc,CAAC,CAC1C,YAAc,CAAE,EAAK,QAAQ,EAAI,GAEpC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region packages/authenticator/hooks.yongdall.mjs
|
|
2
|
+
const enumerations = { authenticator: [{
|
|
3
|
+
authenticator: "@yongdall/authenticator#authenticator",
|
|
4
|
+
label: "基础登录器"
|
|
5
|
+
}] };
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { enumerations };
|
|
9
|
+
//# sourceMappingURL=hooks.yongdall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.yongdall.mjs","names":[],"sources":["../../packages/authenticator/hooks.yongdall.mjs"],"sourcesContent":["export const enumerations = {\n\tauthenticator: [\n\t\t{ authenticator: '@yongdall/authenticator#authenticator', label: '基础登录器' },\n\t]\n};\n"],"mappings":";AAAA,MAAa,eAAe,EAC3B,eAAe,CACd;CAAE,eAAe;CAAyC,OAAO;CAAS,CAC1E,EACD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yongdall/authenticator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": "./assets/web.mjs"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@yongdall/http": "^0.1.0",
|
|
9
|
+
"@yongdall/core": "^0.1.0"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@yongdall/web": "^0.1.0"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@yongdall/web": "^0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"main": "./assets/web.mjs",
|
|
18
|
+
"type": "module"
|
|
19
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ApiRouter, useBody } from "@yongdall/http";
|
|
2
|
+
import { existUser, findUser, loadUser, setUser, setUserVerify, verifyUser } from "@yongdall/core";
|
|
3
|
+
|
|
4
|
+
//#region packages/authenticator/verifyNewPassword.mjs
|
|
5
|
+
const signTypeRegex = [
|
|
6
|
+
/[a-z]/,
|
|
7
|
+
/[A-Z]/,
|
|
8
|
+
/[0-9]/,
|
|
9
|
+
/[~!@#$%^&*()_+{}|<>?,./:";'\\\[\]-]/
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {string} password
|
|
14
|
+
*/
|
|
15
|
+
function* verifyNewPassword(password) {
|
|
16
|
+
if (password.length < 8) yield "密码不足 8 位";
|
|
17
|
+
if (signTypeRegex.filter((r) => r.test(password)).length < 3) yield `密码至少包含小写字母、大写字母、数字、符号中的 3 种`;
|
|
18
|
+
if (password.toLowerCase().includes("admin")) yield `密码不能包含admin`;
|
|
19
|
+
if ([...password].find((a, index, list) => list[index - 1] === a && list[index + 1] === a)) yield `密码不能包含三位以上的相同的字母或数字`;
|
|
20
|
+
if ([...password].find((a, index, list) => {
|
|
21
|
+
const p = list[index - 1];
|
|
22
|
+
const n = list[index + 1];
|
|
23
|
+
if (!p || !n) return false;
|
|
24
|
+
const x = p.charCodeAt(0);
|
|
25
|
+
const y = a.charCodeAt(0);
|
|
26
|
+
const z = n.charCodeAt(0);
|
|
27
|
+
const u = x - y;
|
|
28
|
+
const v = y - z;
|
|
29
|
+
if (u === v && (v === 1 || v === -1)) return true;
|
|
30
|
+
})) yield `密码不能包含三位以上的连续的字母或数字`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region packages/authenticator/routers.yongdall.mjs
|
|
35
|
+
const plugin = new ApiRouter();
|
|
36
|
+
plugin.put(async (ctx) => {
|
|
37
|
+
const { login, password, newPassword } = await useBody() || {};
|
|
38
|
+
if (!login || typeof login !== "string") return 404;
|
|
39
|
+
if (!password || typeof password !== "string") return 404;
|
|
40
|
+
const userId = await findUser(login);
|
|
41
|
+
if (!userId) return 404;
|
|
42
|
+
if (!await existUser(userId)) return 404;
|
|
43
|
+
const result = await verifyUser(userId, password, "password");
|
|
44
|
+
if (!result) return 403;
|
|
45
|
+
if (result === 2) {
|
|
46
|
+
if (newPassword === password) return 408;
|
|
47
|
+
if (!newPassword || typeof newPassword !== "string") return 408;
|
|
48
|
+
if ([...verifyNewPassword(newPassword)].length) return 408;
|
|
49
|
+
await setUserVerify(userId, "password", newPassword);
|
|
50
|
+
}
|
|
51
|
+
await setUser(userId);
|
|
52
|
+
return loadUser(userId, true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { plugin };
|
|
57
|
+
//# sourceMappingURL=routers.yongdall.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routers.yongdall.mjs","names":[],"sources":["../../packages/authenticator/verifyNewPassword.mjs","../../packages/authenticator/routers.yongdall.mjs"],"sourcesContent":["const signTypeRegex = [\n\t/[a-z]/,\n\t/[A-Z]/,\n\t/[0-9]/,\n\t/[~!@#$%^&*()_+{}|<>?,./:\";'\\\\\\[\\]-]/,\n]\n/**\n * \n * @param {string} password \n */\nexport function* verifyNewPassword(password) {\n\tif (password.length < 8) { yield '密码不足 8 位'; }\n\t\n\tif (signTypeRegex.filter(r => r.test(password)).length < 3) {\n\t\tyield `密码至少包含小写字母、大写字母、数字、符号中的 3 种`;\n\t}\n\tif (password.toLowerCase().includes('admin')) {\n\t\tyield `密码不能包含admin`;\n\t}\n\tif ([...password].find((a,index, list) => list[index - 1] === a && list[index + 1] === a)) {\n\t\tyield `密码不能包含三位以上的相同的字母或数字`;\n\t}\n\tif ([...password].find((a,index, list) => {\n\t\tconst p = list[index - 1];\n\t\tconst n = list[index + 1];\n\t\tif (!p || !n) { return false; }\n\t\tconst x = p.charCodeAt(0);\n\t\tconst y = a.charCodeAt(0);\n\t\tconst z = n.charCodeAt(0);\n\t\tconst u = x - y;\n\t\tconst v = y - z;\n\t\tif (u === v && (v === 1 || v === -1)) { return true}\n\t})) {\n\t\tyield `密码不能包含三位以上的连续的字母或数字`;\n\t}\n}\n","import { ApiRouter, useBody } from '@yongdall/http';\nimport { existUser, findUser, loadUser, setUser, setUserVerify, verifyUser } from '@yongdall/core';\nimport { verifyNewPassword } from './verifyNewPassword.mjs';\n\nexport const plugin = new ApiRouter();\n\nplugin.put(async ctx => {\n\tconst {login, password, newPassword} = await useBody() || {};\n\tif (!login || typeof login !== 'string') { return 404; }\n\tif (!password || typeof password !== 'string') { return 404; }\n\tconst userId = await findUser(login);\n\tif (!userId) { return 404; }\n\tif (!await existUser(userId)) { return 404; }\n\tconst result = await verifyUser(userId, password, 'password');\n\tif (!result) { return 403; }\n\tif (result === 2) {\n\t\tif (newPassword === password) { return 408; }\n\t\tif (!newPassword || typeof newPassword !== 'string') { return 408; }\n\t\tif ([...verifyNewPassword(newPassword)].length) { return 408; }\n\t\tawait setUserVerify(userId, 'password', newPassword);\n\t}\n\tawait setUser(userId);\n\treturn loadUser(userId, true);\n});\n"],"mappings":";;;;AAAA,MAAM,gBAAgB;CACrB;CACA;CACA;CACA;CACA;;;;;AAKD,UAAiB,kBAAkB,UAAU;AAC5C,KAAI,SAAS,SAAS,EAAK,OAAM;AAEjC,KAAI,cAAc,QAAO,MAAK,EAAE,KAAK,SAAS,CAAC,CAAC,SAAS,EACxD,OAAM;AAEP,KAAI,SAAS,aAAa,CAAC,SAAS,QAAQ,CAC3C,OAAM;AAEP,KAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAE,OAAO,SAAS,KAAK,QAAQ,OAAO,KAAK,KAAK,QAAQ,OAAO,EAAE,CACxF,OAAM;AAEP,KAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAE,OAAO,SAAS;EACzC,MAAM,IAAI,KAAK,QAAQ;EACvB,MAAM,IAAI,KAAK,QAAQ;AACvB,MAAI,CAAC,KAAK,CAAC,EAAK,QAAO;EACvB,MAAM,IAAI,EAAE,WAAW,EAAE;EACzB,MAAM,IAAI,EAAE,WAAW,EAAE;EACzB,MAAM,IAAI,EAAE,WAAW,EAAE;EACzB,MAAM,IAAI,IAAI;EACd,MAAM,IAAI,IAAI;AACd,MAAI,MAAM,MAAM,MAAM,KAAK,MAAM,IAAO,QAAO;GAC9C,CACD,OAAM;;;;;AC7BR,MAAa,SAAS,IAAI,WAAW;AAErC,OAAO,IAAI,OAAM,Q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