2FAuth/public/build/assets/CreateUpdate-erSWwknc.js
2024-11-27 12:03:02 +01:00

3 lines
17 KiB
JavaScript
Vendored

import{Z as ke,_ as De,r as f,l as h,m as n,d as u,e as s,f as e,n as T,V as Q,h as _,k,G as N,j as i,U as Te,i as c,F as ie,u as Pe,b as He,a as Ke,c as le,x as Ve,o as Ge,J as L,P as se,s as G,$ as Qe,C as ae,D as Ee,t as w,g as $e,w as Ie,L as Re,p as je,T as ze,H as A}from"./app-CzxRjCVM.js";import{F as ne}from"./Form-EFIuWKGI.js";import{_ as re}from"./OtpDisplay-ytUtG8ZN.js";import{_ as We}from"./QrContentDisplay-C2fFtz-5.js";import{u as Je}from"./bus-BNAtGMCo.js";import"./Spinner-C-V0HKYn.js";/*! 2FAuth version 5.4.3 - Copyright (c) 2024 Bubka - https://github.com/Bubka/2FAuth */const Ze=["for","innerHTML"],Xe=["disabled","id","type","value","placeholder","maxlength","aria-describedby","aria-invalid","aria-errormessage"],Ye={key:0,class:"control"},eo=["title"],oo={class:"icon"},to={key:1,class:"control"},lo=["title"],so={class:"icon has-text-danger"},ao=["id","innerHTML"],Fe=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},idSuffix:{type:String,default:""}},emits:["update:modelValue"],setup(d,{emit:R}){const p=d,{inputId:D}=ke(p.inputType,p.fieldName+p.idSuffix),{valErrorId:b}=De(p.fieldName),U=ke("legend",p.fieldName).inputId,E=f(p.isDisabled||p.isEditMode),g=f(!1),o=f(0),C=R;function $(m){let v=m.target.value;p.modelModifiers.trimAll&&(v=v.replace(/\s+/g,"")),C("update:modelValue",v)}function M(m){let v=m.target.value;g.value=v.includes(" "),C("update:modelValue",v)}function j(m){g.value=m.target.value.includes(" "),o.value+=1}return(m,v)=>{const V=h("FontAwesomeIcon"),r=h("FieldError");return n(),u(ie,null,[s("label",{for:e(D),class:"label",innerHTML:m.$t(d.label)},null,8,Ze),s("div",{class:T(["field has-addons mb-0",{"pt-3":d.hasOffset}])},[s("div",{class:T(["control",{"is-expanded":d.isExpanded}])},[(n(),u("input",Q({key:e(o),disabled:e(E),id:e(D),type:d.inputType,class:"input",value:d.modelValue,placeholder:d.placeholder},m.$attrs,{onInput:M,onChange:$,onBlur:j,maxlength:d.maxLength,"aria-describedby":d.help?e(U):void 0,"aria-invalid":d.fieldError!=null,"aria-errormessage":d.fieldError!=null?e(b):void 0}),null,16,Xe))],2),d.isEditMode?(n(),_(e(Te),{key:0},{default:k(({mode:I})=>[e(E)?(n(),u("div",Ye,[s("button",{type:"button",class:T(["button field-lock",{"is-dark":I=="dark"}]),onClick:v[0]||(v[0]=N(F=>E.value=!1,["stop"])),title:m.$t("twofaccounts.forms.unlock.title")},[s("span",oo,[i(V,{icon:["fas","lock"]})])],10,eo)])):(n(),u("div",to,[s("button",{type:"button",class:T(["button field-unlock",{"is-dark":I=="dark"}]),onClick:v[1]||(v[1]=N(F=>E.value=!0,["stop"])),title:m.$t("twofaccounts.forms.lock.title")},[s("span",so,[i(V,{icon:["fas","lock-open"]})])],10,lo)]))]),_:1})):c("",!0)],2),e(g)?(n(),_(r,{key:0,error:m.$t("twofaccounts.forms.spaces_are_ignored"),field:"spaces",alertType:"is-warning"},null,8,["error"])):c("",!0),d.fieldError!=null?(n(),_(r,{key:1,error:d.fieldError,field:d.fieldName},null,8,["error","field"])):c("",!0),d.help?(n(),u("p",{key:2,id:e(U),class:"help",innerHTML:m.$t(d.help)},null,8,ao)):c("",!0)],64)}}}),no={class:"container preview has-text-centered"},ro={class:"columns is-mobile"},io={class:"column"},co={key:1,class:"add-icon-button"},uo={class:"columns is-mobile",role:"alert"},fo={key:0,class:"column"},po={class:"columns is-mobile"},mo={class:"column quickform-footer"},vo={class:"field is-grouped is-grouped-centered"},ho={class:"control"},go={key:0,class:"field is-grouped"},yo={class:"control"},_o=["title"],bo={class:"file-cta"},wo={class:"file-icon"},ko={class:"file-label"},Vo={for:"filUploadIcon",class:"label"},Eo={class:"field is-grouped"},$o={key:0,class:"control"},Io={class:"icon is-small"},Fo={class:"control is-flex"},To={class:"file-cta"},Co={class:"file-icon"},Mo={class:"file-label"},So=["src","alt"],xo=["aria-label"],Lo={class:"field"},Ao=["innerHTML"],Uo={key:3},Oo={key:0},No={class:"title is-4 mt-5 mb-2"},Bo={class:"help mb-4"},qo={class:"control"},Do={key:0,class:"control"},jo={__name:"CreateUpdate",props:{twofaccountId:[Number,String]},setup(d){const R=Re("2fauth"),p=je(),D=Qe(),b=Pe(),U=He(),E=Je(),g=Ke(),o=le(new ne({service:"",account:"",otp_type:"",icon:"",group_id:b.preferences.defaultGroup==-1?b.preferences.activeGroup:b.preferences.defaultGroup,secret:"",algorithm:"",digits:null,counter:null,period:null,image:""})),C=le(new ne({qrcode:null})),$=le(new ne({icon:null})),M=f({otp_type:"",account:"",service:"",icon:""}),j=[{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}],v=[{text:"sha1",value:"sha1"},{text:"sha256",value:"sha256"},{text:"sha512",value:"sha512"},{text:"md5",value:"md5"}],V=f(),r=f(""),I=f(!1),F=f(!1),B=f(!1),q=f(!1),S=f(!1),z=f(!1),W=f(null),J=f(null),P=f(null),Z=f(null),ce=f(null),ue=f(null),de=f(null),X=d,y=Ve(()=>X.twofaccountId!=null),fe=Ve(()=>ze().items.map(t=>({text:t.id>0?t.name:"- "+A("groups.no_group")+" -",value:t.id})));Ge(()=>{D.name=="editAccount"?L.get(X.twofaccountId).then(t=>{o.fill(t.data),o.group_id==null&&(o.group_id=0),o.setOriginal(),r.value=o.icon,q.value=!0}):E.decodedUri?(V.value=E.decodedUri,E.decodedUri=null,b.preferences.AutoSaveQrcodedAccount?L.storeFromUri(V.value).then(t=>{xe(t.data)}).catch(t=>{t.response.data.errors.uri&&(F.value=!0,q.value=!0)}):L.preview(V.value).then(t=>{o.fill(t.data),r.value=t.data.icon?t.data.icon:"",I.value=!0,se().then(()=>{P.value.show()})}).catch(t=>{t.response.data.errors.uri&&(F.value=!0,q.value=!0)})):q.value=!0}),G(r,t=>{I.value&&se().then(()=>{P.value.icon=t})}),G(S,t=>{var l,O;t==!1&&((l=Z.value)==null||l.clearOTP(),(O=P.value)==null||O.clearOTP())}),G(B,t=>{var l;t==!1&&((l=J.value)==null||l.clearOTP(),p.push({name:"accounts"}))}),G(()=>o.otp_type,(t,l)=>{t==="steamtotp"?(o.service="Steam",ye()):l==="steamtotp"&&(o.service="",x())});function Ce(){y.value?Me():pe()}async function pe(){o.icon=r.value;const{data:t}=await o.post("/api/v1/twofaccounts");o.errors.any()===!1&&(U.items.push(t),g.success({text:A("twofaccounts.account_created")}),p.push({name:"accounts"}))}async function Me(){if(r.value!==o.icon){let l="";l=o.icon,o.icon=r.value,r.value=l,x()}const{data:t}=await o.put("/api/v1/twofaccounts/"+X.twofaccountId);if(o.errors.any()===!1){const l=U.items.findIndex(O=>O.id===t.id);U.items.splice(l,1,t),g.success({text:A("twofaccounts.account_updated")}),p.push({name:"accounts"})}}function Se(){o.clear(),S.value=!0,Z.value.show()}function xe(t){M.value.otp_type=t.otp_type,M.value.service=t.service,M.value.account=t.account,M.value.icon=t.icon,se().then(()=>{B.value=!0,J.value.show(t.id)})}function me(){o.hasChanged()||r.value!=o.icon?confirm(A("twofaccounts.confirm.cancel"))===!0&&((!y.value||r.value!=o.icon)&&x(),p.push({name:"accounts"})):p.push({name:"accounts"})}function ve(){x(),$.icon=W.value.files[0],$.upload("/api/v1/icons",{returnError:!0}).then(t=>{r.value=t.data.filename,I.value&&(o.icon=r.value)}).catch(t=>{t.response.status!==422&&g.alert({text:t.response.data.message})})}function x(){y.value?r.value&&(r.value!==o.icon&&L.deleteIcon(r.value),r.value=""):r.value&&(L.deleteIcon(r.value),r.value="",I.value&&(o.icon=""))}function he(t){o.counter=t.nextHotpCounter}function ge(t){o.errors.set(o.extractErrors(t))}function Le(){C.qrcode=ue.value.files[0],C.upload("/api/v1/qrcode/decode",{returnError:!0}).then(t=>{V.value=t.data.data,L.preview(V.value,{returnError:!0}).then(l=>{o.fill(l.data),r.value=l.data.icon?l.data.icon:null}).catch(l=>{l.response.status===422?l.response.data.errors.uri?F.value=!0:g.alert({text:A(l.response.data.message)}):g.error(l)})}).catch(t=>{t.response.status!==422&&g.alert({text:t.response.data.message})})}function ye(){b.preferences.getOfficialIcons&&(z.value=!0,L.getLogo(o.service,{returnError:!0}).then(t=>{t.status===201?(x(),r.value=t.data.filename):g.warn({text:A("errors.no_logo_found_for_x",{service:_e(o.service)})})}).catch(()=>{g.warn({text:A("errors.no_logo_found_for_x",{service:_e(o.service)})})}).finally(()=>{z.value=!1}))}function _e(t){return t.replace(/(<([^> ]+)>)/ig,"")}return(t,l)=>{const O=h("Modal"),Y=h("FieldError"),H=h("FontAwesomeIcon"),ee=h("VueButton"),be=h("ButtonBackCloseCancel"),oe=h("FormField"),Ae=h("FormSelect"),te=h("FormToggle"),Ue=h("VueFooter"),we=h("modal"),Oe=h("FormWrapper");return n(),_(e(Te),null,{default:k(({mode:K})=>[s("div",null,[e(b).preferences.AutoSaveQrcodedAccount?(n(),_(O,{key:0,modelValue:e(B),"onUpdate:modelValue":l[1]||(l[1]=a=>ae(B)?B.value=a:null)},{default:k(()=>[i(re,Q({ref_key:"OtpDisplayForAutoSave",ref:J},e(M),{onPleaseCloseMe:l[0]||(l[0]=a=>e(p).push({name:"accounts"}))}),null,16)]),_:1},8,["modelValue"])):c("",!0),!e(y)&&e(I)?(n(),u("form",{key:1,onSubmit:N(pe,["prevent"]),onKeydown:l[3]||(l[3]=a=>e(o).onKeydown(a))},[s("div",no,[s("div",ro,[s("div",io,[e($).errors.hasAny("icon")?(n(),_(Y,{key:0,error:e($).errors.get("icon"),field:"icon",class:"help-for-file"},null,8,["error"])):c("",!0),e(r)?c("",!0):(n(),u("label",co,[s("input",{inert:"",class:"file-input",type:"file",accept:"image/*",onChange:ve,ref_key:"iconInput",ref:W},null,544),i(H,{icon:["fas","image"],size:"2x"})])),e(r)?(n(),u("button",{key:2,type:"button",class:"delete delete-icon-button is-medium",onClick:N(x,["prevent"])})):c("",!0),i(re,Q({ref_key:"OtpDisplayForQuickForm",ref:P},e(o).data(),{onIncrementHotp:he,onValidationError:ge,onPleaseCloseMe:l[2]||(l[2]=a=>S.value=!1)}),null,16)])]),s("div",uo,[e(o).errors.any()?(n(),u("div",fo,[(n(!0),u(ie,null,Ee(e(o).errors.errors,(a,Ne)=>(n(),u("p",{key:Ne,class:"help is-danger"},[s("ul",null,[(n(!0),u(ie,null,Ee(a,(Be,qe)=>(n(),u("li",{key:qe},w(Be),1))),128))])]))),128))])):c("",!0)]),s("div",po,[s("div",mo,[s("div",vo,[s("div",ho,[i(ee,{isLoading:e(o).isBusy},{default:k(()=>[$e(w(t.$t("commons.save")),1)]),_:1},8,["isLoading"])]),i(be,{action:"cancel",isText:!0,isRounded:!1,useLinkTag:!1,onCanceled:me})])])])])],32)):c("",!0),e(q)?(n(),_(Oe,{key:2,title:t.$t(e(y)?"twofaccounts.forms.edit_account":"twofaccounts.forms.new_account")},{default:k(()=>[s("form",{onSubmit:N(Ce,["prevent"]),onKeydown:l[15]||(l[15]=a=>e(o).onKeydown(a))},[e(y)?c("",!0):(n(),u("div",go,[s("div",yo,[s("div",{role:"button",tabindex:"0",class:T(["file is-small",{"is-black":K=="dark"}]),onKeyup:l[4]||(l[4]=Ie(a=>e(ce).click(),["enter"]))},[s("label",{class:"file-label",title:t.$t("twofaccounts.forms.use_qrcode.title"),ref_key:"qrcodeInputLabel",ref:ce},[s("input",{inert:"",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:Le,ref_key:"qrcodeInput",ref:ue},null,544),s("span",bo,[s("span",wo,[i(H,{icon:["fas","qrcode"],size:"lg"})]),s("span",ko,w(t.$t("twofaccounts.forms.prefill_using_qrcode")),1)])],8,_o)],34)])])),e(C).errors.hasAny("qrcode")?(n(),_(Y,{key:1,error:e(C).errors.get("qrcode"),field:"qrcode",class:"help-for-file"},null,8,["error"])):c("",!0),i(oe,{modelValue:e(o).service,"onUpdate:modelValue":l[5]||(l[5]=a=>e(o).service=a),fieldName:"service",fieldError:e(o).errors.get("email"),isDisabled:e(o).otp_type==="steamtotp",label:"twofaccounts.service",placeholder:t.$t("twofaccounts.forms.service.placeholder"),autofocus:""},null,8,["modelValue","fieldError","isDisabled","placeholder"]),i(oe,{modelValue:e(o).account,"onUpdate:modelValue":l[6]||(l[6]=a=>e(o).account=a),fieldName:"account",fieldError:e(o).errors.get("account"),label:"twofaccounts.account",placeholder:t.$t("twofaccounts.forms.account.placeholder")},null,8,["modelValue","fieldError","placeholder"]),s("label",Vo,w(t.$t("twofaccounts.icon")),1),s("div",Eo,[e(b).preferences.getOfficialIcons?(n(),u("div",$o,[i(ee,{onClick:ye,color:K=="dark"?"is-dark":"",nativeType:"button","is-loading":e(z),isDisabled:!e(o).service,"aria-describedby":"lgdTryMyLuck"},{default:k(()=>[s("span",Io,[i(H,{icon:["fas","globe"]})]),s("span",null,w(t.$t("twofaccounts.forms.i_m_lucky")),1)]),_:2},1032,["color","is-loading","isDisabled"])])):c("",!0),s("div",Fo,[s("div",{role:"button",tabindex:"0",class:T(["file mr-3",K=="dark"?"is-dark":"is-white"]),onKeyup:l[7]||(l[7]=Ie(a=>e(de).click(),["enter"]))},[s("label",{for:"filUploadIcon",class:"file-label",ref_key:"iconInputLabel",ref:de},[s("input",{id:"filUploadIcon",tabindex:"-1",class:"file-input",type:"file",accept:"image/*",onChange:ve,ref_key:"iconInput",ref:W},null,544),s("span",To,[s("span",Co,[i(H,{icon:["fas","upload"]})]),s("span",Mo,w(t.$t("twofaccounts.forms.choose_image")),1)])],512)],34),e(r)?(n(),u("span",{key:0,class:T(["tag is-large",K=="dark"?"is-dark":"is-white"])},[s("img",{class:"icon-preview",src:e(R).config.subdirectory+"/storage/icons/"+e(r),alt:t.$t("twofaccounts.icon_to_illustrate_the_account")},null,8,So),s("button",{type:"button",class:"clear-selection delete is-small",onClick:N(x,["prevent"]),"aria-label":t.$t("twofaccounts.remove_icon")},null,8,xo)],2)):c("",!0)])]),s("div",Lo,[e($).errors.hasAny("icon")?(n(),_(Y,{key:0,error:e($).errors.get("icon"),field:"icon",class:"help-for-file"},null,8,["error"])):c("",!0),e(b).preferences.getOfficialIcons?(n(),u("p",{key:1,id:"lgdTryMyLuck",class:"help",innerHTML:t.$t("twofaccounts.forms.i_m_lucky_legend")},null,8,Ao)):c("",!0)]),e(fe).length>0?(n(),_(Ae,{key:2,modelValue:e(o).group_id,"onUpdate:modelValue":l[8]||(l[8]=a=>e(o).group_id=a),options:e(fe),fieldName:"group_id",label:"twofaccounts.forms.group.label",help:"twofaccounts.forms.group.help"},null,8,["modelValue","options"])):c("",!0),i(te,{modelValue:e(o).otp_type,"onUpdate:modelValue":l[9]||(l[9]=a=>e(o).otp_type=a),isDisabled:e(y),choices:j,fieldName:"otp_type",fieldError:e(o).errors.get("otp_type"),label:"twofaccounts.forms.otp_type.label",help:"twofaccounts.forms.otp_type.help",hasOffset:!0},null,8,["modelValue","isDisabled","fieldError"]),e(o).otp_type!=""?(n(),u("div",Uo,[i(Fe,{isEditMode:e(y),modelValue:e(o).secret,"onUpdate:modelValue":l[10]||(l[10]=a=>e(o).secret=a),modelModifiers:{trimAll:!0},fieldName:"secret",fieldError:e(o).errors.get("secret"),label:"twofaccounts.forms.secret.label",help:"twofaccounts.forms.secret.help"},null,8,["isEditMode","modelValue","fieldError"]),e(o).otp_type!=="steamtotp"?(n(),u("div",Oo,[s("h2",No,w(t.$t("commons.options")),1),s("p",Bo,w(t.$t("twofaccounts.forms.options_help")),1),i(te,{modelValue:e(o).digits,"onUpdate:modelValue":l[11]||(l[11]=a=>e(o).digits=a),choices:m,fieldName:"digits",fieldError:e(o).errors.get("digits"),label:"twofaccounts.forms.digits.label",help:"twofaccounts.forms.digits.help"},null,8,["modelValue","fieldError"]),i(te,{modelValue:e(o).algorithm,"onUpdate:modelValue":l[12]||(l[12]=a=>e(o).algorithm=a),choices:v,fieldName:"algorithm",fieldError:e(o).errors.get("algorithm"),label:"twofaccounts.forms.algorithm.label",help:"twofaccounts.forms.algorithm.help"},null,8,["modelValue","fieldError"]),e(o).otp_type==="totp"?(n(),_(oe,{key:0,pattern:"[0-9]{1,4}",class:T("is-third-width-field"),modelValue:e(o).period,"onUpdate:modelValue":l[13]||(l[13]=a=>e(o).period=a),fieldName:"period",fieldError:e(o).errors.get("period"),label:"twofaccounts.forms.period.label",help:"twofaccounts.forms.period.help",placeholder:t.$t("twofaccounts.forms.period.placeholder")},null,8,["modelValue","fieldError","placeholder"])):c("",!0),e(o).otp_type==="hotp"?(n(),_(Fe,{key:1,pattern:"[0-9]{1,4}",isEditMode:e(y),isExpanded:!1,modelValue:e(o).counter,"onUpdate:modelValue":l[14]||(l[14]=a=>e(o).counter=a),fieldName:"counter",fieldError:e(o).errors.get("counter"),label:"twofaccounts.forms.counter.label",placeholder:t.$t("twofaccounts.forms.counter.placeholder"),help:e(y)?"twofaccounts.forms.counter.help_lock":"twofaccounts.forms.counter.help"},null,8,["isEditMode","modelValue","fieldError","placeholder","help"])):c("",!0)])):c("",!0)])):c("",!0),i(Ue,{showButtons:!0},{default:k(()=>[s("p",qo,[i(ee,{id:e(y)?"btnUpdate":"btnCreate",isLoading:e(o).isBusy,class:"is-rounded"},{default:k(()=>[$e(w(e(y)?t.$t("commons.save"):t.$t("commons.create")),1)]),_:1},8,["id","isLoading"])]),e(o).otp_type&&e(o).secret?(n(),u("p",Do,[s("button",{id:"btnPreview",type:"button",class:"button is-success is-rounded",onClick:Se},w(t.$t("twofaccounts.forms.test")),1)])):c("",!0),i(be,{action:"cancel",useLinkTag:!1,onCanceled:me})]),_:1})],32),i(we,{modelValue:e(S),"onUpdate:modelValue":l[17]||(l[17]=a=>ae(S)?S.value=a:null)},{default:k(()=>[i(re,Q({ref_key:"OtpDisplayForAdvancedForm",ref:Z},e(o).data(),{onIncrementHotp:he,onValidationError:ge,onPleaseCloseMe:l[16]||(l[16]=a=>S.value=!1)}),null,16)]),_:1},8,["modelValue"])]),_:2},1032,["title"])):c("",!0),i(we,{modelValue:e(F),"onUpdate:modelValue":l[18]||(l[18]=a=>ae(F)?F.value=a:null)},{default:k(()=>[i(We,{qrContent:e(V)},null,8,["qrContent"])]),_:1},8,["modelValue"])])]),_:1})}}};export{jo as default};
//# sourceMappingURL=CreateUpdate-erSWwknc.js.map