Make Application name configurable

This commit is contained in:
Thomas Peetz
2019-09-03 15:42:48 +02:00
parent b7cbe08d7b
commit 276e65b153
15 changed files with 359 additions and 12 deletions
+15 -8
View File
@@ -3,17 +3,24 @@ package admin
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/auth"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/dao"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/properties"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/util"
"net/http"
"strconv"
"fmt"
"github.com/gin-gonic/gin"
)
var (
// PageTitleUserAdministration defines the page title for user administration
PageTitleUserAdministration = fmt.Sprintf("%s User Administration", properties.Application)
)
// ShowLoginPage renders login page.
func ShowLoginPage(c *gin.Context) {
// Call the render function with the name of the template to render
util.Render(c, gin.H{"title": "Login"}, "login.html")
util.Render(c, gin.H{"title": "Login"}, "login.html", false)
}
// PerformLogin reads data from login form and validates input.
@@ -34,7 +41,7 @@ func PerformLogin(c *gin.Context) {
session.Username = username
session.IsAdmin = user.IsAdmin
sessionDao.Update(session)
util.Render(c, gin.H{"title": "Successful Login", "InfoMessage": "Login successfull"}, "kontor/index.html")
util.Render(c, gin.H{"title": "Successful Login", "InfoMessage": "Login successfull"}, "index.html", true)
} else {
// If the username/password combination is invalid,
// show the error message on the login page
@@ -56,15 +63,15 @@ func Logout(c *gin.Context) {
func showAdminIndex(c *gin.Context) {
// Call the render function with the name of the template to render
util.Render(c, gin.H{"title": "Kontor", "payload": nil}, "kontor/admin.html")
util.Render(c, gin.H{"title": properties.Application, "payload": nil}, "admin.html", true)
}
func showUserIndex(c *gin.Context) {
var dao = UserDAO{Db: dao.KalorienmanagerDb}
if users, err := dao.FindAll(); err == nil && users != nil {
util.Render(c, gin.H{"title": "Kontor User Administration", "payload": users}, "kontor/users.html")
util.Render(c, gin.H{"title": PageTitleUserAdministration, "payload": users}, "users.html", true)
} else {
util.Render(c, gin.H{"title": "Kontor User Administration", "payload": users, "ErrorMessage": err}, "kontor/users.html")
util.Render(c, gin.H{"title": PageTitleUserAdministration, "payload": users, "ErrorMessage": err}, "users.html", true)
}
}
@@ -72,7 +79,7 @@ func showUserDetails(c *gin.Context) {
userID := c.Param("userid")
var userDao = UserDAO{Db: dao.KalorienmanagerDb}
if user, err := userDao.FindByID(userID); err == nil && &user != nil {
util.Render(c, gin.H{"title": "Kontor User Administration", "payload": user, "action": util.SaveAction}, "kontor/user-detail.html")
util.Render(c, gin.H{"title": PageTitleUserAdministration, "payload": user, "action": util.SaveAction}, "user-detail.html", true)
} else {
c.AbortWithError(http.StatusNotFound, err)
}
@@ -80,7 +87,7 @@ func showUserDetails(c *gin.Context) {
func showUserCreation(c *gin.Context) {
var user = User{}
util.Render(c, gin.H{"title": "Kontor User Administration", "payload": user, "action": util.AddAction}, "kontor/user-detail.html")
util.Render(c, gin.H{"title": PageTitleUserAdministration, "payload": user, "action": util.AddAction}, "user-detail.html", true)
}
func validateUserCreation(c *gin.Context) {
@@ -121,7 +128,7 @@ func validateUserCreation(c *gin.Context) {
if err == nil {
c.Redirect(http.StatusTemporaryRedirect, "/admin/user")
} else {
c.HTML(http.StatusBadRequest, "kontor/create-user.html", gin.H{
c.HTML(http.StatusBadRequest, "kalorienmanager/create-user.html", gin.H{
"ErrorTitle": "User Creation Failed",
"ErrorMessage": err.Error()})
}