|
package auth
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
const dbPrefix = ""
|
|
|
|
type Group struct {
|
|
Id string `json:"id" xql:"type=uuid,pk,default=uuid_generate_v4()"`
|
|
Name string `json:"name" xql:"size=32,unique,index"`
|
|
Description string `json:"description" xql:"size=256,default=''"`
|
|
Created *time.Time `json:"created,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Updated *time.Time `json:"updated,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Permissions []string `json:"permissions" xql:"-"`
|
|
}
|
|
|
|
func (Group) TableName() string {
|
|
return dbPrefix + "auth_groups"
|
|
}
|
|
|
|
type GroupPermission struct {
|
|
Id string `json:"id" xql:"type=uuid,pk,default=uuid_generate_v4()"`
|
|
GroupId string `json:"groupId" xql:"type=uuid"`
|
|
Role string `json:"role" xql:"size=32,index"`
|
|
Created *time.Time `json:"created,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Updated *time.Time `json:"updated,omitempty" xql:"type=timestamp,default=Now()"`
|
|
}
|
|
|
|
func (GroupPermission) TableName() string {
|
|
return dbPrefix + "auth_group_permissions"
|
|
}
|
|
|
|
func (GroupPermission) Constraints() [][3]string {
|
|
return [][3]string{
|
|
{"fk", "group_id", fmt.Sprintf("%s (id) ON DELETE CASCADE", Group{}.TableName())},
|
|
}
|
|
}
|
|
|
|
type GroupUser struct {
|
|
Id string `json:"id" xql:"type=uuid,pk,default=uuid_generate_v4()"`
|
|
GroupId string `json:"groupId" xql:"name=group_id,type=uuid"`
|
|
UserId string `json:"userId" xql:"name=user_id,type=uuid"`
|
|
Created *time.Time `json:"created,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Updated *time.Time `json:"updated,omitempty" xql:"type=timestamp,default=Now()"`
|
|
}
|
|
|
|
func (GroupUser) TableName() string {
|
|
return dbPrefix + "auth_group_users"
|
|
}
|
|
|
|
func (GroupUser) Constraints() [][3]string {
|
|
return [][3]string{
|
|
{"fk", "group_id", fmt.Sprintf("%s (id) ON DELETE CASCADE", Group{}.TableName())},
|
|
{"fk", "user_id", fmt.Sprintf("%s (id) ON DELETE CASCADE", User{}.TableName())},
|
|
}
|
|
}
|
|
|
|
type User struct {
|
|
Id string `json:"id" xql:"type=uuid,pk,default=uuid_generate_v4()"`
|
|
Username string `json:"username" xql:"size=32,unique,index"`
|
|
Password string `json:"password" xql:"size=64,default=''"`
|
|
Email string `json:"email" xql:"size=64,default=''"`
|
|
Contact string `json:"contact" xql:"size=256,,default=''"`
|
|
Activate bool `json:"activate" xql:"default=false"`
|
|
Created *time.Time `json:"created,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Updated *time.Time `json:"updated,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Groups []string `json:"groups" xql:"-"`
|
|
Permissions []string `json:"permissions" xql:"-"`
|
|
IsSelf bool `json:"isSelf" xql:"-"`
|
|
}
|
|
|
|
func (User) TableName() string {
|
|
return dbPrefix + "auth_users"
|
|
}
|
|
|
|
type Session struct {
|
|
Id string `json:"id" xql:"type=uuid,pk,default=uuid_generate_v4()"`
|
|
UserId string `json:"userId" xql:"type=uuid"`
|
|
Login *time.Time `json:"login,omitempty" xql:"type=timestamp,default=Now()"`
|
|
Logout *time.Time `json:"login,omitempty" xql:"type=timestamp,default=NULL"`
|
|
Updated *time.Time `json:"updated,omitempty" xql:"type=timestamp,default=Now()"`
|
|
}
|
|
|
|
func (Session) TableName() string {
|
|
return dbPrefix + "auth_sessions"
|
|
}
|
|
|
|
func (Session) Constraints() [][3]string {
|
|
return [][3]string{
|
|
{"fk", "user_id", fmt.Sprintf("%s (id) ON DELETE CASCADE", User{}.TableName())},
|
|
}
|
|
}
|