make "create an account" link disabled when user registration is disabled in config

This commit is contained in:
MaysWind
2020-10-27 22:38:58 +08:00
parent f483838a25
commit 0c7391b85d
7 changed files with 80 additions and 7 deletions
+14 -5
View File
@@ -78,8 +78,9 @@ func startWebServer(c *cli.Context) error {
router.NoRoute(bindApi(api.Default.ApiNotFound))
router.NoMethod(bindApi(api.Default.MethodNotAllowed))
router.StaticFile("/mobile", filepath.Join(config.StaticRootPath, "mobile.html"))
router.StaticFile("/desktop", filepath.Join(config.StaticRootPath, "desktop.html"))
router.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/mobile/")
})
router.StaticFile("robots.txt", filepath.Join(config.StaticRootPath, "robots.txt"))
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("/fonts", filepath.Join(config.StaticRootPath, "fonts"))
router.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/mobile")
})
mobileEntryRoute := router.Group("/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")
+5
View File
@@ -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": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
+1
View File
@@ -13,6 +13,7 @@
"framework7": "^5.7.13",
"framework7-icons": "^3.0.1",
"framework7-vue": "^5.7.13",
"js-cookie": "^2.2.1",
"vue": "^2.6.11",
"vue-i18n": "^8.22.0"
},
+32
View File
@@ -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
View File
@@ -1,4 +1,8 @@
import Cookies from 'js-cookie'
const settingsLocalStorageKey = 'lab_user_settings';
const serverSettingsCookieKey = 'ACP_SETTINGS';
const defaultSettings = {
lang: 'en'
};
@@ -37,7 +41,23 @@ function setOption(key, value) {
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 {
getLanguage: () => getOriginalOption('lang'),
setLanguage: value => setOption('lang', value)
setLanguage: value => setOption('lang', value),
isUserRegistrationEnabled: () => getServerSetting('r') === '1'
};
+3
View File
@@ -31,6 +31,8 @@ Vue.prototype.$setLanguage = function (locale) {
document.querySelector('html').setAttribute('lang', locale);
return locale;
};
Vue.prototype.$isUserRegistrationEnabled = settings.isUserRegistrationEnabled;
Vue.prototype.$alert = function (message, confirmCallback) {
let parameters = {};
@@ -84,6 +86,7 @@ Vue.prototype.$toast = function (message, timeout) {
closeTimeout: timeout || 1500
}).open();
};
Vue.prototype.$services = services;
Vue.prototype.$user = userstate;
+4 -1
View File
@@ -23,7 +23,7 @@
<f7-list-button :class="{ 'disabled': inputIsEmpty }" :text="$t('Log In')" @click="login"></f7-list-button>
<f7-block-footer>
<span v-t="'Don\'t have an account?'"></span>&nbsp;
<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/>
<f7-link class="disabled" href="/forget-pwd" :text="$t('Forget Password?')"></f7-link>
</f7-block-footer>
@@ -98,6 +98,9 @@ export default {
};
},
computed: {
isUserRegistrationEnabled() {
return this.$isUserRegistrationEnabled();
},
inputIsEmpty() {
return !this.username || !this.password;
},