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