-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
1 lines (1 loc) · 6.77 KB
/
index.js
1
(function () {var a={data:function(){return{code:"",isLoading:!1,issue:"",require2fa:!1,user:{email:"",password:"",long:!1},tfa_session_id:""}},computed:{fields:function(){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:function(){return{name:"code",label:"Authentication code",minLength:6,maxLength:6,counter:!1}}},methods:{login:function(){this.issue=null,this.isLoading=!0,this.require2fa?this.auth2FA():this.auth()},auth:function(){var t=this;this.$api.post("kirby-2fa/auth/login",this.user).then(function(i){var s=i.code,e=i.user,a=i.tfa_session_id;202===s?(t.require2fa=!0,t.tfa_session_id=a):200===s&&e&&t.initialize(e)}).catch(function(i){var s=i.message;t.issue=s}).finally(function(){t.isLoading=!1})},auth2FA:function(){var t=this;this.$api.post("kirby-2fa/auth/code",{tfa_session_id:this.tfa_session_id,long:this.user.long,code:this.code}).then(function(i){i.code,i.status;var s=i.user;t.initialize(s)}).catch(function(i){t.issue=i.message,t.isLoading=!1})},initialize:function(t){var i=this;this.$store.dispatch("user/current",t),this.$store.dispatch("translation/activate",t.language,{root:!0}),this.$router.push(this.$store.state.path||"/"),this.$store.dispatch("system/load",!0).then(function(){i.$store.dispatch("notification/success",i.$t("welcome")),i.isLoading=!1})}}};if(typeof a==="function"){a=a.options}Object.assign(a,function(){var render=function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c("form",{staticClass:"k-login-form",on:{"submit":function($event){$event.preventDefault();return _vm.login($event)}}},[_c("h1",{staticClass:"k-offscreen"},[_vm._v(_vm._s(_vm.$t("login")))]),_vm._v(" "),_vm.issue?_c("div",{staticClass:"k-login-alert",on:{"click":function($event){_vm.issue=null}}},[_c("span",[_vm._v(_vm._s(_vm.issue))]),_vm._v(" "),_c("k-icon",{attrs:{"type":"alert"}})],1):_vm._e(),_vm._v(" "),_vm.require2fa?[_c("k-text-field",_vm._b({model:{value:_vm.code,callback:function($$v){_vm.code=$$v},expression:"code"}},"k-text-field",_vm.codeField,false)),_vm._v(" "),_c("div",{staticClass:"k-login-buttons"},[_c("k-button",{staticClass:"k-login-button",attrs:{"icon":"check","type":"submit"}},[_vm._v(" "+_vm._s(_vm.$t("login"))+" "),_vm.isLoading?[_vm._v("\u2026")]:_vm._e()],2)],1)]:[_c("k-fieldset",{attrs:{"novalidate":true,"fields":_vm.fields},model:{value:_vm.user,callback:function($$v){_vm.user=$$v},expression:"user"}}),_vm._v(" "),_c("div",{staticClass:"k-login-buttons"},[_c("span",{staticClass:"k-login-checkbox"},[_c("k-checkbox-input",{attrs:{"value":_vm.user.long,"label":_vm.$t("login.remember")},on:{"input":function($event){_vm.user.long=$event}}})],1),_vm._v(" "),_c("k-button",{staticClass:"k-login-button",attrs:{"icon":"check","type":"submit"}},[_vm._v(" "+_vm._s(_vm.$t("login"))+" "),_vm.isLoading?[_vm._v("\u2026")]:_vm._e()],2)],1)]],2)};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:null,functional:undefined}}());var b={props:{label:String,userHasTwoFactorAuth:Boolean},data:function(){return{isLoading:!1,auth:void 0,code:"",Kbox:{text:null,theme:"negative"}}},methods:{getSecret:function(){var e=this;this.isNotTheCurrentUserPage||(this.$refs.enableDialog.open(),this.$api.post("kirby-2fa/secret").then(function(t){e.auth=t}).catch(function(e){}))},verifyCode:function(){var e=this;this.isNotTheCurrentUserPage||(this.isLoading=!0,this.Kbox.text=null,this.$api.post("kirby-2fa/verify",{code:this.code}).then(function(t){var i=t.verify;i?(e.userHasTwoFactorAuth=i,e.$refs.enableDialog.close()):e.Kbox.text="Incorrect code",e.isLoading=!1,e.code=""}).catch(function(e){}))},disabletfa:function(){var e=this;this.isNotTheCurrentUserPage||(this.isLoading=!0,this.$api.post("kirby-2fa/disable").then(function(t){var i=t.disabled;i&&(e.userHasTwoFactorAuth=!i,e.$refs.disableDialog.close()),e.isLoading=!1}).catch(function(e){}))}},computed:{isNotTheCurrentUserPage:function(){return"User"===this.$route.name&&this.$route.params.id!=this.$store.state.user.current.id},codeField:function(){return{name:"code",label:"The code shown in your app",minLength:6,maxLength:6,counter:!1}}}};if(typeof b==="function"){b=b.options}Object.assign(b,function(){var render=function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c("div",[!_vm.userHasTwoFactorAuth?_c("k-button",{attrs:{"icon":"lock","disabled":_vm.isNotTheCurrentUserPage},on:{"click":_vm.getSecret}},[_vm._v("Enable 2fa")]):_c("k-button",{attrs:{"icon":"unlock","theme":"negative","disabled":_vm.isNotTheCurrentUserPage},on:{"click":function($event){return _vm.$refs.disableDialog.open()}}},[_vm._v("Disable 2fa")]),_vm._v(" "),_c("k-dialog",{ref:"enableDialog",attrs:{"size":"medium"}},[_vm.auth?[_c("k-text",{staticClass:"mg-b-lg",attrs:{"size":"large"}},[_c("strong",[_vm._v("Enabling two factor authentication")])]),_vm._v(" "),_c("ol",{staticClass:"mg-b-lg o-list"},[_c("li",[_vm._v("Open your authenticator app.")]),_vm._v(" "),_c("li",[_vm._v("Add an account and scan the QR code shown here.")])]),_vm._v(" "),_c("img",{staticClass:"mg-b-lg",attrs:{"src":_vm.auth.qr,"width":"140","alt":"QR code"}}),_vm._v(" "),_c("ol",{staticClass:"mg-b-lg o-list",attrs:{"start":"3"}},[_c("li",[_vm._v("Enter the code generated by your authenticator app.")])]),_vm._v(" "),_c("k-text-field",_vm._b({staticClass:"mg-b-md",model:{value:_vm.code,callback:function($$v){_vm.code=$$v},expression:"code"}},"k-text-field",_vm.codeField,false)),_vm._v(" "),_vm.Kbox.text?_c("k-box",_vm._b({staticClass:"mg-b-md"},"k-box",_vm.Kbox,false)):_vm._e()]:[_c("k-icon",{staticClass:"loader",attrs:{"type":"loader"}})],_vm._v(" "),_c("template",{slot:"footer"},[_c("k-button-group",[_c("k-button",{attrs:{"icon":"cancel"},on:{"click":function($event){return _vm.$refs.enableDialog.close()}}},[_vm._v("Cancel")]),_vm._v(" "),_vm.auth?_c("k-button",{attrs:{"icon":"check","theme":"positive"},on:{"click":_vm.verifyCode}},[_vm._v(" Verify code "),_vm.isLoading?[_vm._v("\u2026")]:_vm._e()],2):_vm._e()],1)],1)],2),_vm._v(" "),_c("k-dialog",{ref:"disableDialog"},[_c("k-text",{staticClass:"mg-b-md"},[_vm._v("Are you sure that you want to disable two factor authentication?")]),_vm._v(" "),_c("template",{slot:"footer"},[_c("k-button-group",[_c("k-button",{attrs:{"icon":"cancel"},on:{"click":function($event){return _vm.$refs.disableDialog.close()}}},[_vm._v("Cancel")]),_vm._v(" "),_c("k-button",{attrs:{"icon":"check","theme":"negative"},on:{"click":_vm.disabletfa}},[_vm._v(" Disable "),_vm.isLoading?[_vm._v("\u2026")]:_vm._e()],2)],1)],1)],2)],1)};var staticRenderFns=[];return{render:render,staticRenderFns:staticRenderFns,_compiled:true,_scopeId:"data-v-cfb458",functional:undefined}}());panel.plugin("graphicmarket/kirby-2fa",{login:a,fields:{"2fa":b}});})();