mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 09:14:27 +08:00
make "create an account" link disabled when user registration is disabled in config
This commit is contained in:
+14
-5
@@ -78,8 +78,9 @@ func startWebServer(c *cli.Context) error {
|
|||||||
router.NoRoute(bindApi(api.Default.ApiNotFound))
|
router.NoRoute(bindApi(api.Default.ApiNotFound))
|
||||||
router.NoMethod(bindApi(api.Default.MethodNotAllowed))
|
router.NoMethod(bindApi(api.Default.MethodNotAllowed))
|
||||||
|
|
||||||
router.StaticFile("/mobile", filepath.Join(config.StaticRootPath, "mobile.html"))
|
router.GET("/", func(c *gin.Context) {
|
||||||
router.StaticFile("/desktop", filepath.Join(config.StaticRootPath, "desktop.html"))
|
c.Redirect(http.StatusMovedPermanently, "/mobile/")
|
||||||
|
})
|
||||||
|
|
||||||
router.StaticFile("robots.txt", filepath.Join(config.StaticRootPath, "robots.txt"))
|
router.StaticFile("robots.txt", filepath.Join(config.StaticRootPath, "robots.txt"))
|
||||||
router.Static("/js", filepath.Join(config.StaticRootPath, "js"))
|
router.Static("/js", filepath.Join(config.StaticRootPath, "js"))
|
||||||
@@ -87,9 +88,17 @@ func startWebServer(c *cli.Context) error {
|
|||||||
router.Static("/img", filepath.Join(config.StaticRootPath, "img"))
|
router.Static("/img", filepath.Join(config.StaticRootPath, "img"))
|
||||||
router.Static("/fonts", filepath.Join(config.StaticRootPath, "fonts"))
|
router.Static("/fonts", filepath.Join(config.StaticRootPath, "fonts"))
|
||||||
|
|
||||||
router.GET("/", func(c *gin.Context) {
|
mobileEntryRoute := router.Group("/mobile")
|
||||||
c.Redirect(http.StatusMovedPermanently, "/mobile")
|
mobileEntryRoute.Use(bindMiddleware(middlewares.ServerSettingsCookie(config)))
|
||||||
})
|
{
|
||||||
|
mobileEntryRoute.StaticFile("/", filepath.Join(config.StaticRootPath, "mobile.html"))
|
||||||
|
}
|
||||||
|
|
||||||
|
desktopEntryRoute := router.Group("/desktop")
|
||||||
|
desktopEntryRoute.Use(bindMiddleware(middlewares.ServerSettingsCookie(config)))
|
||||||
|
{
|
||||||
|
desktopEntryRoute.StaticFile("/", filepath.Join(config.StaticRootPath, "desktop.html"))
|
||||||
|
}
|
||||||
|
|
||||||
apiRoute := router.Group("/api")
|
apiRoute := router.Group("/api")
|
||||||
|
|
||||||
|
|||||||
Generated
+5
@@ -6755,6 +6755,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"js-cookie": {
|
||||||
|
"version": "2.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-2.2.1.tgz",
|
||||||
|
"integrity": "sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ=="
|
||||||
|
},
|
||||||
"js-message": {
|
"js-message": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"framework7": "^5.7.13",
|
"framework7": "^5.7.13",
|
||||||
"framework7-icons": "^3.0.1",
|
"framework7-icons": "^3.0.1",
|
||||||
"framework7-vue": "^5.7.13",
|
"framework7-vue": "^5.7.13",
|
||||||
|
"js-cookie": "^2.2.1",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-i18n": "^8.22.0"
|
"vue-i18n": "^8.22.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mayswind/lab/pkg/core"
|
||||||
|
"github.com/mayswind/lab/pkg/settings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const SETTINGS_COOKIE_NAME = "ACP_SETTINGS"
|
||||||
|
|
||||||
|
func ServerSettingsCookie(config *settings.Config) core.MiddlewareHandlerFunc {
|
||||||
|
return func(c *core.Context) {
|
||||||
|
settingsArr := []string{
|
||||||
|
buildBooleanSetting("r", config.EnableUserRegister),
|
||||||
|
}
|
||||||
|
|
||||||
|
bundledSettings := strings.Join(settingsArr, "_")
|
||||||
|
c.SetCookie(SETTINGS_COOKIE_NAME, bundledSettings, config.TokenExpiredTime, "", "", false, false)
|
||||||
|
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildBooleanSetting(key string, value bool) string {
|
||||||
|
if value {
|
||||||
|
return fmt.Sprintf("%s.1", key)
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%s.0", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-1
@@ -1,4 +1,8 @@
|
|||||||
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
const settingsLocalStorageKey = 'lab_user_settings';
|
const settingsLocalStorageKey = 'lab_user_settings';
|
||||||
|
const serverSettingsCookieKey = 'ACP_SETTINGS';
|
||||||
|
|
||||||
const defaultSettings = {
|
const defaultSettings = {
|
||||||
lang: 'en'
|
lang: 'en'
|
||||||
};
|
};
|
||||||
@@ -37,7 +41,23 @@ function setOption(key, value) {
|
|||||||
return setSettings(settings);
|
return setSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getServerSetting(key) {
|
||||||
|
const settings = Cookies.get(serverSettingsCookieKey) || '';
|
||||||
|
const settingsArr = settings.split('_');
|
||||||
|
|
||||||
|
for (let i = 0; i < settingsArr.length; i++) {
|
||||||
|
const pairs = settingsArr[i].split('.');
|
||||||
|
|
||||||
|
if (pairs[0] === key) {
|
||||||
|
return pairs[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getLanguage: () => getOriginalOption('lang'),
|
getLanguage: () => getOriginalOption('lang'),
|
||||||
setLanguage: value => setOption('lang', value)
|
setLanguage: value => setOption('lang', value),
|
||||||
|
isUserRegistrationEnabled: () => getServerSetting('r') === '1'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ Vue.prototype.$setLanguage = function (locale) {
|
|||||||
document.querySelector('html').setAttribute('lang', locale);
|
document.querySelector('html').setAttribute('lang', locale);
|
||||||
return locale;
|
return locale;
|
||||||
};
|
};
|
||||||
|
Vue.prototype.$isUserRegistrationEnabled = settings.isUserRegistrationEnabled;
|
||||||
|
|
||||||
Vue.prototype.$alert = function (message, confirmCallback) {
|
Vue.prototype.$alert = function (message, confirmCallback) {
|
||||||
let parameters = {};
|
let parameters = {};
|
||||||
|
|
||||||
@@ -84,6 +86,7 @@ Vue.prototype.$toast = function (message, timeout) {
|
|||||||
closeTimeout: timeout || 1500
|
closeTimeout: timeout || 1500
|
||||||
}).open();
|
}).open();
|
||||||
};
|
};
|
||||||
|
|
||||||
Vue.prototype.$services = services;
|
Vue.prototype.$services = services;
|
||||||
Vue.prototype.$user = userstate;
|
Vue.prototype.$user = userstate;
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<f7-list-button :class="{ 'disabled': inputIsEmpty }" :text="$t('Log In')" @click="login"></f7-list-button>
|
<f7-list-button :class="{ 'disabled': inputIsEmpty }" :text="$t('Log In')" @click="login"></f7-list-button>
|
||||||
<f7-block-footer>
|
<f7-block-footer>
|
||||||
<span v-t="'Don\'t have an account?'"></span>
|
<span v-t="'Don\'t have an account?'"></span>
|
||||||
<f7-link href="/signup" :text="$t('Create an account')"></f7-link>
|
<f7-link :class="{'disabled': !isUserRegistrationEnabled}" href="/signup" :text="$t('Create an account')"></f7-link>
|
||||||
<br/>
|
<br/>
|
||||||
<f7-link class="disabled" href="/forget-pwd" :text="$t('Forget Password?')"></f7-link>
|
<f7-link class="disabled" href="/forget-pwd" :text="$t('Forget Password?')"></f7-link>
|
||||||
</f7-block-footer>
|
</f7-block-footer>
|
||||||
@@ -98,6 +98,9 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
isUserRegistrationEnabled() {
|
||||||
|
return this.$isUserRegistrationEnabled();
|
||||||
|
},
|
||||||
inputIsEmpty() {
|
inputIsEmpty() {
|
||||||
return !this.username || !this.password;
|
return !this.username || !this.password;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user