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