mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-02 13:14:23 +01:00
2 lines
15 KiB
JavaScript
Vendored
2 lines
15 KiB
JavaScript
Vendored
import{Z as xe,r as f,e as h,f as a,g as u,h as s,i as e,n as $,V as X,k as E,p as v,D as L,m as r,U as H,l as c,F as Y,Q as Le,u as Me,_ as Se,a as Be,c as Ne,b as qe,d as W,v as Ue,o as Oe,K as T,P as fe,x as Z,G as pe,E as me,t as g,j as ve,w as he,I as x}from"./app-06176200.js";import{F as J}from"./Form-87bc0477.js";import{_ as _e}from"./OtpDisplay-6b6605f3.js";import{_ as Ae}from"./QrContentDisplay-f8870613.js";import{u as De}from"./bus-01c5df37.js";import"./Spinner-1a29b2e3.js";/*! 2FAuth version 5.0.4 - Copyright (c) 2023 Bubka - https://github.com/Bubka/2FAuth */const He={class:"field",style:{"margin-bottom":"0.5rem"}},Pe=["for","innerHTML"],Ke=["disabled","id","type","value","placeholder","maxlength"],Qe={key:0,class:"control"},je=["title"],ze={class:"icon"},Re={key:1,class:"control"},Ge=["title"],We={class:"icon has-text-danger"},Ze=["innerHTML"],ge=Object.assign({inheritAttrs:!1},{__name:"FormLockField",props:{modelValue:[String,Number,Boolean],isEditMode:{type:Boolean,default:!1},label:{type:String,default:""},fieldName:{type:String,default:"",required:!0},fieldError:[String],inputType:{type:String,default:"text"},placeholder:{type:String,default:""},help:{type:String,default:""},hasOffset:{type:Boolean,default:!1},isDisabled:{type:Boolean,default:!1},isExpanded:{type:Boolean,default:!0},maxLength:{type:Number,default:null}},setup(d){const b=d,{inputId:q}=xe(b.inputType,b.fieldName),y=f(b.isDisabled||b.isEditMode);return(w,_)=>{const I=h("FontAwesomeIcon"),M=h("FieldError");return a(),u(Y,null,[s("div",He,[s("label",{for:e(q),class:"label",innerHTML:w.$t(d.label)},null,8,Pe)]),s("div",{class:$(["field has-addons",{"pt-3":d.hasOffset}])},[s("div",{class:$(["control",{"is-expanded":d.isExpanded}])},[s("input",X({disabled:e(y),id:e(q),type:d.inputType,class:"input",value:d.modelValue,placeholder:d.placeholder},w.$attrs,{onInput:_[0]||(_[0]=p=>w.$emit("update:modelValue",p.target.value)),maxlength:d.maxLength}),null,16,Ke)],2),d.isEditMode?(a(),E(e(H),{key:0},{default:v(({mode:p})=>[e(y)?(a(),u("div",Qe,[s("button",{type:"button",class:$(["button field-lock",{"is-dark":p=="dark"}]),onClick:_[1]||(_[1]=L(t=>y.value=!1,["stop"])),title:w.$t("twofaccounts.forms.unlock.title")},[s("span",ze,[r(I,{icon:["fas","lock"]})])],10,je)])):(a(),u("div",Re,[s("button",{type:"button",class:$(["button field-unlock",{"is-dark":p=="dark"}]),onClick:_[2]||(_[2]=L(t=>y.value=!0,["stop"])),title:w.$t("twofaccounts.forms.lock.title")},[s("span",We,[r(I,{icon:["fas","lock-open"]})])],10,Ge)]))]),_:1})):c("",!0)],2),d.fieldError!=null?(a(),E(M,{key:0,error:d.fieldError,field:d.fieldName},null,8,["error","field"])):c("",!0),d.help?(a(),u("p",{key:1,class:"help",innerHTML:w.$t(d.help)},null,8,Ze)):c("",!0)],64)}}}),Je=["onSubmit"],Xe={class:"container preview has-text-centered"},Ye={class:"columns is-mobile"},et={class:"column"},tt={key:1,class:"add-icon-button"},ot=["onClick"],lt={class:"columns is-mobile",role:"alert"},st={key:0,class:"column"},nt={class:"columns is-mobile"},at={class:"column quickform-footer"},rt={class:"field is-grouped is-grouped-centered"},it={class:"control"},ct=["onSubmit"],ut={key:0,class:"field is-grouped"},dt={class:"control"},ft=["title"],pt={class:"file-cta"},mt={class:"file-icon"},vt={class:"file-label"},ht={class:"label"},_t={class:"field is-grouped"},gt={key:0,class:"control"},yt={class:"icon is-small"},bt={class:"control is-flex"},wt={class:"file-cta"},kt={class:"file-icon"},Et={class:"file-label"},$t=["src","alt"],Vt=["onClick","aria-label"],Ft={class:"field"},It=["innerHTML"],Ct={key:2},Tt={key:0},xt={class:"title is-4 mt-5 mb-2"},Lt={class:"help mb-4"},Mt={class:"control"},St={key:0,class:"control"},Dt={__name:"CreateUpdate",props:{twofaccountId:[Number,String]},setup(d){const b=d,q=Le("2fauth"),y=Me(),w=Se(),_=Be(),I=Ne(),M=De(),p=qe(),t=W(new J({service:"",account:"",otp_type:"",icon:"",secret:"",algorithm:"",digits:null,counter:null,period:null,image:""})),U=W(new J({qrcode:null})),C=W(new J({icon:null})),ye=[{text:"TOTP",value:"totp"},{text:"HOTP",value:"hotp"},{text:"STEAM",value:"steamtotp"}],be=[{text:"6",value:6},{text:"7",value:7},{text:"8",value:8},{text:"9",value:9},{text:"10",value:10}],we=[{text:"sha1",value:"sha1"},{text:"sha256",value:"sha256"},{text:"sha512",value:"sha512"},{text:"md5",value:"md5"}],S=f(),i=f(""),B=f(!1),N=f(!1),O=f(!1),V=f(!1),P=f(!1),K=f(null),A=f(null),Q=f(null),ee=f(null),te=f(null),oe=f(null),m=Ue(()=>b.twofaccountId!=null);Oe(()=>{w.name=="editAccount"?T.get(b.twofaccountId).then(o=>{t.fill(o.data),t.setOriginal(),i.value=t.icon,O.value=!0}):M.decodedUri?(S.value=M.decodedUri,M.decodedUri=null,T.preview(S.value).then(o=>{t.fill(o.data),i.value=o.data.icon?o.data.icon:"",B.value=!0,fe().then(()=>{A.value.show()})}).catch(o=>{o.response.data.errors.uri&&(N.value=!0,O.value=!0)})):O.value=!0}),Z(i,o=>{B.value&&fe().then(()=>{A.value.icon=o})}),Z(V,o=>{var l,k;o==!1&&((l=Q.value)==null||l.clearOTP(),(k=A.value)==null||k.clearOTP())}),Z(()=>t.otp_type,(o,l)=>{o==="steamtotp"?(t.service="Steam",ie()):l==="steamtotp"&&(t.service="",F())});function ke(){m.value?Ee():le()}async function le(){t.icon=i.value;const{data:o}=await t.post("/api/v1/twofaccounts");t.errors.any()===!1&&(I.items.push(o),p.success({text:x("twofaccounts.account_created")}),y.push({name:"accounts"}))}async function Ee(){if(i.value!==t.icon){let l="";l=t.icon,t.icon=i.value,i.value=l,F()}const{data:o}=await t.put("/api/v1/twofaccounts/"+b.twofaccountId);if(t.errors.any()===!1){const l=I.items.findIndex(k=>k.id===o.id);I.items.splice(l,1,o),p.success({text:x("twofaccounts.account_updated")}),y.push({name:"accounts"})}}function $e(){t.clear(),V.value=!0,Q.value.show()}function se(){t.hasChanged()||i.value!=t.icon?confirm(x("twofaccounts.confirm.cancel"))===!0&&((!m.value||i.value!=t.icon)&&F(),y.push({name:"accounts"})):y.push({name:"accounts"})}function ne(){F(),C.icon=K.value.files[0],C.upload("/api/v1/icons",{returnError:!0}).then(o=>{i.value=o.data.filename,B.value&&(t.icon=i.value)}).catch(o=>{o.response.status!==422&&p.alert({text:o.response.data.message})})}function F(){m.value?i.value&&(i.value!==t.icon&&T.deleteIcon(i.value),i.value=""):i.value&&(T.deleteIcon(i.value),i.value="",B.value&&(t.icon=""))}function ae(o){t.counter=o.nextHotpCounter}function re(o){t.errors.set(t.extractErrors(o))}function Ve(){U.qrcode=te.value.files[0],U.upload("/api/v1/qrcode/decode",{returnError:!0}).then(o=>{S.value=o.data.data,T.preview(S.value,{returnError:!0}).then(l=>{t.fill(l.data),i.value=l.data.icon?l.data.icon:null}).catch(l=>{l.response.status===422?l.response.data.errors.uri?N.value=!0:p.alert({text:x(l.response.data.message)}):p.error(l)})}).catch(o=>{o.response.status!==422&&p.alert({text:o.response.data.message})})}function ie(){_.preferences.getOfficialIcons&&(P.value=!0,T.getLogo(t.service,{returnError:!0}).then(o=>{o.status===201?(F(),i.value=o.data.filename):p.warn({text:x("errors.no_logo_found_for_x",{service:ce(t.service)})})}).catch(()=>{p.warn({text:x("errors.no_logo_found_for_x",{service:ce(t.service)})})}).finally(()=>{P.value=!1}))}function ce(o){return o.replace(/(<([^> ]+)>)/ig,"")}return(o,l)=>{const k=h("FieldError"),D=h("FontAwesomeIcon"),j=h("VueButton"),ue=h("ButtonBackCloseCancel"),z=h("FormField"),R=h("FormToggle"),Fe=h("VueFooter"),de=h("modal"),Ie=h("FormWrapper");return a(),u("div",null,[!e(m)&&e(B)?(a(),u("form",{key:0,onSubmit:L(le,["prevent"]),onKeydown:l[1]||(l[1]=n=>e(t).onKeydown(n))},[s("div",Xe,[s("div",Ye,[s("div",et,[e(C).errors.hasAny("icon")?(a(),E(k,{key:0,error:e(C).errors.get("icon"),field:"icon",class:"help-for-file"},null,8,["error"])):c("",!0),e(i)?c("",!0):(a(),u("label",tt,[s("input",{class:"file-input",type:"file",accept:"image/*",onChange:ne,ref_key:"iconInput",ref:K},null,544),r(D,{icon:["fas","image"],size:"2x"})])),e(i)?(a(),u("button",{key:2,class:"delete delete-icon-button is-medium",onClick:L(F,["prevent"])},null,8,ot)):c("",!0),r(_e,X({ref_key:"OtpDisplayForQuickForm",ref:A},e(t).data(),{onIncrementHotp:ae,onValidationError:re,onPleaseCloseMe:l[0]||(l[0]=n=>V.value=!1)}),null,16)])]),s("div",lt,[e(t).errors.any()?(a(),u("div",st,[(a(!0),u(Y,null,pe(e(t).errors.errors,(n,G)=>(a(),u("p",{key:G,class:"help is-danger"},[s("ul",null,[(a(!0),u(Y,null,pe(n,(Ce,Te)=>(a(),u("li",{key:Te},g(Ce),1))),128))])]))),128))])):c("",!0)]),s("div",nt,[s("div",at,[s("div",rt,[s("div",it,[r(j,{isLoading:e(t).isBusy},{default:v(()=>[ve(g(o.$t("commons.save")),1)]),_:1},8,["isLoading"])]),r(ue,{action:"cancel",isText:!0,useLinkTag:!1,onCanceled:se})])])])])],40,Je)):c("",!0),e(O)?(a(),E(Ie,{key:1,title:o.$t(e(m)?"twofaccounts.forms.edit_account":"twofaccounts.forms.new_account")},{default:v(()=>[s("form",{onSubmit:L(ke,["prevent"]),onKeydown:l[12]||(l[12]=n=>e(t).onKeydown(n))},[e(m)?c("",!0):(a(),u("div",ut,[s("div",dt,[r(e(H),null,{default:v(({mode:n})=>[s("div",{role:"button",tabindex:"0",class:$(["file is-small",{"is-black":n=="dark"}]),onKeyup:l[2]||(l[2]=he(G=>e(ee).click(),["enter"]))},[s("label",{class:"file-label",title:o.$t("twofaccounts.forms.use_qrcode.title"),ref_key:"qrcodeInputLabel",ref:ee},[s("input",{"aria-hidden":"true",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:Ve,ref_key:"qrcodeInput",ref:te},null,544),s("span",pt,[s("span",mt,[r(D,{icon:["fas","qrcode"],size:"lg"})]),s("span",vt,g(o.$t("twofaccounts.forms.prefill_using_qrcode")),1)])],8,ft)],34)]),_:1})])])),e(U).errors.hasAny("qrcode")?(a(),E(k,{key:1,error:e(U).errors.get("qrcode"),field:"qrcode",class:"help-for-file"},null,8,["error"])):c("",!0),r(z,{modelValue:e(t).service,"onUpdate:modelValue":l[3]||(l[3]=n=>e(t).service=n),fieldName:"service",fieldError:e(t).errors.get("email"),isDisabled:e(t).otp_type==="steamtotp",label:"twofaccounts.service",placeholder:o.$t("twofaccounts.forms.service.placeholder"),autofocus:""},null,8,["modelValue","fieldError","isDisabled","placeholder"]),r(z,{modelValue:e(t).account,"onUpdate:modelValue":l[4]||(l[4]=n=>e(t).account=n),fieldName:"account",fieldError:e(t).errors.get("account"),label:"twofaccounts.account",placeholder:o.$t("twofaccounts.forms.account.placeholder")},null,8,["modelValue","fieldError","placeholder"]),s("label",ht,g(o.$t("twofaccounts.icon")),1),s("div",_t,[e(_).preferences.getOfficialIcons?(a(),u("div",gt,[r(e(H),null,{default:v(({mode:n})=>[r(j,{onClick:ie,color:n=="dark"?"is-dark":"",nativeType:"button","is-loading":e(P),isDisabled:!e(t).service},{default:v(()=>[s("span",yt,[r(D,{icon:["fas","globe"]})]),s("span",null,g(o.$t("twofaccounts.forms.i_m_lucky")),1)]),_:2},1032,["color","is-loading","isDisabled"])]),_:1})])):c("",!0),s("div",bt,[r(e(H),null,{default:v(({mode:n})=>[s("div",{role:"button",tabindex:"0",class:$(["file mr-3",n=="dark"?"is-dark":"is-white"]),onKeyup:l[5]||(l[5]=he(G=>e(oe).click(),["enter"]))},[s("label",{class:"file-label",ref_key:"iconInputLabel",ref:oe},[s("input",{"aria-hidden":"true",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:ne,ref_key:"iconInput",ref:K},null,544),s("span",wt,[s("span",kt,[r(D,{icon:["fas","upload"]})]),s("span",Et,g(o.$t("twofaccounts.forms.choose_image")),1)])],512)],34),e(i)?(a(),u("span",{key:0,class:$(["tag is-large",n=="dark"?"is-dark":"is-white"])},[s("img",{class:"icon-preview",src:e(q).config.subdirectory+"/storage/icons/"+e(i),alt:o.$t("twofaccounts.icon_to_illustrate_the_account")},null,8,$t),s("button",{class:"clear-selection delete is-small",onClick:L(F,["prevent"]),"aria-label":o.$t("twofaccounts.remove_icon")},null,8,Vt)],2)):c("",!0)]),_:1})])]),s("div",Ft,[e(C).errors.hasAny("icon")?(a(),E(k,{key:0,error:e(C).errors.get("icon"),field:"icon",class:"help-for-file"},null,8,["error"])):c("",!0),e(_).preferences.getOfficialIcons?(a(),u("p",{key:1,class:"help",innerHTML:o.$t("twofaccounts.forms.i_m_lucky_legend")},null,8,It)):c("",!0)]),r(R,{modelValue:e(t).otp_type,"onUpdate:modelValue":l[6]||(l[6]=n=>e(t).otp_type=n),isDisabled:e(m),choices:ye,fieldName:"otp_type",fieldError:e(t).errors.get("otp_type"),label:"twofaccounts.forms.otp_type.label",help:"twofaccounts.forms.otp_type.help",hasOffset:!0},null,8,["modelValue","isDisabled","fieldError"]),e(t).otp_type!=""?(a(),u("div",Ct,[r(ge,{isEditMode:e(m),modelValue:e(t).secret,"onUpdate:modelValue":l[7]||(l[7]=n=>e(t).secret=n),fieldName:"secret",fieldError:e(t).errors.get("secret"),label:"twofaccounts.forms.secret.label",help:"twofaccounts.forms.secret.help"},null,8,["isEditMode","modelValue","fieldError"]),e(t).otp_type!=="steamtotp"?(a(),u("div",Tt,[s("h2",xt,g(o.$t("commons.options")),1),s("p",Lt,g(o.$t("twofaccounts.forms.options_help")),1),r(R,{modelValue:e(t).digits,"onUpdate:modelValue":l[8]||(l[8]=n=>e(t).digits=n),choices:be,fieldName:"digits",fieldError:e(t).errors.get("digits"),label:"twofaccounts.forms.digits.label",help:"twofaccounts.forms.digits.help"},null,8,["modelValue","fieldError"]),r(R,{modelValue:e(t).algorithm,"onUpdate:modelValue":l[9]||(l[9]=n=>e(t).algorithm=n),choices:we,fieldName:"algorithm",fieldError:e(t).errors.get("algorithm"),label:"twofaccounts.forms.algorithm.label",help:"twofaccounts.forms.algorithm.help"},null,8,["modelValue","fieldError"]),e(t).otp_type==="totp"?(a(),E(z,{key:0,pattern:"[0-9]{1,4}",class:$("is-third-width-field"),modelValue:e(t).period,"onUpdate:modelValue":l[10]||(l[10]=n=>e(t).period=n),fieldName:"period",fieldError:e(t).errors.get("period"),label:"twofaccounts.forms.period.label",help:"twofaccounts.forms.period.help",placeholder:o.$t("twofaccounts.forms.period.placeholder")},null,8,["modelValue","fieldError","placeholder"])):c("",!0),e(t).otp_type==="hotp"?(a(),E(ge,{key:1,pattern:"[0-9]{1,4}",isEditMode:e(m),isExpanded:!1,modelValue:e(t).counter,"onUpdate:modelValue":l[11]||(l[11]=n=>e(t).counter=n),fieldName:"counter",fieldError:e(t).errors.get("counter"),label:"twofaccounts.forms.counter.label",placeholder:o.$t("twofaccounts.forms.counter.placeholder"),help:e(m)?"twofaccounts.forms.counter.help_lock":"twofaccounts.forms.counter.help"},null,8,["isEditMode","modelValue","fieldError","placeholder","help"])):c("",!0)])):c("",!0)])):c("",!0),r(Fe,{showButtons:!0},{default:v(()=>[s("p",Mt,[r(j,{id:e(m)?"btnUpdate":"btnCreate",isLoading:e(t).isBusy,class:"is-rounded"},{default:v(()=>[ve(g(e(m)?o.$t("commons.save"):o.$t("commons.create")),1)]),_:1},8,["id","isLoading"])]),e(t).otp_type&&e(t).secret?(a(),u("p",St,[s("button",{id:"btnPreview",type:"button",class:"button is-success is-rounded",onClick:$e},g(o.$t("twofaccounts.forms.test")),1)])):c("",!0),r(ue,{action:"cancel",useLinkTag:!1,onCanceled:se})]),_:1})],40,ct),r(de,{modelValue:e(V),"onUpdate:modelValue":l[14]||(l[14]=n=>me(V)?V.value=n:null)},{default:v(()=>[r(_e,X({ref_key:"OtpDisplayForAdvancedForm",ref:Q},e(t).data(),{onIncrementHotp:ae,onValidationError:re,onPleaseCloseMe:l[13]||(l[13]=n=>V.value=!1)}),null,16)]),_:1},8,["modelValue"])]),_:1},8,["title"])):c("",!0),r(de,{modelValue:e(N),"onUpdate:modelValue":l[15]||(l[15]=n=>me(N)?N.value=n:null)},{default:v(()=>[r(Ae,{qrContent:e(S)},null,8,["qrContent"])]),_:1},8,["modelValue"])])}}};export{Dt as default};
|