Documentation ¶
Index ¶
- Constants
- Variables
- func GenToken(a *Account) string
- func PermissionGrantLabelsPairFromGroupIdAndPerm(groupId uint64, perm string) map[string]string
- func PermissionRevokeLabelKeysFromPermissionId(permissionId string) []string
- type Account
- type AccountFilter
- type AccountGroup
- type Authenticator
- type Group
- type GroupFilter
- type GroupPermission
- type MockAuthenticator
- func (d *MockAuthenticator) Account(id interface{}) (*Account, error)
- func (d *MockAuthenticator) AccountGroups(account model.ListOptions) (*[]Group, error)
- func (d *MockAuthenticator) AccountPermissions(account *Account) (*[]string, error)
- func (d *MockAuthenticator) Accounts(listOptions model.ListOptions) (auths *[]Account, err error)
- func (d *MockAuthenticator) CreateAccount(groupId uint64, a *Account) error
- func (d *MockAuthenticator) CreateGroup(g *Group) error
- func (d *MockAuthenticator) DeleteGroup(groupId uint64) error
- func (d *MockAuthenticator) EncryptPassword(password string) string
- func (d *MockAuthenticator) GetDefaultAccounts() (account []Account)
- func (d *MockAuthenticator) Group(id uint64) (*Group, error)
- func (d *MockAuthenticator) GroupAccounts(account model.ListOptions) (*[]Account, error)
- func (d *MockAuthenticator) Groups(options model.ListOptions) (auths *[]Group, err error)
- func (d *MockAuthenticator) JoinGroup(accountId, groupId uint64) error
- func (d *MockAuthenticator) LeaveGroup(accountId, groupId uint64) error
- func (d *MockAuthenticator) Login(a *Account) (token string, err error)
- func (d *MockAuthenticator) ModificationAllowed() bool
- func (d *MockAuthenticator) UpdateAccount(a *Account) error
- func (d *MockAuthenticator) UpdateGroup(g *Group) error
- type Permission
- type TokenStore
Constants ¶
View Source
const ( SESSION_DURATION = time.Second * 60 * 10 * 1000 SESSION_KEY_FORMAT = "account_id:%v:token" )
View Source
const ( //Account CodeInvalidGroupId = "400-12001" CodeAccountCreateParamError = "400-12002" CodeAccountCreateAuthenticatorError = "503-12003" CodeAccountGetAccountError = "503-12004" CodeAccountGetAccountNotFoundError = "503-12005" CodeAccountLoginParamError = "400-12006" CodeAccountLoginFailedError = "401-12007" CodeAccountLogoutError = "503-12008" CodeAccountGroupAccountsGroupIdNotValidError = "400-12009" CodeAccountGroupAccountsNotFoundError = "404-12010" CodeAccountAccoutGroupsAccountIdNotValidError = "400-12011" CodeAccountAccoutGroupsNotFoundError = "503-12012" CodeAccountGetGroupGroupIdNotValidError = "503-12013" CodeAccountGetGroupGroupIdNotFoundError = "404-12014" CodeAccountListGroupNotFoundError = "503-12015" CodeAccountAuthenticatorModificationNotAllowedError = "503-12016" CodeAccountCreateGroupParamError = "400-12017" CodeAccountCreateGroupFailedError = "503-12018" CodeAccountUpdateGroupParamError = "400-12019" CodeAccountUpdateGroupFailedError = "503-12020" CodeAccountDeleteGroupGroupIdNotValidError = "503-12021" CodeAccountDeleteGroupFailedError = "503-12022" CodeAccountJoinGroupGroupIdNotValidError = "503-12023" CodeAccountJoinGroupAccountIdNotValidError = "503-12024" CodeAccountJoinGroupFailedError = "503-12025" CodeAccountLeaveGroupGroupIdNotValidError = "503-12026" CodeAccountLeaveGroupAccountIdNotValidError = "503-12027" CodeAccountLeaveGroupFailedError = "503-12028" CodeAccountGrantServicePermissionParamError = "400-12029" CodeAccountGrantServicePermissionFailedError = "503-12030" CodeAccountRevokeServicePermissionParamError = "400-12031" CodeAccountRevokeServicePermissionFailedError = "503-12032" CodeAccountTokenInvalidError = "401-12033" CodeAccountLoginFailedEmailNotValidError = "401-12034" CodeAccountLoginFailedPasswordNotValidError = "401-12035" )
View Source
const (
DEFAULT_SALT = "thequickbrownfoxjumpdog"
)
View Source
const (
PERMISSION_LABEL_PREFIX = "crane.reserved.permissions"
)
Variables ¶
View Source
var ( ErrLoginFailed = errors.New("account login failed") ErrAccountNotFound = errors.New("account not found") ErrGroupNotFound = errors.New("group not found") )
View Source
var ( AuthError error AccountError error CreateAccountError error AccountsError error )
Functions ¶
Types ¶
type Account ¶
type Account struct { ID uint64 `json:"Id"` Title string `json:"Title"` Email string `json:"Email" gorm:"not null"` Phone string `json:"Phone"` LoginAt time.Time `json:"LoginAt"` Password string `json:"Password" gorm:"not null"` Token string `json:"-" gorm:"-"` }
func ReferenceToValue ¶
type AccountFilter ¶
type AccountGroup ¶
type Authenticator ¶
type Authenticator interface { AccountPermissions(account *Account) (*[]string, error) Login(account *Account) (token string, err error) EncryptPassword(password string) string DeleteGroup(groupId uint64) error Groups(listOptions model.ListOptions) (*[]Group, error) Group(id uint64) (*Group, error) CreateGroup(role *Group) error UpdateGroup(role *Group) error GroupAccounts(account model.ListOptions) (*[]Account, error) AccountGroups(account model.ListOptions) (*[]Group, error) Accounts(listOptions model.ListOptions) (*[]Account, error) Account(id interface{}) (*Account, error) CreateAccount(groupId uint64, a *Account) error UpdateAccount(a *Account) error JoinGroup(accountId, groupId uint64) error LeaveGroup(accountId, groupId uint64) error ModificationAllowed() bool GetDefaultAccounts() []Account }
type GroupFilter ¶
type GroupPermission ¶
type GroupPermission struct { Permission Permission `json:"Permission"` GroupID uint64 `json:"GroupID"` }
type MockAuthenticator ¶
type MockAuthenticator struct {
Authenticator
}
func NewMockAuthenticator ¶
func NewMockAuthenticator() *MockAuthenticator
func (*MockAuthenticator) Account ¶
func (d *MockAuthenticator) Account(id interface{}) (*Account, error)
func (*MockAuthenticator) AccountGroups ¶
func (d *MockAuthenticator) AccountGroups(account model.ListOptions) (*[]Group, error)
func (*MockAuthenticator) AccountPermissions ¶
func (d *MockAuthenticator) AccountPermissions(account *Account) (*[]string, error)
func (*MockAuthenticator) Accounts ¶
func (d *MockAuthenticator) Accounts(listOptions model.ListOptions) (auths *[]Account, err error)
func (*MockAuthenticator) CreateAccount ¶
func (d *MockAuthenticator) CreateAccount(groupId uint64, a *Account) error
func (*MockAuthenticator) CreateGroup ¶
func (d *MockAuthenticator) CreateGroup(g *Group) error
func (*MockAuthenticator) DeleteGroup ¶
func (d *MockAuthenticator) DeleteGroup(groupId uint64) error
func (*MockAuthenticator) EncryptPassword ¶
func (d *MockAuthenticator) EncryptPassword(password string) string
func (*MockAuthenticator) GetDefaultAccounts ¶
func (d *MockAuthenticator) GetDefaultAccounts() (account []Account)
func (*MockAuthenticator) GroupAccounts ¶
func (d *MockAuthenticator) GroupAccounts(account model.ListOptions) (*[]Account, error)
func (*MockAuthenticator) Groups ¶
func (d *MockAuthenticator) Groups(options model.ListOptions) (auths *[]Group, err error)
func (*MockAuthenticator) JoinGroup ¶
func (d *MockAuthenticator) JoinGroup(accountId, groupId uint64) error
func (*MockAuthenticator) LeaveGroup ¶
func (d *MockAuthenticator) LeaveGroup(accountId, groupId uint64) error
func (*MockAuthenticator) Login ¶
func (d *MockAuthenticator) Login(a *Account) (token string, err error)
func (*MockAuthenticator) ModificationAllowed ¶
func (d *MockAuthenticator) ModificationAllowed() bool
func (*MockAuthenticator) UpdateAccount ¶
func (d *MockAuthenticator) UpdateAccount(a *Account) error
func (*MockAuthenticator) UpdateGroup ¶
func (d *MockAuthenticator) UpdateGroup(g *Group) error
type Permission ¶
var ( PermReadOnly Permission = Permission{Perm: 0, Display: "r"} PermReadWrite Permission = Permission{Perm: 1, Display: "w"} PermAdmin Permission = Permission{Perm: 2, Display: "x"} Perms []Permission = []Permission{PermReadOnly, PermReadWrite, PermAdmin} )
func NewPermission ¶
func NewPermission(display string) Permission
func PermGreaterOrEqualThan ¶
func PermGreaterOrEqualThan(p Permission) []Permission
func PermLessOrEqualThan ¶
func PermLessOrEqualThan(p Permission) []Permission
func (Permission) Normalize ¶
func (p Permission) Normalize() Permission
Source Files ¶
Click to show internal directories.
Click to hide internal directories.