Import sources from Kontor

This commit is contained in:
Thomas Peetz
2019-06-18 18:33:38 +02:00
parent fa3286c8e2
commit f326e994da
20 changed files with 1262 additions and 3 deletions
+11
View File
@@ -0,0 +1,11 @@
package setup
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/dao"
"log"
)
// CheckTradeYourSportsCardsData checks if the TYSC releated data is available.
func CheckFoodData() {
log.Printf("Check data for Food values")
}
+28
View File
@@ -0,0 +1,28 @@
package setup
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/admin"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/auth"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/util"
"github.com/gin-gonic/gin"
)
// InitializeRoutes setup the routes for Kalorien Manager web application.
func InitializeRoutes(router *gin.Engine) {
// Use the setUserStatus middleware for every route to set a flag
// indicating whether the request was from an authenticated user or not
router.Use(auth.SetSessionStatus())
// Handle the index route
router.GET("/", util.ShowIndexPage)
userRoutes := router.Group("/user")
{
userRoutes.GET("/login", auth.EnsureNotLoggedIn(), admin.ShowLoginPage)
userRoutes.POST("/login", auth.EnsureNotLoggedIn(), admin.PerformLogin)
userRoutes.GET("/logout", auth.EnsureLoggedIn(), admin.Logout)
}
admin.GetRoutes(router)
}
+15
View File
@@ -0,0 +1,15 @@
package setup
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/auth"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/dao"
)
// CleanupSessions removes all sessions from database.
func CleanupSessions() {
sessionDao := auth.SessionDAO{Db: dao.KalorienmanagerDb}
sessions, _ := sessionDao.FindAll()
for _, session := range sessions {
sessionDao.Delete(session)
}
}
+20
View File
@@ -0,0 +1,20 @@
package setup
import (
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/admin"
"gitlab.ingenieurbuero-peetz.de/tpeetz/kalorienmanager.git/pkg/dao"
"gopkg.in/mgo.v2/bson"
)
// CheckUserList ensures that at least the admin user is available.
func CheckUserList() {
var userDao = admin.UserDAO{Db: dao.KalorienmanagerDb}
users, err := userDao.FindAll()
if err == nil && len(users) == 0 {
password, _ := admin.HashPassword("admin")
id := bson.NewObjectId()
user := admin.User{ID: id, Username: "admin", Password: password, Firstname: "Administrator", IsAdmin: true}
userDao.Insert(user)
}
}