nextcloud-server/dist/twofactor_backupcodes-setti...

4 lines
7.4 KiB
JavaScript

import{L as ae,M as S,O as ne,m as he,P as ke,k as ye,Q as U,R as oe,S as me,T as ge,V as ve,z as we,W as Se,X as $e,n as H,f,i as je,e as Oe,l as Ee,j as Pe,D as w,o as k,c as Z,u as i,w as I,d as E,t as g,E as q,Y as xe,Z as L,h as A,$ as Ce,a0 as z,b as B,_ as Me,g as Ie}from"./NcSettingsSection-DFav6ob5-DwBgvX10.chunk.mjs";import{g as Le,m as ce,s as se,j as R}from"./check-JUc8IOXP.chunk.mjs";import{c as Ae}from"./index-OdkWN6SR.chunk.mjs";let re;const F=e=>re=e,ue=Symbol();function J(e){return e&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"&&typeof e.toJSON!="function"}var N;(function(e){e.direct="direct",e.patchObject="patch object",e.patchFunction="patch function"})(N||(N={}));function Ne(){const e=ae(!0),n=e.run(()=>S({}));let t=[],a=[];const o=ne({install(u){F(o),o._a=u,u.provide(ue,o),u.config.globalProperties.$pinia=o,a.forEach(c=>t.push(c)),a=[]},use(u){return this._a?t.push(u):a.push(u),this},_p:t,_a:null,_e:e,_s:new Map,state:n});return o}const ie=()=>{};function K(e,n,t,a=ie){e.push(n);const o=()=>{const u=e.indexOf(n);u>-1&&(e.splice(u,1),a())};return!t&&ge()&&ve(o),o}function P(e,...n){e.slice().forEach(t=>{t(...n)})}const Te=e=>e(),ee=Symbol(),D=Symbol();function Q(e,n){e instanceof Map&&n instanceof Map?n.forEach((t,a)=>e.set(a,t)):e instanceof Set&&n instanceof Set&&n.forEach(e.add,e);for(const t in n){if(!n.hasOwnProperty(t))continue;const a=n[t],o=e[t];J(o)&&J(a)&&e.hasOwnProperty(t)&&!U(a)&&!oe(a)?e[t]=Q(o,a):e[t]=a}return e}const Re=Symbol();function Ue(e){return!J(e)||!Object.prototype.hasOwnProperty.call(e,Re)}const{assign:v}=Object;function Fe(e){return!!(U(e)&&e.effect)}function We(e,n,t,a){const{state:o,actions:u,getters:c}=n,y=t.state.value[e];let m;function d(){y||(t.state.value[e]=o?o():{});const _=$e(t.state.value[e]);return v(_,u,Object.keys(c||{}).reduce((h,$)=>(h[$]=ne(H(()=>{F(t);const j=t._s.get(e);return c[$].call(j,j)})),h),{}))}return m=de(e,d,n,t,a,!0),m}function de(e,n,t={},a,o,u){let c;const y=v({actions:{}},t),m={deep:!0};let d,_,h=[],$=[],j;const O=a.state.value[e];!u&&!O&&(a.state.value[e]={}),S({});let V;function X(s){let r;d=_=!1,typeof s=="function"?(s(a.state.value[e]),r={type:N.patchFunction,storeId:e,events:j}):(Q(a.state.value[e],s),r={type:N.patchObject,payload:s,storeId:e,events:j});const l=V=Symbol();Se().then(()=>{V===l&&(d=!0)}),_=!0,P(h,r,a.state.value[e])}const le=u?function(){const{state:s}=t,r=s?s():{};this.$patch(l=>{v(l,r)})}:ie;function pe(){c.stop(),h=[],$=[],a._s.delete(e)}const Y=(s,r="")=>{if(ee in s)return s[D]=r,s;const l=function(){F(a);const T=Array.from(arguments),C=[],W=[];function be(p){C.push(p)}function _e(p){W.push(p)}P($,{args:T,name:l[D],store:b,after:be,onError:_e});let M;try{M=s.apply(this&&this.$id===e?this:b,T)}catch(p){throw P(W,p),p}return M instanceof Promise?M.then(p=>(P(C,p),p)).catch(p=>(P(W,p),Promise.reject(p))):(P(C,M),M)};return l[ee]=!0,l[D]=r,l},fe={_p:a,$id:e,$onAction:K.bind(null,$),$patch:X,$reset:le,$subscribe(s,r={}){const l=K(h,s,r.detached,()=>T()),T=c.run(()=>we(()=>a.state.value[e],C=>{(r.flush==="sync"?_:d)&&s({storeId:e,type:N.direct,events:j},C)},v({},m,r)));return l},$dispose:pe},b=ye(fe);a._s.set(e,b);const x=(a._a&&a._a.runWithContext||Te)(()=>a._e.run(()=>(c=ae()).run(()=>n({action:Y}))));for(const s in x){const r=x[s];if(U(r)&&!Fe(r)||oe(r))u||(O&&Ue(r)&&(U(r)?r.value=O[s]:Q(r,O[s])),a.state.value[e][s]=r);else if(typeof r=="function"){const l=Y(r,s);x[s]=l,y.actions[s]=r}}return v(b,x),v(me(b),x),Object.defineProperty(b,"$state",{get:()=>a.state.value[e],set:s=>{X(r=>{v(r,s)})}}),a._p.forEach(s=>{v(b,c.run(()=>s({store:b,app:a._a,pinia:a,options:y})))}),O&&u&&t.hydrate&&t.hydrate(b.$state,O),d=!0,_=!0,b}function ze(e,n,t){let a;const o=typeof n=="function";a=o?t:n;function u(c,y){const m=ke();return c=c||(m?he(ue,null):null),c&&F(c),c=re,c._s.has(e)||(o?de(e,n,a,c):We(e,a,c)),c._s.get(e)}return u.$id=e,u}const Be=Le().detectLogLevel().setApp("twofactor_backupcodes").build();function De(e){const n=ce().theming.name||"Nextcloud",t=window.open("",f("twofactor_backupcodes","{name} backup codes",{name:n}));if(!t)throw se(f("twofactor_backupcodes","Unable to open a new tab for printing")),new Error("Unable to open a new tab for printing");const a=t.document.createElement("h1");a.textContent=f("twofactor_backupcodes","{name} backup codes",{name:n});const o=t.document.createElement("pre");for(const u of e){const c=t.document.createTextNode(u);o.appendChild(c),o.appendChild(t.document.createElement("br"))}t.document.body.innerHTML="",t.document.body.appendChild(a),t.document.body.appendChild(o),t.print(),t.close()}async function Ge(){const e=je("/apps/twofactor_backupcodes/settings/create"),{data:n}=await Oe.post(e);return n}const G=Ee("twofactor_backupcodes","state"),He=ze("twofactor_backupcodes",()=>{const e=S(G.enabled),n=S(G.total),t=S(G.used),a=S([]);async function o(){e.value=!1;const{codes:u,state:c}=await Ge();e.value=c.enabled,n.value=c.total,t.value=c.used,a.value=u}return{enabled:e,total:n,used:t,codes:a,generate:o}}),Je=["aria-label"],Qe=Pe({__name:"PersonalSettings",setup(e){const n=ce().theming.name??"Nextcloud",t=He(),a=S(!1),o=H(()=>t.codes&&t.codes.length>0),u=n+"-backup-codes.txt",c=H(()=>o.value?"data:text/plain,"+encodeURIComponent(t.codes.reduce((d,_)=>d+_+`
`,"")):"");async function y(){await Ae(),a.value=!0;try{await t.generate()}catch(d){Be.error("Error generating backup codes",{error:d}),se(f("twofactor_backupcodes","An error occurred while generating your backup codes"))}finally{a.value=!1}}function m(){De(!t.codes||t.codes.length===0?[]:t.codes)}return(d,_)=>(k(),w("div",{class:z(d.$style.backupcodesSettings)},[i(t).enabled?(k(),w(L,{key:1},[A("p",null,[o.value?(k(),w(L,{key:1},[E(g(i(f)("twofactor_backupcodes","These are your backup codes. Please save and/or print them as you will not be able to read the codes again later."))+" ",1),A("ul",{"aria-label":i(f)("twofactor_backupcodes","List of backup codes")},[(k(!0),w(L,null,Ce(i(t).codes,h=>(k(),w("li",{key:h,class:z(d.$style.backupcodesSettings__code)},g(h),3))),128))],8,Je)],64)):(k(),w(L,{key:0},[E(g(i(f)("twofactor_backupcodes","Backup codes have been generated. {used} of {total} codes have been used.",{used:i(t).used,total:i(t).total})),1)],64))]),A("p",{class:z(d.$style.backupcodesSettings__actions)},[B(i(R),{id:"generate-backup-codes",variant:"error",onClick:y},{default:I(()=>[E(g(i(f)("twofactor_backupcodes","Regenerate backup codes")),1)]),_:1}),o.value?(k(),w(L,{key:0},[B(i(R),{onClick:m},{default:I(()=>[E(g(i(f)("twofactor_backupcodes","Print backup codes")),1)]),_:1}),B(i(R),{href:c.value,download:u,variant:"primary"},{default:I(()=>[E(g(i(f)("twofactor_backupcodes","Save backup codes")),1)]),_:1},8,["href"])],64)):q("",!0)],2),A("p",null,[A("em",null,g(i(f)("twofactor_backupcodes","If you regenerate backup codes, you automatically invalidate old codes.")),1)])],64)):(k(),Z(i(R),{key:0,disabled:a.value,variant:"primary",onClick:y},{icon:I(()=>[a.value?(k(),Z(i(xe),{key:0})):q("",!0)]),default:I(()=>[E(" "+g(i(f)("twofactor_backupcodes","Generate backup codes")),1)]),_:1},8,["disabled"]))],2))}}),Ve="_backupcodesSettings_bnkw8_2",Xe="_backupcodesSettings__code_bnkw8_7",Ye="_backupcodesSettings__actions_bnkw8_13",Ze={backupcodesSettings:Ve,backupcodesSettings__code:Xe,backupcodesSettings__actions:Ye},qe={$style:Ze},Ke=Me(Qe,[["__cssModules",qe]]),et=Ne(),te=Ie(Ke);te.use(et),te.mount("#twofactor-backupcodes-settings");
//# sourceMappingURL=twofactor_backupcodes-settings-personal.mjs.map