forked from graphicmarket/kirby-2fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1 lines (1 loc) · 6.41 KB
/
index.js
1
(function(){"use strict";const w="";function l(s,e,t,i,r,c,u,y){var a=typeof s=="function"?s.options:s;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),i&&(a.functional=!0),c&&(a._scopeId="data-v-"+c);var n;if(u?(n=function(o){o=o||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!o&&typeof __VUE_SSR_CONTEXT__<"u"&&(o=__VUE_SSR_CONTEXT__),r&&r.call(this,o),o&&o._registeredComponents&&o._registeredComponents.add(u)},a._ssrRegister=n):r&&(n=y?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),n)if(a.functional){a._injectStyles=n;var L=a.render;a.render=function(x,h){return n.call(h),L(x,h)}}else{var d=a.beforeCreate;a.beforeCreate=d?[].concat(d,n):[n]}return{exports:s,options:a}}const f={data(){return{code:"",isLoading:!1,issue:"",require2fa:!1,user:{email:"",password:"",long:!1},tfa_session_id:""}},computed:{fields(){return{email:{autofocus:!0,label:this.$t("email"),type:"email",required:!0,link:!1},password:{label:this.$t("password"),type:"password",minLength:8,required:!0,autocomplete:"current-password",counter:!1}}},codeField(){return{name:"code",label:"Authentication code",minLength:6,maxLength:6,counter:!1}}},methods:{login(){this.issue=null,this.isLoading=!0,this.require2fa?this.auth2FA():this.auth()},auth(){this.$api.post("kirby-2fa/auth/login",this.user).then(({code:s,user:e,tfa_session_id:t})=>{s===202?(this.require2fa=!0,this.tfa_session_id=t):s===200&&e&&this.initialize(e)}).catch(({message:s})=>{this.issue=s}).finally(()=>{this.isLoading=!1})},auth2FA(){this.$api.post("kirby-2fa/auth/code",{tfa_session_id:this.tfa_session_id,long:this.user.long,code:this.code}).then(({code:s,status:e,user:t})=>{this.initialize(t)}).catch(s=>{this.issue=s.message,this.isLoading=!1})},initialize(s){this.$store.dispatch("user/current",s),this.$store.dispatch("translation/activate",s.language,{root:!0}),this.$router.push(this.$store.state.path||"/"),this.$store.dispatch("system/load",!0).then(()=>{this.$store.dispatch("notification/success",this.$t("welcome")),this.isLoading=!1})}}};var _=function(){var e=this,t=e._self._c;return t("form",{staticClass:"k-login-form",on:{submit:function(i){return i.preventDefault(),e.login.apply(null,arguments)}}},[t("h1",{staticClass:"k-offscreen"},[e._v(e._s(e.$t("login")))]),e.issue?t("div",{staticClass:"k-login-alert",on:{click:function(i){e.issue=null}}},[t("span",[e._v(e._s(e.issue))]),t("k-icon",{attrs:{type:"alert"}})],1):e._e(),e.require2fa?[t("k-text-field",e._b({model:{value:e.code,callback:function(i){e.code=i},expression:"code"}},"k-text-field",e.codeField,!1)),t("div",{staticClass:"k-login-buttons"},[t("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[e._v(" "+e._s(e.$t("login"))+" "),e.isLoading?[e._v("\u2026")]:e._e()],2)],1)]:[t("k-fieldset",{attrs:{novalidate:!0,fields:e.fields},model:{value:e.user,callback:function(i){e.user=i},expression:"user"}}),t("div",{staticClass:"k-login-buttons"},[t("span",{staticClass:"k-login-checkbox"},[t("k-checkbox-input",{attrs:{value:e.user.long,label:e.$t("login.remember")},on:{input:function(i){e.user.long=i}}})],1),t("k-button",{staticClass:"k-login-button",attrs:{icon:"check",type:"submit"}},[e._v(" "+e._s(e.$t("login"))+" "),e.isLoading?[e._v("\u2026")]:e._e()],2)],1)]],2)},g=[],p=l(f,_,g,!1,null,null,null,null);const b=p.exports,T="",v={props:{label:String,userHasTwoFactorAuth:Boolean},data(){return{isLoading:!1,auth:void 0,code:"",Kbox:{text:null,theme:"negative"}}},methods:{getSecret(){this.isNotTheCurrentUserPage||(this.$refs.enableDialog.open(),this.$api.post("kirby-2fa/secret").then(s=>{this.auth=s}).catch(s=>{}))},verifyCode(){this.isNotTheCurrentUserPage||(this.isLoading=!0,this.Kbox.text=null,this.$api.post("kirby-2fa/verify",{code:this.code}).then(({verify:s})=>{s?(this.userHasTwoFactorAuth=s,this.$refs.enableDialog.close()):this.Kbox.text="Incorrect code",this.isLoading=!1,this.code=""}).catch(s=>{}))},disabletfa(){this.isNotTheCurrentUserPage||(this.isLoading=!0,this.$api.post("kirby-2fa/disable").then(({disabled:s})=>{s&&(this.userHasTwoFactorAuth=!s,this.$refs.disableDialog.close()),this.isLoading=!1}).catch(s=>{}))}},computed:{isNotTheCurrentUserPage(){return this.$route.name==="User"&&this.$route.params.id!=this.$store.state.user.current.id},codeField(){return{name:"code",label:"The code shown in your app",minLength:6,maxLength:6,counter:!1}}}};var m=function(){var e=this,t=e._self._c;return t("div",[e.userHasTwoFactorAuth?t("k-button",{attrs:{icon:"unlock",theme:"negative",disabled:e.isNotTheCurrentUserPage},on:{click:function(i){return e.$refs.disableDialog.open()}}},[e._v("Disable 2fa")]):t("k-button",{attrs:{icon:"lock",disabled:e.isNotTheCurrentUserPage},on:{click:e.getSecret}},[e._v("Enable 2fa")]),t("k-dialog",{ref:"enableDialog",attrs:{size:"medium"}},[e.auth?[t("k-text",{staticClass:"mg-b-lg",attrs:{size:"large"}},[t("strong",[e._v("Enabling two factor authentication")])]),t("ol",{staticClass:"mg-b-lg o-list"},[t("li",[e._v("Open your authenticator app.")]),t("li",[e._v("Add an account and scan the QR code shown here.")])]),t("img",{staticClass:"mg-b-lg",attrs:{src:e.auth.qr,width:"140",alt:"QR code"}}),t("ol",{staticClass:"mg-b-lg o-list",attrs:{start:"3"}},[t("li",[e._v("Enter the code generated by your authenticator app.")])]),t("k-text-field",e._b({staticClass:"mg-b-md",model:{value:e.code,callback:function(i){e.code=i},expression:"code"}},"k-text-field",e.codeField,!1)),e.Kbox.text?t("k-box",e._b({staticClass:"mg-b-md"},"k-box",e.Kbox,!1)):e._e()]:[t("k-icon",{staticClass:"loader",attrs:{type:"loader"}})],t("template",{slot:"footer"},[t("k-button-group",[t("k-button",{attrs:{icon:"cancel"},on:{click:function(i){return e.$refs.enableDialog.close()}}},[e._v("Cancel")]),e.auth?t("k-button",{attrs:{icon:"check",theme:"positive"},on:{click:e.verifyCode}},[e._v(" Verify code "),e.isLoading?[e._v("\u2026")]:e._e()],2):e._e()],1)],1)],2),t("k-dialog",{ref:"disableDialog"},[t("k-text",{staticClass:"mg-b-md"},[e._v("Are you sure that you want to disable two factor authentication?")]),t("template",{slot:"footer"},[t("k-button-group",[t("k-button",{attrs:{icon:"cancel"},on:{click:function(i){return e.$refs.disableDialog.close()}}},[e._v("Cancel")]),t("k-button",{attrs:{icon:"check",theme:"negative"},on:{click:e.disabletfa}},[e._v(" Disable "),e.isLoading?[e._v("\u2026")]:e._e()],2)],1)],1)],2)],1)},k=[],$=l(v,m,k,!1,null,"137bfcc7",null,null);const C=$.exports;panel.plugin("graphicmarket/kirby-2fa",{login:b,fields:{"2fa":C}})})();