From 8d1199cc0d2bdf52c177f791ee30e86d343e000a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Fri, 18 Sep 2020 16:27:43 +0200 Subject: [PATCH] Fix enable/disable, fix improper config publish - [Fix] Enabling/disabling of the magic link usage was not saved correctly - [Fix] Publishing of config file --- public/js/statamic-magiclink.js | 2 +- resources/js/components/SettingsComponent.vue | 12 ++++++------ resources/views/cp/settings/index.blade.php | 2 +- src/Http/Controllers/Cp/SettingsController.php | 2 +- src/Repositories/SettingsRepository.php | 2 +- src/ServiceProvider.php | 2 ++ 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/public/js/statamic-magiclink.js b/public/js/statamic-magiclink.js index f93f699..d76a130 100644 --- a/public/js/statamic-magiclink.js +++ b/public/js/statamic-magiclink.js @@ -1 +1 @@ -!function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s=0)}([function(e,t,r){r(1),e.exports=r(2)},function(e,t,r){"use strict";r.r(t);function i(e,t,r,i,n,s,o,a){var l,c="function"==typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=r,c._compiled=!0),i&&(c.functional=!0),s&&(c._scopeId="data-v-"+s),o?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),n&&n.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},c._ssrRegister=l):n&&(l=a?function(){n.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:n),l)if(c.functional){c._injectStyles=l;var u=c.render;c.render=function(e,t){return l.call(t),u(e,t)}}else{var d=c.beforeCreate;c.beforeCreate=d?[].concat(d,l):[l]}return{exports:e,options:c}}var n=i({props:{action:String,method:{type:String,required:!0}},data:function(){return{error:null,errors:{},email:""}},computed:{hasErrors:function(){return this.error||Object.keys(this.errors).length},payload:function(){return{email:this.email}}},methods:{clearErrors:function(){this.error=null,this.errors={}},send:function(){var e=this;this.clearErrors(),this.$axios[this.method](this.action,this.payload).then((function(e){window.location=e.data.redirect})).catch((function(t){if(t.response&&422===t.response.status){var r=t.response.data,i=r.message,n=r.errors;e.error=i,e.errors=n,e.$toast.error(i)}else e.$toast.error(__("magiclink::web.unable_to_send"))}))}}},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[r("publish-fields-container",{staticClass:"p-0"},[r("form-group",{staticClass:"p-0",attrs:{handle:"email",display:e.__("magiclink::web.email_address"),errors:e.errors.email,focus:!0},model:{value:e.email,callback:function(t){e.email=t},expression:"email"}})],1),e._v(" "),r("div",{staticClass:"py-2 flex justify-between"},[r("button",{staticClass:"btn-primary w-full",attrs:{type:"submit"},on:{click:e.send}},[e._v(e._s(e.__("magiclink::web.login_magic_link")))])])],1)}),[],!1,null,null,null).exports,s=i({props:{action:String,initialExpireTime:{type:Number,required:!0},initialIsEnabled:{type:Boolean,required:!0},indexUrl:{type:String,required:!0},method:{type:String,required:!0}},data:function(){return{error:null,errors:{},isEnabled:this.initialIsEnabled,expireTime:this.initialExpireTime}},computed:{hasErrors:function(){return this.error||Object.keys(this.errors).length},payload:function(){return{isEnabled:this.isEnabled,expireTime:this.expireTime}}},methods:{clearErrors:function(){this.error=null,this.errors={}},save:function(){var e=this;this.clearErrors(),this.$axios[this.method](this.action,this.payload).then((function(e){window.location=e.data.redirect})).catch((function(t){if(t.response&&422===t.response.status){var r=t.response.data,i=r.message,n=r.errors;e.error=i,e.errors=n,e.$toast.error(i)}else e.$toast.error(__("magiclink::cp.unable_to_save"))}))}},mounted:function(){var e=this;this.$keys.bindGlobal(["mod+s"],(function(t){t.preventDefault(),e.save()}))}},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[r("publish-fields-container",{staticClass:"card p-0 mb-3 configure-section"},[r("form-group",{staticClass:"toggle-fieldtype",attrs:{fieldtype:"toggle",handle:"isEnabled",display:e.__("magiclink::cp.settings.ml_enabled"),instructions:e.__("magiclink::cp.settings.ml_enabled_instructions")},model:{value:e.isEnabled,callback:function(t){e.isEnabled=t},expression:"isEnabled"}}),e._v(" "),r("form-group",{staticClass:"border-b",attrs:{handle:"expireTime",display:e.__("magiclink::cp.settings.ml_expire_time"),errors:e.errors.expireTime,instructions:e.__("magiclink::cp.settings.ml_expire_time_instructions")},model:{value:e.expireTime,callback:function(t){e.expireTime=t},expression:"expireTime"}})],1),e._v(" "),r("div",{staticClass:"py-2 mt-3 border-t flex justify-between"},[r("a",{staticClass:"btn",attrs:{href:e.indexUrl},domProps:{textContent:e._s(e.__("Cancel"))}}),e._v(" "),r("button",{staticClass:"btn-primary",attrs:{type:"submit"},on:{click:e.save}},[e._v(e._s(e.__("Save")))])])],1)}),[],!1,null,null,null).exports;Statamic.booting((function(){Statamic.$components.register("magiclink-settings",s),Statamic.$components.register("magiclink-send-link",n)}))},function(e,t){}]); \ No newline at end of file +!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/",r(r.s=0)}([function(e,t,r){r(1),e.exports=r(2)},function(e,t,r){"use strict";r.r(t);function n(e,t,r,n,i,s,o,a){var l,c="function"==typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=r,c._compiled=!0),n&&(c.functional=!0),s&&(c._scopeId="data-v-"+s),o?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},c._ssrRegister=l):i&&(l=a?function(){i.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:i),l)if(c.functional){c._injectStyles=l;var u=c.render;c.render=function(e,t){return l.call(t),u(e,t)}}else{var d=c.beforeCreate;c.beforeCreate=d?[].concat(d,l):[l]}return{exports:e,options:c}}var i=n({props:{action:String,method:{type:String,required:!0}},data:function(){return{error:null,errors:{},email:""}},computed:{hasErrors:function(){return this.error||Object.keys(this.errors).length},payload:function(){return{email:this.email}}},methods:{clearErrors:function(){this.error=null,this.errors={}},send:function(){var e=this;this.clearErrors(),this.$axios[this.method](this.action,this.payload).then((function(e){window.location=e.data.redirect})).catch((function(t){if(t.response&&422===t.response.status){var r=t.response.data,n=r.message,i=r.errors;e.error=n,e.errors=i,e.$toast.error(n)}else e.$toast.error(__("magiclink::web.unable_to_send"))}))}}},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[r("publish-fields-container",{staticClass:"p-0"},[r("form-group",{staticClass:"p-0",attrs:{handle:"email",display:e.__("magiclink::web.email_address"),errors:e.errors.email,focus:!0},model:{value:e.email,callback:function(t){e.email=t},expression:"email"}})],1),e._v(" "),r("div",{staticClass:"py-2 flex justify-between"},[r("button",{staticClass:"btn-primary w-full",attrs:{type:"submit"},on:{click:e.send}},[e._v(e._s(e.__("magiclink::web.login_magic_link")))])])],1)}),[],!1,null,null,null).exports,s=n({props:{action:String,initialExpireTime:{type:Number,required:!0},initialEnabled:{type:Boolean,required:!0},indexUrl:{type:String,required:!0},method:{type:String,required:!0}},data:function(){return{error:null,errors:{},enabled:this.initialEnabled,expireTime:this.initialExpireTime}},computed:{hasErrors:function(){return this.error||Object.keys(this.errors).length},payload:function(){return{enabled:this.enabled,expireTime:this.expireTime}}},methods:{clearErrors:function(){this.error=null,this.errors={}},save:function(){var e=this;this.clearErrors(),this.$axios[this.method](this.action,this.payload).then((function(e){window.location=e.data.redirect})).catch((function(t){if(t.response&&422===t.response.status){var r=t.response.data,n=r.message,i=r.errors;e.error=n,e.errors=i,e.$toast.error(n)}else e.$toast.error(__("magiclink::cp.unable_to_save"))}))}},mounted:function(){var e=this;this.$keys.bindGlobal(["mod+s"],(function(t){t.preventDefault(),e.save()}))}},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[r("publish-fields-container",{staticClass:"card p-0 mb-3 configure-section"},[r("form-group",{staticClass:"toggle-fieldtype",attrs:{fieldtype:"toggle",handle:"enabled",display:e.__("magiclink::cp.settings.ml_enabled"),instructions:e.__("magiclink::cp.settings.ml_enabled_instructions")},model:{value:e.enabled,callback:function(t){e.enabled=t},expression:"enabled"}}),e._v(" "),r("form-group",{staticClass:"border-b",attrs:{handle:"expireTime",display:e.__("magiclink::cp.settings.ml_expire_time"),errors:e.errors.expireTime,instructions:e.__("magiclink::cp.settings.ml_expire_time_instructions")},model:{value:e.expireTime,callback:function(t){e.expireTime=t},expression:"expireTime"}})],1),e._v(" "),r("div",{staticClass:"py-2 mt-3 border-t flex justify-between"},[r("a",{staticClass:"btn",attrs:{href:e.indexUrl},domProps:{textContent:e._s(e.__("Cancel"))}}),e._v(" "),r("button",{staticClass:"btn-primary",attrs:{type:"submit"},on:{click:e.save}},[e._v(e._s(e.__("Save")))])])],1)}),[],!1,null,null,null).exports;Statamic.booting((function(){Statamic.$components.register("magiclink-settings",s),Statamic.$components.register("magiclink-send-link",i)}))},function(e,t){}]); \ No newline at end of file diff --git a/resources/js/components/SettingsComponent.vue b/resources/js/components/SettingsComponent.vue index d0e9796..7b54cda 100644 --- a/resources/js/components/SettingsComponent.vue +++ b/resources/js/components/SettingsComponent.vue @@ -5,15 +5,15 @@ diff --git a/src/Http/Controllers/Cp/SettingsController.php b/src/Http/Controllers/Cp/SettingsController.php index af4ca62..ef57faa 100644 --- a/src/Http/Controllers/Cp/SettingsController.php +++ b/src/Http/Controllers/Cp/SettingsController.php @@ -28,7 +28,7 @@ public function update(Request $request) $this->authorize('view settings'); $request->validate([ - 'isEnabled' => ['required', 'boolean'], + 'enabled' => ['required', 'boolean'], 'expireTime' => ['required', 'numeric'], ]); diff --git a/src/Repositories/SettingsRepository.php b/src/Repositories/SettingsRepository.php index 8f06309..da2eaba 100644 --- a/src/Repositories/SettingsRepository.php +++ b/src/Repositories/SettingsRepository.php @@ -22,7 +22,7 @@ public function __construct(Filesystem $files) $this->path = storage_path('statamic-magiclink/settings.yaml'); $this->defaultValues = [ - self::IS_ENABLED_KEY => true, + self::IS_ENABLED_KEY => false, self::EXPIRE_TIME_KEY => config('statamic-magiclink.expire_time'), ]; } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 27e3ea2..798da0b 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -56,6 +56,8 @@ public function boot() { public function register() { + $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'statamic-magiclink'); + /* * Swap login controller to be able to inject custom template. */