admin

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2022 License: BSD-2-Clause, MIT, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWT = &jwt.GinJWTMiddleware{
	Realm:       "si-engine",
	Key:         []byte("RGV05HJoZWx0b3Ryb2xpZ3R2aWxrZXRzduVydGz2c2Vub3JkZGV0dGHkcg=="),
	Timeout:     time.Hour * 24 * 365 * 30,
	MaxRefresh:  time.Hour,
	IdentityKey: identityKey,
	PayloadFunc: func(data interface{}) jwt.MapClaims {
		if v, ok := data.(*db.User); ok {
			return jwt.MapClaims{
				identityKey: v.UserName,
			}
		}
		return jwt.MapClaims{}
	},
	IdentityHandler: func(c *gin.Context) interface{} {
		claims := jwt.ExtractClaims(c)
		return &db.User{
			UserName: claims[identityKey].(string),
		}
	},
	Authenticator: func(c *gin.Context) (interface{}, error) {
		var loginVals login
		if err := c.ShouldBind(&loginVals); err != nil {
			return "", jwt.ErrMissingLoginValues
		}
		userID := loginVals.Username
		password := loginVals.Password

		// TODO: save salted and hashed passwords rather than plain text
		var user db.User
		result := db.DB.Where("user_name = ? and password = ?", userID, password).First(&user)
		if result.Error != nil {
			return nil, jwt.ErrFailedAuthentication
		}
		return &user, nil
	},
	Authorizator: func(data interface{}, c *gin.Context) bool {
		if v, ok := data.(*db.User); ok && v.UserName == "admin@acme.com" {
			return true
		}

		return true
	},
	Unauthorized: func(c *gin.Context, code int, message string) {
		c.JSON(code, gin.H{
			"code":    code,
			"message": message,
		})
	},

	TokenLookup: "header: Authorization",

	TokenHeadName: "Bearer",

	TimeFunc: time.Now,
}

Functions

func Log

func Log(category string, title string, msg string)

func Run

func Run(broker *usvc.UsvcBroker)

func WShandler

func WShandler(w http.ResponseWriter, r *http.Request, connections *list.List)

Types

type Message

type Message struct {
	Author  string `json:"author"`
	Message string `json:"message"`
}

type Session

type Session struct {
	SessionID string `json:"sessionid"`
	Extra     string `json:"extra"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL