go,tmpl: allow conditionally disabling the sign-up
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-08-16 15:07:10 +02:00
parent 01907c349f
commit ab93161867
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI
5 changed files with 28 additions and 9 deletions

@ -56,8 +56,11 @@ func (a *App) SetupRoutes() error {
base.HEAD("/", handlers.Index())
base.GET("/signin", handlers.Signin(), compress)
base.POST("/signin", handlers.SigninPost(a.db))
if a.setting.RegistrationAllowed {
base.GET("/signup", handlers.Signup(), compress)
base.POST("/signup", handlers.SignupPost(a.db))
}
base.GET("/home", handlers.Home(a.db))

@ -39,6 +39,7 @@ type Settings struct {
dbConnstring string
dbType string
dbIsSetUp bool
RegistrationAllowed bool
}
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)
}

@ -18,6 +18,7 @@ var (
slogger *slogging.Slogger
log slogging.Slogger
dbclient *ent.Client
registrationAllowed bool
)
func SetDBClient(client *ent.Client) {
@ -36,4 +37,5 @@ func InitHandlers(s *settings.Settings) {
appName = setting.AppName()
appver = setting.Version()
appIsDevel = setting.IsDevel()
registrationAllowed = setting.RegistrationAllowed
}

@ -21,10 +21,15 @@ type page struct {
}
func newPage() *page {
data := make(map[string]any, 0)
data["RegistrationAllowed"] = registrationAllowed
p := &page{
AppName: appName,
AppVer: appver,
DevelMode: appIsDevel,
Data: data,
}
return p

@ -46,6 +46,7 @@
<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>
</li>
{{ if and .Data .Data.RegistrationAllowed }}
{{ if or (not .User) (and .User (not .User.IsLoggedIn)) }}
<li>
{{ if pageIs .Current "signup" }}
@ -56,6 +57,9 @@
Register
</a>
</li>
{{end}}
{{end}}
{{ if or (not .User) (and .User (not .User.IsLoggedIn)) }}
<li>
{{ 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">