2FAuth/public/build/assets/CreateUpdate-CdA-dxxn.js
2024-10-27 07:35:17 +01:00

2 lines
16 KiB
JavaScript
Vendored

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