auth

package
v0.0.0-...-685c49b Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DEFUALT_TOKEN_EXPIRATION_DATE = 60 * 60 * 24 * 365

Variables

View Source
var (
	TokenCollection = "tokens"
	Tokens          = make(map[string]Token)
)
View Source
var (
	RoleCollection = "roles"
)
View Source
var UserCollection = "users"

Functions

func AddToken

func AddToken(token *Token)

func ForbiddenError

func ForbiddenError() *common.Error

func HashUserPassword

func HashUserPassword(password string) string

func RemoveToken

func RemoveToken(token string)

func SyncTokens

func SyncTokens(tokens []Token)

func TokenExpiredError

func TokenExpiredError() *common.Error

func UserAlreadyRegisteredError

func UserAlreadyRegisteredError() *common.Error

func UserNotRegisteredError

func UserNotRegisteredError() *common.Error

func UserUnauthorizedError

func UserUnauthorizedError() *common.Error

Types

type Param

type Param struct {
	Name  string   `json:"name"`
	Rules []string `json:"rules"`
}

type Permission

type Permission struct {
	URL    string  `json:"url"`
	Rights Rights  `json:"rights"`
	Params []Param `json:"params"`
}

type Rights

type Rights struct {
	Read  int `json:"read"`
	Write int `json:"write"`
}

func (Rights) Sum

func (permission Rights) Sum() int

type Role

type Role struct {
	ID          string                `json:"_id" bson:"-"`
	Name        string                `json:"name" bson:"name"`
	Permissions map[string]Permission `json:"permissions" bson:"permissions"`
}

func CreateNewRole

func CreateNewRole() *Role

func (*Role) CreateID

func (role *Role) CreateID()

type Session

type Session struct {
	ID               string
	User             User
	Token            Token
	RoutePermissions Permission
}

func CreateSession

func CreateSession() *Session

type Token

type Token struct {
	ID              string                `json:"_id" bson:"-"`
	Token           string                `json:"token" bson:"token"`
	EXPIRATION_TIME string                `json:"expiration_time" bson:"expiration_time"`
	UserID          string                `json:"user_id" bson:"user_id"`
	Permissions     map[string]Permission `json:"permissions" bson:"permissions"`
}

func CreateNewToken

func CreateNewToken() *Token

func CreateUserToken

func CreateUserToken(user *User) *Token

func (*Token) VerifyToken

func (token *Token) VerifyToken() bool

type User

type User struct {
	ID       string      `json:"_id" bson:"-"`
	Email    string      `json:"email" bson:"email"`
	IPAddr   string      `json:"ipaddr" bson:"ipaddr"`
	Password string      `json:"password" bson:"password"`
	Data     interface{} `json:"data" bson:"data"`
	RoleID   string      `json:"role_id" bson:"role_id"`
}

func CreateNewUser

func CreateNewUser() *User

func (*User) Can

func (user *User) Can(permission Permission) bool

func (*User) SetCredentials

func (user *User) SetCredentials(email string, password string)

func (*User) String

func (user *User) String() string

Jump to

Keyboard shortcuts

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