2FAuth/public/build/assets/OtpDisplay-ec83b57b.js

2 lines
6.4 KiB
JavaScript

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-1b332c21.js";import{S as fe}from"./Spinner-b3cbad3a.js";/*! 2FAuth version 5.0.0 - 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=e.value.icon=e.value.otp_type=e.value.secret="",m.value="... ...",v.value=!1,(a=I.value)==null||a.clearLooper()}function Q(){G().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"),O.value=!1,L()),i.success({text:E("commons.copied_to_clipboard")}))}function U(a){return a==="totp"||a==="steamtotp"}function P(a){return a==="hotp"}function K(a){D.value.turnOn(a)}return T({show:X,clearOTP:L}),(a,t)=>{const R=ue("font-awesome-icon");return u(),f("div",null,[S("figure",{class:N(["image is-64x64",{"no-icon":!n(e).icon}]),style:{display:"inline-block"}},[n(e).icon?(u(),f("img",{key:0,src:n(x).config.subdirectory+"/storage/icons/"+n(e).icon,alt:a.$t("twofaccounts.icon_to_illustrate_the_account")},null,8,ge)):A("",!0)],2),M(n(ve),null,{default:ie(({mode:d})=>[S("p",{class:N(["is-size-4 has-ellipsis",d=="dark"?"has-text-grey-light":"has-text-grey"])},b(n(e).service),3),S("p",{class:N(["is-size-6 has-ellipsis",d=="dark"?"has-text-grey":"has-text-grey-light"])},b(n(e).account),3),S("p",null,[n(g)?(u(),f("span",we,[M(fe,{isVisible:n(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]=W=>$(n(m),!0)),onKeyup:t[1]||(t[1]=ce(W=>$(n(m),!0),["enter"])),title:a.$t("commons.copy_to_clipboard")},b(n(pe)(n(m),n(r).preferences.showOtpAsDot&&n(r).preferences.revealDottedOTP&&n(O))),43,he))])]),_:1}),j(M(_e,{ref_key:"dots",ref:D},null,512),[[q,U(n(e).otp_type)]]),j(S("p",null,b(a.$t("twofaccounts.forms.counter.label"))+": "+b(n(e).counter),513),[[q,P(n(e).otp_type)]]),n(r).preferences.showOtpAsDot&&n(r).preferences.revealDottedOTP?(u(),f("p",ke,[S("button",{class:"button is-ghost has-text-grey-dark",onClick:t[2]||(t[2]=de(d=>O.value=!n(O),["stop"]))},[n(O)?(u(),z(R,{key:0,icon:["fas","eye"]})):(u(),z(R,{key:1,icon:["fas","eye-slash"]}))])])):A("",!0),n(v)?(u(),z(ye,{key:1,period:n(e).period,generated_at:n(_),autostart:!1,onLoopEnded:t[3]||(t[3]=d=>F()),onLoopStarted:t[4]||(t[4]=d=>K(d)),onSteppedUp:t[5]||(t[5]=d=>K(d)),ref_key:"totpLooper",ref:I},null,8,["period","generated_at"])):A("",!0)])}}};export{Se as _,ye as a,_e as b};