@yongdall/user 0.1.1 → 0.1.4
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/index.mjs +1 -1
- package/assets/index.mjs.map +1 -1
- package/index.d.mts +17 -17
- package/package.json +1 -1
- package/routers.yongdall.mjs +2 -2
- package/routers.yongdall.mjs.map +1 -1
package/assets/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Store as e,
|
|
1
|
+
import{Store as e,renderStoreForm as t,single as n}from"@yongdall/web";import r from"@yongdall/web/plugin";var i=Object.defineProperty,a=(e,t)=>{let n={};for(var r in e)i(n,r,{get:e[r],enumerable:!0});return t||i(n,Symbol.toStringTag,{value:`Module`}),n};const o=[/[a-z]/,/[A-Z]/,/[0-9]/,/[~!@#$%^&*()_+{}|<>?,./:";'\\\[\]-]/];function*s(e){e.length<8&&(yield`密码不足 8 位`),o.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`密码不能包含三位以上的连续的字母或数字`)}var c=a({user:()=>d});const l={password:{type:`string`,label:`您的密码`,component:`password`,hidden:n,validators:{blur(e){if(n)return;let t=e.value;if(!t||typeof t!=`string`)return`请填写您的密码`}}},newPassword1:{type:`string`,label:`新密码`,component:`password`,validators:{blur(e){let t=e.value;return!t||typeof t!=`string`?`请填写新密码`:[...s(t)]}}},newPassword2:{type:`string`,label:`重复密码`,component:`password`,validators:{blur(e){let t=e.value;if(!t)return`请填写重复密码`;if(t!==e.parent?.child(`newPassword1`)?.value)return`重复密码与新密码不一致`}}}},u={fields:[{field:`password`},{field:`newPassword1`},{field:`newPassword2`}]},d={documentScripts:{setPassword(n){let i=n.document?.id;if(!i)return;let a=document.createElement(`dialog`),o=document.createElement(`form`),s=o.appendChild(document.createElement(`h2`));s.textContent=`设置用户密码`,a.appendChild(o);let c=new AbortController;a.addEventListener(`close`,()=>{a.remove(),c.abort()});let d=e.create(l);d.reset(),t(d,o,{editable:!0,layout:u,signal:c.signal});let f=o.appendChild(document.createElement(`button`));f.type=`submit`,f.textContent=`修改密码`,o.addEventListener(`submit`,async e=>{if(e.preventDefault(),!f.disabled)try{f.disabled=!0;let{password:e,newPassword1:t}=d.value;if((await d.validate())?.length)return;let n=await r.request.clone().put(`password`).body({userId:i,password:e,newPassword:t}).result();if(!n||n===200||typeof n==`object`){a.close(),alert(`密码修改完成`);return}if(n===404){alert(`新旧密码不能相同`);return}if(n===403){alert(`密码错误`);return}if(n===400){alert(`不能修改自己的密码`);return}if(n===402){alert(`您无操作权限`);return}}catch(e){e instanceof Response&&e.status===403&&alert(`密码错误`)}finally{f.disabled=!1}}),document.body.appendChild(a),a.showModal()}}},f={password:{type:`string`,label:`当前密码`,component:`password`,validators:{blur(e){let t=e.value;if(!t||typeof t!=`string`)return`请填写密码`}}},newPassword1:{type:`string`,label:`新密码`,component:`password`,validators:{blur(e){let t=e.value;return!t||typeof t!=`string`?`请填写新密码`:[...s(t)]}}},newPassword2:{type:`string`,label:`重复密码`,component:`password`,validators:{blur(e){let t=e.value;if(!t)return`请填写重复密码`;if(t!==e.parent?.child(`newPassword1`)?.value)return`重复密码与新密码不一致`}}}},p={fields:[{field:`password`},{field:`newPassword1`},{field:`newPassword2`}]};function m(n){n.loading=!1,n.panel=!0,n.title=`修改密码`;let i=n.container;i.style.margin=`auto`,i.style.maxInlineSize=`300px`;let a=document.createElement(`form`),o=a.appendChild(document.createElement(`h2`));o.textContent=`修改密码`,i.appendChild(a);let s=e.create(f);if(s.reset(),n.signal.aborted)return null;t(s,a,{editable:!0,layout:p,signal:n.signal});let c=a.appendChild(document.createElement(`button`));c.type=`submit`,c.textContent=`修改密码`,a.addEventListener(`submit`,async e=>{if(e.preventDefault(),!c.disabled)try{c.disabled=!0;let{password:e,newPassword1:t}=s.value;if((await s.validate())?.length)return;let n=await r.request.clone().put(`password`).body({password:e,newPassword:t}).result();if(!n||n===200||typeof n==`object`){s.reset(),alert(`密码修改完成`);return}if(n===403){alert(`密码错误`);return}}catch(e){e instanceof Response&&e.status===403&&alert(`密码错误`)}finally{c.disabled=!1}})}export{c as models,m as password,s as verifyNewPassword};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/assets/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["schema","StoreLayout"],"sources":["../../../plugins/user/common/verifyNewPassword.mjs","../../../plugins/user/assets/models.mjs","../../../plugins/user/assets/password.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 { ModelScript } from '@yongdall/web' */\n/** @import { Schema, StoreLayout } from '@yongdall/web' */\n\nimport { createStoreField, renderStore, single, Store } from '@yongdall/web';\nimport Plugin from '@yongdall/web/plugin';\nimport { verifyNewPassword } from './common/verifyNewPassword.mjs';\n\n/** @type {Schema} */\nconst schema = {\n\n\tpassword: {\n\t\ttype: 'password', label: '您的密码',\n\t\thidden: single,\n\t\tvalidators: {\n\t\t\tblur(store) {\n\t\t\t\tif (single) { return; }\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\tnewPassword1: {\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\treturn [...verifyNewPassword(value)];\n\t\t\t},\n\t\t},\n\t},\n\tnewPassword2: {\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) { return '请填写重复密码'; }\n\t\t\t\tif (value !== store.parent?.child('newPassword1')?.value) {\n\t\t\t\t\treturn '重复密码与新密码不一致';\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t},\n};\n\n/** @type {StoreLayout} */\nconst StoreLayout = {\n\tfields: [\n\t\t{ field: 'password' },\n\t\t{ field: 'newPassword1' },\n\t\t{ field: 'newPassword2' },\n\t],\n};\n/** @type {ModelScript} */\nexport const user = {\n\tdocumentScripts: {\n\t\tsetPassword(params) {\n\t\t\tconst userId = params.document?.id;\n\t\t\tif (!userId) { return; }\n\t\t\tconst dialog = document.createElement('dialog');\n\t\t\tconst form = document.createElement('form');\n\t\t\tconst title = form.appendChild(document.createElement('h2'));\n\t\t\ttitle.textContent = '设置用户密码';\n\t\t\tdialog.appendChild(form);\n\t\t\tconst ac = new AbortController();\n\t\t\tdialog.addEventListener('close', () => {\n\t\t\t\tdialog.remove();\n\t\t\t\tac.abort();\n\t\t\t});\n\t\t\tconst store = Store.create(schema);\n\t\t\tstore.reset();\n\t\t\tconst destroy = renderStore(\n\t\t\t\tstore,\n\t\t\t\t(store, options) => createStoreField(store, {}, options),\n\t\t\t\tform,\n\t\t\t\tStoreLayout,\n\t\t\t\t{ editable: true },\n\t\t\t);\n\t\t\tac.signal.addEventListener('abort', destroy, { once: true });\n\n\t\t\tconst submitButton = form.appendChild(document.createElement('button'));\n\t\t\tsubmitButton.type = 'submit';\n\t\t\tsubmitButton.textContent = '修改密码';\n\n\t\t\tform.addEventListener('submit', async event => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif (submitButton.disabled) { return; }\n\t\t\t\ttry {\n\t\t\t\t\tsubmitButton.disabled = true;\n\t\t\t\t\tconst { password, newPassword1 } = store.value;\n\t\t\t\t\tconst r = await store.validate();\n\t\t\t\t\tif (r?.length) { return; }\n\t\t\t\t\tconst result = await Plugin.request.clone().put('password').body({\n\t\t\t\t\t\tuserId, password, newPassword: newPassword1,\n\t\t\t\t\t}).result();\n\t\t\t\t\tif (!result || result === 200 || typeof result === 'object') {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\talert('密码修改完成');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 404) {\n\t\t\t\t\t\talert('新旧密码不能相同');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 403) {\n\t\t\t\t\t\talert('密码错误');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 400) {\n\t\t\t\t\t\talert('不能修改自己的密码');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 402) {\n\t\t\t\t\t\talert('您无操作权限');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof Response) {\n\t\t\t\t\t\tif (e.status === 403) {\n\t\t\t\t\t\t\talert('密码错误');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tsubmitButton.disabled = false;\n\t\t\t\t}\n\t\t\t});\n\t\t\tdocument.body.appendChild(dialog);\n\t\t\tdialog.showModal();\n\t\t}\n\t}\n};\n","/** @import { PageContext, Schema, StoreLayout } from '@yongdall/web' */\n\nimport { createStoreField, renderStore, Store } from '@yongdall/web';\nimport Plugin from '@yongdall/web/plugin';\nimport { verifyNewPassword } from './common/verifyNewPassword.mjs';\n\n/** @type {Schema} */\nconst schema = {\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\tnewPassword1: {\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\treturn [...verifyNewPassword(value)];\n\t\t\t},\n\t\t},\n\t},\n\tnewPassword2: {\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) { return '请填写重复密码'; }\n\t\t\t\tif (value !== store.parent?.child('newPassword1')?.value) {\n\t\t\t\t\treturn '重复密码与新密码不一致';\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t},\n};\n\n/** @type {StoreLayout} */\nconst StoreLayout = {\n\tfields: [\n\t\t{ field: 'password' },\n\t\t{ field: 'newPassword1' },\n\t\t{ field: 'newPassword2' },\n\t],\n};\n/**\n * \n * @param {PageContext} ctx \n */\nexport default function(ctx) {\n\tctx.loading = false;\n\tctx.panel = true;\n\tctx.title = '修改密码';\n\tconst container = ctx.container;\n\tcontainer.style.margin = 'auto';\n\tcontainer.style.maxInlineSize = '300px';\n\n\tconst form = document.createElement('form');\n\tconst title = form.appendChild(document.createElement('h2'));\n\ttitle.textContent = '修改密码';\n\tcontainer.appendChild(form);\n\n\tconst store = Store.create(schema);\n\tstore.reset();\n\tif (ctx.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\tctx.signal.addEventListener('abort', destroy, { once: true });\n\n\n\tconst submitButton = form.appendChild(document.createElement('button'));\n\tsubmitButton.type = 'submit';\n\tsubmitButton.textContent = '修改密码';\n\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 { password, newPassword1 } = 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('password').body({\n\t\t\t\tpassword, newPassword: newPassword1,\n\t\t\t}).result();\n\t\t\tif (!result || result === 200 || typeof result === 'object') {\n\t\t\t\tstore.reset();\n\t\t\t\talert('密码修改完成');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (result === 403) {\n\t\t\t\talert('密码错误');\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 === 403) {\n\t\t\t\t\talert('密码错误');\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"],"mappings":"iRAAA,MAAM,EAAgB,CACrB,QACA,QACA,QACA,sCACA,CAKD,SAAiB,EAAkB,EAAU,CACxC,EAAS,OAAS,IAAK,KAAM,YAE7B,EAAc,OAAO,GAAK,EA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GACC,EAAO,IAAY,EAAiB,EAAO,EAAE,CAAE,EAAQ,CACxD,EACA,EACA,CAAE,SAAU,GAAM,CAClB,CACD,EAAI,OAAO,iBAAiB,QAAS,EAAS,CAAE,KAAM,GAAM,CAAC,CAG7D,IAAM,EAAe,EAAK,YAAY,SAAS,cAAc,SAAS,CAAC,CACvE,EAAa,KAAO,SACpB,EAAa,YAAc,OAE3B,EAAK,iBAAiB,SAAU,KAAM,IAAS,CAC9C,KAAM,gBAAgB,CAClB,GAAa,SACjB,GAAI,CACH,EAAa,SAAW,GACxB,GAAM,CAAE,WAAU,gBAAiB,EAAM,MAEzC,IADU,MAAM,EAAM,UAAU,GACzB,OAAU,OACjB,IAAM,EAAS,MAAM,EAAO,QAAQ,OAAO,CAAC,IAAI,WAAW,CAAC,KAAK,CAChE,WAAU,YAAa,EACvB,CAAC,CAAC,QAAQ,CACX,GAAI,CAAC,GAAU,IAAW,KAAO,OAAO,GAAW,SAAU,CAC5D,EAAM,OAAO,CACb,MAAM,SAAS,CACf,OAED,GAAI,IAAW,IAAK,CACnB,MAAM,OAAO,CACb,cAGO,EAAG,CACP,aAAa,UACZ,EAAE,SAAW,KAChB,MAAM,OAAO,QAGN,CACT,EAAa,SAAW,KAExB"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["schema","layout"],"sources":["../../../plugins/user/common/verifyNewPassword.mjs","../../../plugins/user/assets/models.mjs","../../../plugins/user/assets/password.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 { ModelScript } from '@yongdall/web' */\n/** @import { Schema, StoreLayout } from '@yongdall/web' */\n\nimport { renderStoreForm, single, Store } from '@yongdall/web';\nimport Plugin from '@yongdall/web/plugin';\nimport { verifyNewPassword } from './common/verifyNewPassword.mjs';\n\n/** @type {Schema} */\nconst schema = {\n\n\tpassword: {\n\t\ttype: 'string', label: '您的密码', component: 'password',\n\t\thidden: single,\n\t\tvalidators: {\n\t\t\tblur(store) {\n\t\t\t\tif (single) { return; }\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\tnewPassword1: {\n\t\ttype: 'string', label: '新密码', component: 'password',\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\treturn [...verifyNewPassword(value)];\n\t\t\t},\n\t\t},\n\t},\n\tnewPassword2: {\n\t\ttype: 'string', label: '重复密码', component: 'password',\n\t\tvalidators: {\n\t\t\tblur(store) {\n\t\t\t\tconst value = store.value;\n\t\t\t\tif (!value) { return '请填写重复密码'; }\n\t\t\t\tif (value !== store.parent?.child('newPassword1')?.value) {\n\t\t\t\t\treturn '重复密码与新密码不一致';\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t},\n};\n\n/** @type {StoreLayout<any>} */\nconst layout = {\n\tfields: [\n\t\t{ field: 'password' },\n\t\t{ field: 'newPassword1' },\n\t\t{ field: 'newPassword2' },\n\t],\n};\n/** @type {ModelScript} */\nexport const user = {\n\tdocumentScripts: {\n\t\tsetPassword(params) {\n\t\t\tconst userId = params.document?.id;\n\t\t\tif (!userId) { return; }\n\t\t\tconst dialog = document.createElement('dialog');\n\t\t\tconst form = document.createElement('form');\n\t\t\tconst title = form.appendChild(document.createElement('h2'));\n\t\t\ttitle.textContent = '设置用户密码';\n\t\t\tdialog.appendChild(form);\n\t\t\tconst ac = new AbortController();\n\t\t\tdialog.addEventListener('close', () => {\n\t\t\t\tdialog.remove();\n\t\t\t\tac.abort();\n\t\t\t});\n\t\t\tconst store = Store.create(schema);\n\t\t\tstore.reset();\n\n\t\t\trenderStoreForm(store, form, { editable: true, layout, signal: ac.signal });\n\n\t\t\tconst submitButton = form.appendChild(document.createElement('button'));\n\t\t\tsubmitButton.type = 'submit';\n\t\t\tsubmitButton.textContent = '修改密码';\n\n\t\t\tform.addEventListener('submit', async event => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tif (submitButton.disabled) { return; }\n\t\t\t\ttry {\n\t\t\t\t\tsubmitButton.disabled = true;\n\t\t\t\t\tconst { password, newPassword1 } = store.value;\n\t\t\t\t\tconst r = await store.validate();\n\t\t\t\t\tif (r?.length) { return; }\n\t\t\t\t\tconst result = await Plugin.request.clone().put('password').body({\n\t\t\t\t\t\tuserId, password, newPassword: newPassword1,\n\t\t\t\t\t}).result();\n\t\t\t\t\tif (!result || result === 200 || typeof result === 'object') {\n\t\t\t\t\t\tdialog.close();\n\t\t\t\t\t\talert('密码修改完成');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 404) {\n\t\t\t\t\t\talert('新旧密码不能相同');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 403) {\n\t\t\t\t\t\talert('密码错误');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 400) {\n\t\t\t\t\t\talert('不能修改自己的密码');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (result === 402) {\n\t\t\t\t\t\talert('您无操作权限');\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof Response) {\n\t\t\t\t\t\tif (e.status === 403) {\n\t\t\t\t\t\t\talert('密码错误');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tsubmitButton.disabled = false;\n\t\t\t\t}\n\t\t\t});\n\t\t\tdocument.body.appendChild(dialog);\n\t\t\tdialog.showModal();\n\t\t}\n\t}\n};\n","/** @import { PageContext, Schema, StoreLayout } from '@yongdall/web' */\n\nimport { renderStoreForm, Store } from '@yongdall/web';\nimport Plugin from '@yongdall/web/plugin';\nimport { verifyNewPassword } from './common/verifyNewPassword.mjs';\n\n/** @type {Schema} */\nconst schema = {\n\n\tpassword: {\n\t\ttype: 'string', label: '当前密码', component: 'password',\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\tnewPassword1: {\n\t\ttype: 'string', label: '新密码', component: 'password',\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\treturn [...verifyNewPassword(value)];\n\t\t\t},\n\t\t},\n\t},\n\tnewPassword2: {\n\t\ttype: 'string', label: '重复密码', component: 'password',\n\t\tvalidators: {\n\t\t\tblur(store) {\n\t\t\t\tconst value = store.value;\n\t\t\t\tif (!value) { return '请填写重复密码'; }\n\t\t\t\tif (value !== store.parent?.child('newPassword1')?.value) {\n\t\t\t\t\treturn '重复密码与新密码不一致';\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t},\n};\n\n/** @type {StoreLayout<any>} */\nconst layout = {\n\tfields: [\n\t\t{ field: 'password' },\n\t\t{ field: 'newPassword1' },\n\t\t{ field: 'newPassword2' },\n\t],\n};\n/**\n * \n * @param {PageContext} ctx \n */\nexport default function(ctx) {\n\tctx.loading = false;\n\tctx.panel = true;\n\tctx.title = '修改密码';\n\tconst container = ctx.container;\n\tcontainer.style.margin = 'auto';\n\tcontainer.style.maxInlineSize = '300px';\n\n\tconst form = document.createElement('form');\n\tconst title = form.appendChild(document.createElement('h2'));\n\ttitle.textContent = '修改密码';\n\tcontainer.appendChild(form);\n\n\tconst store = Store.create(schema);\n\tstore.reset();\n\tif (ctx.signal.aborted) {\n\t\treturn null;\n\t}\n\n\n\trenderStoreForm(store, form, { editable: true, layout, signal: ctx.signal });\n\n\n\tconst submitButton = form.appendChild(document.createElement('button'));\n\tsubmitButton.type = 'submit';\n\tsubmitButton.textContent = '修改密码';\n\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 { password, newPassword1 } = 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('password').body({\n\t\t\t\tpassword, newPassword: newPassword1,\n\t\t\t}).result();\n\t\t\tif (!result || result === 200 || typeof result === 'object') {\n\t\t\t\tstore.reset();\n\t\t\t\talert('密码修改完成');\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (result === 403) {\n\t\t\t\talert('密码错误');\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 === 403) {\n\t\t\t\t\talert('密码错误');\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"],"mappings":"+PAAA,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,CAE3B,IAAM,EAAQ,EAAM,OAAO,EAAO,CAElC,GADA,EAAM,OAAO,CACT,EAAI,OAAO,QACd,OAAO,KAIR,EAAgB,EAAO,EAAM,CAAE,SAAU,GAAM,SAAQ,OAAQ,EAAI,OAAQ,CAAC,CAG5E,IAAM,EAAe,EAAK,YAAY,SAAS,cAAc,SAAS,CAAC,CACvE,EAAa,KAAO,SACpB,EAAa,YAAc,OAE3B,EAAK,iBAAiB,SAAU,KAAM,IAAS,CAC9C,KAAM,gBAAgB,CAClB,GAAa,SACjB,GAAI,CACH,EAAa,SAAW,GACxB,GAAM,CAAE,WAAU,gBAAiB,EAAM,MAEzC,IADU,MAAM,EAAM,UAAU,GACzB,OAAU,OACjB,IAAM,EAAS,MAAM,EAAO,QAAQ,OAAO,CAAC,IAAI,WAAW,CAAC,KAAK,CAChE,WAAU,YAAa,EACvB,CAAC,CAAC,QAAQ,CACX,GAAI,CAAC,GAAU,IAAW,KAAO,OAAO,GAAW,SAAU,CAC5D,EAAM,OAAO,CACb,MAAM,SAAS,CACf,OAED,GAAI,IAAW,IAAK,CACnB,MAAM,OAAO,CACb,cAGO,EAAG,CACP,aAAa,UACZ,EAAE,SAAW,KAChB,MAAM,OAAO,QAGN,CACT,EAAa,SAAW,KAExB"}
|
package/index.d.mts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as imodel3 from "imodel";
|
|
2
2
|
import * as _yongdall_model0 from "@yongdall/model";
|
|
3
3
|
|
|
4
4
|
//#region plugins/user/models/User.d.mts
|
|
5
5
|
declare const _default: _yongdall_model0.ModelTable<{
|
|
6
|
-
username:
|
|
7
|
-
account:
|
|
8
|
-
userId:
|
|
9
|
-
type:
|
|
6
|
+
username: imodel3.FieldDefine<_yongdall_model0.ModelTable<{
|
|
7
|
+
account: imodel3.FieldDefine<"string", false, false>;
|
|
8
|
+
userId: imodel3.FieldDefine<"uuid", false, false>;
|
|
9
|
+
type: imodel3.FieldDefine<"string", false, false>;
|
|
10
10
|
}, "user.account">, false, false>;
|
|
11
|
-
id:
|
|
12
|
-
name:
|
|
13
|
-
enabled:
|
|
14
|
-
createdAt:
|
|
15
|
-
updatedAt:
|
|
11
|
+
id: imodel3.FieldDefine<"uuid", false, false>;
|
|
12
|
+
name: imodel3.FieldDefine<"string", false, false>;
|
|
13
|
+
enabled: imodel3.FieldDefine<"bool", false, false>;
|
|
14
|
+
createdAt: imodel3.FieldDefine<"timestamp", false, false>;
|
|
15
|
+
updatedAt: imodel3.FieldDefine<"timestamp", false, false>;
|
|
16
16
|
}, "user">;
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region plugins/user/models/UserAccount.d.mts
|
|
19
19
|
declare const _default$1: _yongdall_model0.ModelTable<{
|
|
20
|
-
account:
|
|
21
|
-
userId:
|
|
22
|
-
type:
|
|
20
|
+
account: imodel3.FieldDefine<"string", false, false>;
|
|
21
|
+
userId: imodel3.FieldDefine<"uuid", false, false>;
|
|
22
|
+
type: imodel3.FieldDefine<"string", false, false>;
|
|
23
23
|
}, "user.account">;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region plugins/user/models/UserPassword.d.mts
|
|
26
26
|
declare const _default$2: _yongdall_model0.ModelTable<{
|
|
27
|
-
userId:
|
|
28
|
-
password:
|
|
29
|
-
deadline:
|
|
30
|
-
updatedAt:
|
|
27
|
+
userId: imodel3.FieldDefine<"uuid", false, false>;
|
|
28
|
+
password: imodel3.FieldDefine<"string", false, false>;
|
|
29
|
+
deadline: imodel3.FieldDefine<"timestamp", false, true>;
|
|
30
|
+
updatedAt: imodel3.FieldDefine<"timestamp", false, false>;
|
|
31
31
|
}, "user.password">;
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region plugins/user/common/verifyNewPassword.d.mts
|
package/package.json
CHANGED
package/routers.yongdall.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as setPassword, o as verifyNewPassword } from "./user-DMOZK_4C.mjs";
|
|
2
|
-
import { getUser,
|
|
2
|
+
import { getUser, hasUserPermission, isSingleUser, verifyUser } from "@yongdall/core";
|
|
3
3
|
import { ApiRouter, useBody } from "@yongdall/http";
|
|
4
4
|
|
|
5
5
|
//#region plugins/user/routers.yongdall.mjs
|
|
@@ -18,7 +18,7 @@ plugin.put`password`(async (ctx) => {
|
|
|
18
18
|
if (userId === loggedUser) {
|
|
19
19
|
if (newPassword === password) return 404;
|
|
20
20
|
} else if (!singleUser) {
|
|
21
|
-
if (!
|
|
21
|
+
if (!await hasUserPermission("system:user:password")) return 402;
|
|
22
22
|
}
|
|
23
23
|
if (loggedUser && password && !await verifyUser(loggedUser, password, "password")) return 403;
|
|
24
24
|
if ([...verifyNewPassword(newPassword)].length) return 408;
|
package/routers.yongdall.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routers.yongdall.mjs","names":[],"sources":["../../plugins/user/routers.yongdall.mjs"],"sourcesContent":["import { ApiRouter, useBody } from '@yongdall/http';\nimport { getUser,
|
|
1
|
+
{"version":3,"file":"routers.yongdall.mjs","names":[],"sources":["../../plugins/user/routers.yongdall.mjs"],"sourcesContent":["import { ApiRouter, useBody } from '@yongdall/http';\nimport { getUser, hasUserPermission, isSingleUser, verifyUser } from '@yongdall/core';\nimport { verifyNewPassword } from './common/verifyNewPassword.mjs';\nimport { setPassword } from './index.mjs';\n\nexport const plugin = new ApiRouter();\n\nplugin.put`password`(async ctx => {\n\tconst { password, newPassword, userId } = await useBody() || {};\n\tif (!newPassword || typeof newPassword !== 'string') { return 404; }\n\tconst loggedUser = await getUser();\n\tconst singleUser = await isSingleUser();\n\tif (!singleUser && !loggedUser) { return 404; }\n\tconst targetUser = userId || loggedUser;\n\tif (!targetUser) { return 404; }\n\tif (userId === loggedUser || !singleUser) {\n\t\tif (!password || typeof password !== 'string') { return 404; }\n\t}\n\tif (userId === loggedUser) {\n\t\tif (newPassword === password) { return 404; }\n\t} else if (!singleUser) {\n\t\tif (!await hasUserPermission('system:user:password')) { return 402; }\n\n\t}\n\tif (loggedUser && password && !await verifyUser(loggedUser, password, 'password')) { return 403; }\n\tif ([...verifyNewPassword(newPassword)].length) { return 408; }\n\tawait setPassword(targetUser, newPassword, userId === loggedUser ? null : new Date);\n\treturn 200;\n});\n"],"mappings":";;;;;AAKA,MAAa,SAAS,IAAI,WAAW;AAErC,OAAO,GAAG,WAAW,OAAM,QAAO;CACjC,MAAM,EAAE,UAAU,aAAa,WAAW,MAAM,SAAS,IAAI,EAAE;AAC/D,KAAI,CAAC,eAAe,OAAO,gBAAgB,SAAY,QAAO;CAC9D,MAAM,aAAa,MAAM,SAAS;CAClC,MAAM,aAAa,MAAM,cAAc;AACvC,KAAI,CAAC,cAAc,CAAC,WAAc,QAAO;CACzC,MAAM,aAAa,UAAU;AAC7B,KAAI,CAAC,WAAc,QAAO;AAC1B,KAAI,WAAW,cAAc,CAAC,YAC7B;MAAI,CAAC,YAAY,OAAO,aAAa,SAAY,QAAO;;AAEzD,KAAI,WAAW,YACd;MAAI,gBAAgB,SAAY,QAAO;YAC7B,CAAC,YACX;MAAI,CAAC,MAAM,kBAAkB,uBAAuB,CAAI,QAAO;;AAGhE,KAAI,cAAc,YAAY,CAAC,MAAM,WAAW,YAAY,UAAU,WAAW,CAAI,QAAO;AAC5F,KAAI,CAAC,GAAG,kBAAkB,YAAY,CAAC,CAAC,OAAU,QAAO;AACzD,OAAM,YAAY,YAAY,aAAa,WAAW,aAAa,uBAAO,IAAI,MAAI,CAAC;AACnF,QAAO;EACN"}
|