Documentation
¶
Index ¶
- Constants
- Variables
- func Auth(authenticated bool) gin.HandlerFunc
- func CheckDuplicate(name string) (check bool)
- func CreateCookie(token string) *http.Cookie
- func DeleteCookie() *http.Cookie
- func HashPassword(password string) (hash []byte, err error)
- func IsValidName(name string) bool
- func MakeToken(secret string, uid uint) (newtoken string, err error)
- func Protect() gin.HandlerFunc
- func RandomPassword() (password string, hash []byte, err error)
- func UpdatePassword(hash []byte, uid uint) (err error)
- type Authenticator
- type User
- func (u *User) ComparePassword(password string) bool
- func (u *User) CreateToken() (newtoken string, err error)
- func (u *User) FromName(name string) (err error)
- func (u *User) IsAuthorized(ib uint) bool
- func (u *User) IsValid() bool
- func (u *User) Password() (err error)
- func (u *User) SetAuthenticated()
- func (u *User) SetID(uid uint)
Constants ¶
const (
// CookieName is the name of the jwt session cookie
CookieName = "session_jwt"
)
Variables ¶
var Secret string
Secret holds the hmac secret, is set from main
Functions ¶
func Auth ¶
func Auth(authenticated bool) gin.HandlerFunc
Auth is a gin middleware that checks for session cookie and handles permissions
func CheckDuplicate ¶
CheckDuplicate will check for duplicate name before registering
func CreateCookie ¶ added in v1.3.0
CreateCookie will make a cookie for the JWT
func DeleteCookie ¶ added in v1.3.0
DeleteCookie will delete the JWT cookie
func HashPassword ¶
HashPassword will create a bcrypt hash from the given password
func Protect ¶
func Protect() gin.HandlerFunc
Protect will check to see if a user has the correct permissions A route protected by this middleware needs an ib parameter
func RandomPassword ¶ added in v1.3.0
RandomPassword will generate a random password for password resets
func UpdatePassword ¶ added in v1.3.0
UpdatePassword will update the user password hash in database
Types ¶
type Authenticator ¶
type Authenticator interface {
IsValid() bool
IsAuthorized(ib uint) bool
SetID(uid uint)
SetAuthenticated()
Password() (err error)
ComparePassword(password string) bool
FromName(name string) (err error)
CreateToken() (newtoken string, err error)
}
Authenticator defines the methods for authentication
type User ¶
type User struct {
ID uint
Name string
IsAuthenticated bool
// contains filtered or unexported fields
}
User data struct
func (*User) ComparePassword ¶
ComparePassword will compare the supplied password to the hash from the database
func (*User) CreateToken ¶
CreateToken will make a JWT token associated with a user
func (*User) FromName ¶
FromName will get the password and user id from the database for a user name
func (*User) IsAuthorized ¶
IsAuthorized will get the perms and role info from the userid
func (*User) Password ¶
Password will get the password and name from the database for an instantiated user
func (*User) SetAuthenticated ¶
func (u *User) SetAuthenticated()
SetAuthenticated sets a user as authenticated