go,tmpl: allow conditionally disabling the sign-up
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
01907c349f
commit
ab93161867
@ -56,8 +56,11 @@ func (a *App) SetupRoutes() error {
|
|||||||
base.HEAD("/", handlers.Index())
|
base.HEAD("/", handlers.Index())
|
||||||
base.GET("/signin", handlers.Signin(), compress)
|
base.GET("/signin", handlers.Signin(), compress)
|
||||||
base.POST("/signin", handlers.SigninPost(a.db))
|
base.POST("/signin", handlers.SigninPost(a.db))
|
||||||
|
|
||||||
|
if a.setting.RegistrationAllowed {
|
||||||
base.GET("/signup", handlers.Signup(), compress)
|
base.GET("/signup", handlers.Signup(), compress)
|
||||||
base.POST("/signup", handlers.SignupPost(a.db))
|
base.POST("/signup", handlers.SignupPost(a.db))
|
||||||
|
}
|
||||||
|
|
||||||
base.GET("/home", handlers.Home(a.db))
|
base.GET("/home", handlers.Home(a.db))
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ type Settings struct {
|
|||||||
dbConnstring string
|
dbConnstring string
|
||||||
dbType string
|
dbType string
|
||||||
dbIsSetUp bool
|
dbIsSetUp bool
|
||||||
|
RegistrationAllowed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -160,6 +161,10 @@ func (s *Settings) Consolidate(conf *config.Config, host *string, port *int, dev
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.Registration.Allowed {
|
||||||
|
s.RegistrationAllowed = true
|
||||||
|
}
|
||||||
|
|
||||||
s.SetVersion(version)
|
s.SetVersion(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ var (
|
|||||||
slogger *slogging.Slogger
|
slogger *slogging.Slogger
|
||||||
log slogging.Slogger
|
log slogging.Slogger
|
||||||
dbclient *ent.Client
|
dbclient *ent.Client
|
||||||
|
registrationAllowed bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetDBClient(client *ent.Client) {
|
func SetDBClient(client *ent.Client) {
|
||||||
@ -36,4 +37,5 @@ func InitHandlers(s *settings.Settings) {
|
|||||||
appName = setting.AppName()
|
appName = setting.AppName()
|
||||||
appver = setting.Version()
|
appver = setting.Version()
|
||||||
appIsDevel = setting.IsDevel()
|
appIsDevel = setting.IsDevel()
|
||||||
|
registrationAllowed = setting.RegistrationAllowed
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,15 @@ type page struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newPage() *page {
|
func newPage() *page {
|
||||||
|
data := make(map[string]any, 0)
|
||||||
|
|
||||||
|
data["RegistrationAllowed"] = registrationAllowed
|
||||||
|
|
||||||
p := &page{
|
p := &page{
|
||||||
AppName: appName,
|
AppName: appName,
|
||||||
AppVer: appver,
|
AppVer: appver,
|
||||||
DevelMode: appIsDevel,
|
DevelMode: appIsDevel,
|
||||||
|
Data: data,
|
||||||
}
|
}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<a href="#" class="block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-300 md:hover:bg-transparent md:border-0 md:hover:text-blue-500 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">About</a>
|
<a href="#" class="block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-300 md:hover:bg-transparent md:border-0 md:hover:text-blue-500 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent">About</a>
|
||||||
</li>
|
</li>
|
||||||
|
{{ if and .Data .Data.RegistrationAllowed }}
|
||||||
{{ if or (not .User) (and .User (not .User.IsLoggedIn)) }}
|
{{ if or (not .User) (and .User (not .User.IsLoggedIn)) }}
|
||||||
<li>
|
<li>
|
||||||
{{ if pageIs .Current "signup" }}
|
{{ if pageIs .Current "signup" }}
|
||||||
@ -56,6 +57,9 @@
|
|||||||
Register
|
Register
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
{{ if or (not .User) (and .User (not .User.IsLoggedIn)) }}
|
||||||
<li>
|
<li>
|
||||||
{{ if pageIs .Current "signin" }}
|
{{ if pageIs .Current "signin" }}
|
||||||
<a href="/signin" class="block py-2 pl-3 pr-4 text-white bg-blue-500 rounded md:bg-transparent md:text-blue-700 md:p-0 md:dark:text-blue-500 dark:bg-blue-500 md:dark:bg-transparent" aria-current="page">
|
<a href="/signin" class="block py-2 pl-3 pr-4 text-white bg-blue-500 rounded md:bg-transparent md:text-blue-700 md:p-0 md:dark:text-blue-500 dark:bg-blue-500 md:dark:bg-transparent" aria-current="page">
|
||||||
|
Loading…
Reference in New Issue
Block a user