twofactor_backupcodes-settings.mjs 3.6 KB

12
  1. /*! third party licenses: dist/vendor.LICENSE.txt */
  2. import{bZ as n,bR as r,aV as a,b_ as d}from"./core-common.mjs";import{x as u}from"./chunks/index-CDMqmWCu.mjs";/* empty css */import{n as i}from"./chunks/icons-TElqpmA8.mjs";import{i as l,S as p}from"./chunks/vuex.esm-pSkZdmXO.mjs";function b(e){const o=OC.theme.name||"Nextcloud",s=window.open("",t("twofactor_backupcodes","{name} backup codes",{name:o}));s.document.write("<h1>"+t("twofactor_backupcodes","{name} backup codes",{name:o})+"</h1>"),s.document.write("<pre>"+e+"</pre>"),s.print(),s.close()}const h={name:"PersonalSettings",data(){return{generatingCodes:!1}},computed:{downloadUrl(){return this.codes?"data:text/plain,"+encodeURIComponent(this.codes.reduce((e,o)=>e+o+"\r\n","")):""},downloadFilename(){return(OC.theme.name||"Nextcloud")+"-backup-codes.txt"},enabled(){return this.$store.state.enabled},total(){return this.$store.state.total},used(){return this.$store.state.used},codes(){return this.$store.state.codes},name(){return OC.theme.name||"Nextcloud"},haveCodes(){return this.codes&&this.codes.length>0}},methods:{generateBackupCodes(){u().then(()=>{this.generatingCodes=!0,this.$store.dispatch("generate").then(e=>{this.generatingCodes=!1}).catch(e=>{throw OC.Notification.showTemporary(t("twofactor_backupcodes","An error occurred while generating your backup codes")),this.generatingCodes=!1,e})}).catch(console.error.bind(this))},getPrintData(e){return e?e.reduce((o,s)=>o+s+"<br>",""):""},printCodes(){b(this.getPrintData(this.codes))}}};var m=function(){var e=this,o=e._self._c;return o("div",[e.enabled?[o("p",[e.haveCodes?[e._v(" "+e._s(e.t("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"))+" "),o("ul",e._l(e.codes,function(s){return o("li",{key:s,staticClass:"backup-code"},[e._v(" "+e._s(s)+" ")])}),0),o("a",{staticClass:"button primary",attrs:{href:e.downloadUrl,download:e.downloadFilename}},[e._v(e._s(e.t("twofactor_backupcodes","Save backup codes")))]),o("button",{staticClass:"button",on:{click:e.printCodes}},[e._v(" "+e._s(e.t("twofactor_backupcodes","Print backup codes"))+" ")])]:[e._v(" "+e._s(e.t("twofactor_backupcodes","Backup codes have been generated. {used} of {total} codes have been used.",{used:e.used,total:e.total}))+" ")]],2),o("p",[o("button",{attrs:{id:"generate-backup-codes"},on:{click:e.generateBackupCodes}},[e._v(" "+e._s(e.t("twofactor_backupcodes","Regenerate backup codes"))+" ")])]),o("p",[o("em",[e._v(" "+e._s(e.t("twofactor_backupcodes","If you regenerate backup codes, you automatically invalidate old codes."))+" ")])])]:o("button",{attrs:{id:"generate-backup-codes",disabled:e.generatingCodes},on:{click:e.generateBackupCodes}},[e._v(" "+e._s(e.t("twofactor_backupcodes","Generate backup codes"))+" "),o("span",{class:{"icon-loading-small":e.generatingCodes}})])],2)},k=[],g=i(h,m,k,!1,null,"048bf16d");const _=g.exports;function w(){const e=n("/apps/twofactor_backupcodes/settings/create");return r.post(e,{}).then(o=>o.data)}a.use(l);const f={enabled:!1,total:0,used:0,codes:[]},C={setEnabled(e,o){a.set(e,"enabled",o)},setTotal(e,o){a.set(e,"total",o)},setUsed(e,o){a.set(e,"used",o)},setCodes(e,o){a.set(e,"codes",o)}},v={generate({commit:e}){return e("setEnabled",!1),w().then(({codes:o,state:s})=>(e("setEnabled",s.enabled),e("setTotal",s.total),e("setUsed",s.used),e("setCodes",o),!0))}},c=new p({strict:!1,state:f,mutations:C,actions:v});a.prototype.t=t;const y=d("twofactor_backupcodes","state");c.replaceState(y);const x=a.extend(_);new x({store:c}).$mount("#twofactor-backupcodes-settings");