2FAuth/public/build/assets/OtpDisplay-d48e5cb6.js
2024-03-03 22:50:28 +01:00

2 lines
6.4 KiB
JavaScript
Vendored

import{r as n,v as C,o as R,s as Z,f as u,g as f,F as ee,G as te,i as s,n as N,a as oe,b as ae,Q as se,S as ne,_ as re,x as le,e as ue,h as O,l as A,m as M,p as ie,t as b,w as ce,Y as pe,U as ve,A as q,B as G,k as z,D as de,K as B,I as E,P as Q}from"./app-32c6ab3e.js";import{S as fe}from"./Spinner-fe378243.js";/*! 2FAuth version 5.0.4 - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */const ye={__name:"TotpLooper",props:{step_count:{type:Number,default:10},period:Number,generated_at:Number,autostart:{type:Boolean,default:!0}},emits:["loop-started","loop-ended","stepped-up"],setup(k,{expose:T,emit:l}){const o=k,r=n(null),i=n(null),S=n(null),y=n(null),c=n(null),p=C(()=>r.value%o.period),h=C(()=>o.period-p.value),w=C(()=>o.period/o.step_count),e=C(()=>{let v=p.value*o.step_count/o.period;return Math.floor(v)+0}),m=(v=null)=>{_(),r.value=v??o.generated_at,l("loop-started",e.value),c.value=e.value,i.value=setTimeout(function(){_(),l("loop-ended")},h.value*1e3);let g=Math.ceil(p.value/w.value)*w.value-p.value;S.value=setTimeout(function(){g>0&&(c.value+=1,l("stepped-up",c.value)),y.value=setInterval(function(){c.value+=1,l("stepped-up",c.value)},w.value*1e3)},g*1e3)},_=()=>{clearTimeout(i.value),clearTimeout(S.value),clearInterval(y.value),c.value=r.value=null};return R(()=>{o.autostart==!0&&m()}),Z(()=>{_()}),T({startLoop:m,clearLooper:_,props:o}),(v,g)=>(u(),f("div"))}},me=["data-is-active"],_e={__name:"Dots",props:{stepCount:{type:Number,default:10},initialIndex:{type:Number,default:null},period:{type:Number,default:null}},setup(k,{expose:T}){const l=k,o=n(0),r=C(()=>o.value==-1);function i(y){o.value=y<l.stepCount?y+1:1}function S(){o.value=-1}return R(()=>{isNaN(l.initialIndex)||i(l.initialIndex)}),T({turnOn:i,turnOff:S,props:l}),(y,c)=>(u(),f("ul",{class:N(["dots",{off:s(r)}])},[(u(!0),f(ee,null,te(k.stepCount,p=>(u(),f("li",{key:p,"data-is-active":p==s(o)?!0:null},null,8,me))),128))],2))}},ge=["src","alt"],he=["title"],we={key:1,tabindex:"0",class:"otp is-size-1"},ke={key:0,class:"mt-3"},Oe={__name:"OtpDisplay",props:{otp_type:String,account:String,service:String,icon:String,secret:String,digits:Number,algorithm:String,period:null,counter:null,image:String,qrcode:null,uri:String},emits:["please-close-me","increment-hotp","validation-error"],setup(k,{expose:T,emit:l}){const o=k,r=oe(),i=ae(),S=se("2fauth"),{copy:y,copied:c}=ne({legacy:!0}),p=re(),h=n(null),w=n(null),e=n({otp_type:"",account:"",service:"",icon:"",secret:"",digits:null,algorithm:"",period:null,counter:null,image:""}),m=n(""),_=n(null),v=n(!1),g=n(!1),x=n(!1),D=n(),I=n(),V=n();le(()=>o.icon,a=>{a!=null&&(e.value.icon=a)});const Y=async a=>{if(x.value=!1,e.value.otp_type=o.otp_type,e.value.account=o.account,e.value.service=o.service,e.value.icon=o.icon,e.value.secret=o.secret,e.value.digits=o.digits,e.value.algorithm=o.algorithm,e.value.period=o.period,e.value.counter=o.counter,K(),a){h.value=a;const{data:t}=await B.get(h.value);e.value.service=t.service,e.value.account=t.account,e.value.icon=t.icon,e.value.otp_type=t.otp_type,P(t.otp_type)&&t.counter&&(e.value.counter=t.counter)}else o.uri?(w.value=o.uri,e.value.otp_type=o.uri.slice(0,15).toLowerCase()==="otpauth://totp/"?"totp":"hotp"):o.secret?!U(e.value.otp_type)&&!P(e.value.otp_type)&&i.error(new Error(E("errors.not_a_supported_otp_type"))):i.error(new Error(E("errors.cannot_create_otp_without_secret")));try{await F(),W()}catch{L()}};async function F(){K(),await J().then(a=>{let t=a.data;m.value=t.password,r.preferences.copyOtpOnDisplay&&$(t.password),U(t.otp_type)?(_.value=t.generated_at,e.value.period=t.period,v.value=!0,Q().then(()=>{I.value.startLoop()})):P(t.otp_type)&&(e.value.counter=t.counter,l("increment-hotp",{nextHotpCounter:t.counter,nextUri:t.uri}))}).catch(a=>{a.response.status===422&&l("validation-error",a.response)}).finally(()=>{g.value=!1})}function K(){g.value=!0,D.value.turnOff()}function J(){return h.value?B.getOtpById(h.value):w.value?B.getOtpByUri(w.value):B.getOtpByParams(e.value)}function L(){var a;h.value=e.value.counter=_.value=null,e.value.service=e.value.account=e.value.icon=e.value.otp_type=e.value.secret="",m.value="... ...",v.value=!1,(a=I.value)==null||a.clearLooper()}function W(){Q().then(()=>{var a;(a=V.value)==null||a.focus()})}function $(a,t){y(a.replace(/ /g,"")),c&&(r.preferences.kickUserAfter==-1&&(t||!1)===!0&&p.name!="importAccounts"?r.logout({kicked:!0}):r.preferences.closeOtpOnCopy&&(t||!1)===!0&&(l("please-close-me"),x.value=!1,L()),r.preferences.clearSearchOnCopy&&l("please-clear-search"),i.success({text:E("commons.copied_to_clipboard")}))}function U(a){return a==="totp"||a==="steamtotp"}function P(a){return a==="hotp"}function H(a){D.value.turnOn(a)}return T({show:Y,clearOTP:L}),(a,t)=>{const j=ue("font-awesome-icon");return u(),f("div",null,[O("figure",{class:N(["image is-64x64",{"no-icon":!s(e).icon}]),style:{display:"inline-block"}},[s(e).icon?(u(),f("img",{key:0,src:s(S).config.subdirectory+"/storage/icons/"+s(e).icon,alt:a.$t("twofaccounts.icon_to_illustrate_the_account")},null,8,ge)):A("",!0)],2),M(s(ve),null,{default:ie(({mode:d})=>[O("p",{class:N(["is-size-4 has-ellipsis",d=="dark"?"has-text-grey-light":"has-text-grey"])},b(s(e).service),3),O("p",{class:N(["is-size-6 has-ellipsis",d=="dark"?"has-text-grey":"has-text-grey-light"])},b(s(e).account),3),O("p",null,[s(g)?(u(),f("span",we,[M(fe,{isVisible:s(g),type:"raw"},null,8,["isVisible"])])):(u(),f("span",{key:0,id:"otp",role:"log",ref_key:"otpSpanTag",ref:V,tabindex:"0",class:N(["otp is-size-1 is-clickable px-3",d=="dark"?"has-text-white":"has-text-grey-dark"]),onClick:t[0]||(t[0]=X=>$(s(m),!0)),onKeyup:t[1]||(t[1]=ce(X=>$(s(m),!0),["enter"])),title:a.$t("commons.copy_to_clipboard")},b(s(pe)(s(m),s(r).preferences.showOtpAsDot&&s(r).preferences.revealDottedOTP&&s(x))),43,he))])]),_:1}),q(M(_e,{ref_key:"dots",ref:D},null,512),[[G,U(s(e).otp_type)]]),q(O("p",null,b(a.$t("twofaccounts.forms.counter.label"))+": "+b(s(e).counter),513),[[G,P(s(e).otp_type)]]),s(r).preferences.showOtpAsDot&&s(r).preferences.revealDottedOTP?(u(),f("p",ke,[O("button",{class:"button is-ghost has-text-grey-dark",onClick:t[2]||(t[2]=de(d=>x.value=!s(x),["stop"]))},[s(x)?(u(),z(j,{key:0,icon:["fas","eye"]})):(u(),z(j,{key:1,icon:["fas","eye-slash"]}))])])):A("",!0),s(v)?(u(),z(ye,{key:1,period:s(e).period,generated_at:s(_),autostart:!1,onLoopEnded:t[3]||(t[3]=d=>F()),onLoopStarted:t[4]||(t[4]=d=>H(d)),onSteppedUp:t[5]||(t[5]=d=>H(d)),ref_key:"totpLooper",ref:I},null,8,["period","generated_at"])):A("",!0)])}}};export{Oe as _,ye as a,_e as b};