This commit is contained in:
sentriz
2019-05-19 23:28:05 +01:00
parent 5c657d9630
commit ad571ed7ab
45 changed files with 787 additions and 492 deletions

43
server/handler/handler.go Normal file
View File

@@ -0,0 +1,43 @@
package handler
import (
"html/template"
"github.com/jinzhu/gorm"
"github.com/wader/gormstore"
"github.com/sentriz/gonic/model"
)
type contextKey int
const (
contextUserKey contextKey = iota
contextSessionKey
)
type Controller struct {
DB *gorm.DB
SessDB *gormstore.Store
Templates map[string]*template.Template
MusicPath string
}
func (c *Controller) GetSetting(key string) string {
var setting model.Setting
c.DB.Where("key = ?", key).First(&setting)
return setting.Value
}
func (c *Controller) SetSetting(key, value string) {
c.DB.
Where(model.Setting{Key: key}).
Assign(model.Setting{Value: value}).
FirstOrCreate(&model.Setting{})
}
func (c *Controller) GetUserFromName(name string) *model.User {
var user model.User
c.DB.Where("name = ?", name).First(&user)
return &user
}