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.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")
|
||||
|
||||
|
||||
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": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz",
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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 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'
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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>
|
||||
<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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user