2FAuth/public/build/assets/OtpDisplay-1a3c1737.js

2 lines
6.4 KiB
JavaScript
Raw Normal View History

2024-01-19 15:49:01 +01:00
import{r as s,v as C,o as J,s as Y,f as u,g as f,F as ee,G as te,i as n,n as N,a as oe,b as ae,P as ne,R as se,Z as re,x as le,e as ue,h as S,l as A,m as M,p as ie,t as b,w as ce,X as pe,U as ve,A as j,B as q,k as z,D as de,J as B,I as E,O as G}from"./app-347ef106.js";import{S as fe}from"./Spinner-8bfb7257.js";/*! 2FAuth version 5.0.3 - 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=s(null),i=s(null),x=s(null),y=s(null),c=s(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;x.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(x.value),clearInterval(y.value),c.value=r.value=null};return J(()=>{o.autostart==!0&&m()}),Y(()=>{_()}),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=s(0),r=C(()=>o.value==-1);function i(y){o.value=y<l.stepCount?y+1:1}function x(){o.value=-1}return J(()=>{isNaN(l.initialIndex)||i(l.initialIndex)}),T({turnOn:i,turnOff:x,props:l}),(y,c)=>(u(),f("ul",{class:N(["dots",{off:n(r)}])},[(u(!0),f(ee,null,te(k.stepCount,p=>(u(),f("li",{key:p,"data-is-active":p==n(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"},Se={__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(),x=ne("2fauth"),{copy:y,copied:c}=se({legacy:!0}),p=re(),h=s(null),w=s(null),e=s({otp_type:"",account:"",service:"",icon:"",secret:"",digits:null,algorithm:"",period:null,counter:null,image:""}),m=s(""),_=s(null),v=s(!1),g=s(!1),O=s(!1),D=s(),I=s(),V=s();le(()=>o.icon,a=>{a!=null&&(e.value.icon=a)});const X=async a=>{if(O.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,H(),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(),Q()}catch{L()}};async function F(){H(),await Z().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,G().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 H(){g.value=!0,D.value.turnOff()}function Z(){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