Documentation ¶
Index ¶
- Variables
- func GetUserMigrations(service kit.UserService) []db.Migration
- type IntIdUserProfile
- type IntUserModel
- type IntUserSession
- type Permission
- type PermissionResourceHooks
- type Role
- func (r *Role) AddPermission(perms ...string)
- func (r *Role) ClearPermissions()
- func (r Role) Collection() string
- func (r Role) GetId() interface{}
- func (r Role) GetName() string
- func (r *Role) GetPermissions() []string
- func (r Role) GetStrId() string
- func (r *Role) HasPermission(perms ...string) bool
- func (r *Role) RemovePermission(perms ...string)
- func (r *Role) SetId(n interface{}) error
- func (r *Role) SetName(n string)
- func (r *Role) SetPermissions(perms []string)
- func (r *Role) SetStrId(n string) error
- type RoleResourceHooks
- type Service
- func (h *Service) AddAuthAdaptor(a kit.AuthAdaptor)
- func (h *Service) AuthAdaptor(name string) kit.AuthAdaptor
- func (h *Service) AuthenticateUser(userIdentifier string, authAdaptorName string, data map[string]interface{}) (kit.User, apperror.Error)
- func (s *Service) Backend() db.Backend
- func (s *Service) BuildToken(typ, userId string, expiresAt time.Time) (kit.UserToken, apperror.Error)
- func (s *Service) ChangePassword(user kit.User, newPassword string) apperror.Error
- func (s *Service) ConfirmEmail(token string) (kit.User, apperror.Error)
- func (s *Service) CreateUser(user kit.User, adaptorName string, authData map[string]interface{}) apperror.Error
- func (s *Service) Debug() bool
- func (s *Service) FindUser(userIdentifier interface{}) (kit.User, apperror.Error)
- func (u *Service) PermissionResource() kit.Resource
- func (h *Service) ProfileModel() kit.UserProfile
- func (h *Service) ProfileResource() kit.Resource
- func (s *Service) Registry() kit.Registry
- func (s *Service) ResetPassword(token, newPassword string) (kit.User, apperror.Error)
- func (u *Service) RoleResource() kit.Resource
- func (s *Service) SendConfirmationEmail(user kit.User) apperror.Error
- func (s *Service) SendPasswordResetEmail(user kit.User) apperror.Error
- func (h *Service) SessionResource() kit.Resource
- func (s *Service) SetBackend(b db.Backend)
- func (s *Service) SetDebug(x bool)
- func (u *Service) SetPermissionResource(x kit.Resource)
- func (h *Service) SetProfileResource(x kit.Resource)
- func (s *Service) SetRegistry(x kit.Registry)
- func (u *Service) SetRoleResource(x kit.Resource)
- func (h *Service) SetSessionResource(x kit.Resource)
- func (h *Service) SetTokenResource(x kit.Resource)
- func (h *Service) SetUserResource(x kit.Resource)
- func (s Service) StartSession(user kit.User, sessionType string) (kit.Session, apperror.Error)
- func (h *Service) TokenResource() kit.Resource
- func (h *Service) UserResource() kit.Resource
- func (h *Service) VerifySession(token string) (kit.User, kit.Session, apperror.Error)
- type Session
- func (b Session) Collection() string
- func (s Session) GetId() interface{}
- func (s *Session) GetStartedAt() time.Time
- func (s Session) GetStrId() string
- func (s *Session) GetToken() string
- func (s *Session) GetType() string
- func (s *Session) GetValidUntil() time.Time
- func (s *Session) SetId(x interface{}) error
- func (s *Session) SetStartedAt(x time.Time)
- func (s *Session) SetStrId(x string) error
- func (s *Session) SetToken(x string)
- func (s *Session) SetType(x string)
- func (s *Session) SetValidUntil(x time.Time)
- type SessionResourceHooks
- type StrIdUserProfile
- type StrUserModel
- type StrUserSession
- type Token
- func (t *Token) Collection() string
- func (t *Token) GetExpiresAt() time.Time
- func (t *Token) GetId() interface{}
- func (t *Token) GetStrId() string
- func (t *Token) GetToken() string
- func (t *Token) GetType() string
- func (t *Token) IsValid() bool
- func (t *Token) SetExpiresAt(tm time.Time)
- func (t *Token) SetId(id interface{}) error
- func (t *Token) SetStrId(id string) error
- func (t *Token) SetToken(x string)
- func (t *Token) SetType(x string)
- type User
- func (u *User) AddRole(roles ...string)
- func (u *User) ClearRoles()
- func (u User) Collection() string
- func (u *User) GetCreatedAt() time.Time
- func (u *User) GetData() (interface{}, apperror.Error)
- func (u *User) GetEmail() string
- func (u *User) GetLastLogin() time.Time
- func (a User) GetProfile() kit.UserProfile
- func (u *User) GetRoles() []string
- func (u *User) GetUpdatedAt() time.Time
- func (u *User) GetUsername() string
- func (u *User) HasPermission(perms ...string) bool
- func (u *User) HasRole(roles ...string) bool
- func (u *User) IsActive() bool
- func (u *User) IsEmailConfirmed() bool
- func (u *User) RemoveRole(roles ...string)
- func (u *User) SetCreatedAt(x time.Time)
- func (u *User) SetData(x interface{}) apperror.Error
- func (u *User) SetEmail(x string)
- func (u *User) SetIsActive(x bool)
- func (u *User) SetIsEmailConfirmed(x bool)
- func (u *User) SetLastLogin(x time.Time)
- func (u *User) SetRoles(roles []string)
- func (u *User) SetUpdatedAt(x time.Time)
- func (u *User) SetUsername(x string)
- type UserIntId
- type UserResourceHooks
- func (hooks UserResourceHooks) AllowDelete(res kit.Resource, obj kit.Model, old kit.Model, user kit.User) bool
- func (hooks UserResourceHooks) AllowFind(res kit.Resource, obj kit.Model, user kit.User) bool
- func (hooks UserResourceHooks) AllowUpdate(res kit.Resource, obj kit.Model, old kit.Model, user kit.User) bool
- func (hooks UserResourceHooks) ApiCreate(res kit.Resource, obj kit.Model, r kit.Request) kit.Response
- func (UserResourceHooks) Methods(res kit.Resource) []kit.Method
- type UserStrId
Constants ¶
This section is empty.
Variables ¶
View Source
var AuthenticateMethod kit.Method = &methods.Method{ Name: "users.authenticate", Blocking: true, Handler: func(registry kit.Registry, r kit.Request, unblock func()) kit.Response { if r.GetUser() != nil { return kit.NewErrorResponse("already_authenticated", "Can't authenticate a session which is already authenticated", true) } data, ok := r.GetData().(map[string]interface{}) if !ok { return kit.NewErrorResponse("invalid_data", "Invalid data: expected dict", true) } userIdentifier, _ := data["user"].(string) adaptor, _ := data["adaptor"].(string) if adaptor == "" { return kit.NewErrorResponse("adaptor_missing", "Expected 'adaptor' in metadata.", true) } authData, _ := data["authData"].(map[string]interface{}) if authData == nil { kit.NewErrorResponse("no_or_invalid_auth_data", "Expected 'authData' dictionary in metadata.") } userService := registry.UserService() user, err := userService.AuthenticateUser(userIdentifier, adaptor, authData) if err != nil { return kit.NewErrorResponse(err) } session := r.GetSession() if err := session.SetUserId(user.GetId()); err != nil { return kit.NewErrorResponse(err) } if err := userService.SessionResource().Update(session, user); err != nil { return kit.NewErrorResponse(err) } session.SetUser(user) return &kit.AppResponse{ Data: session, } }, }
View Source
var ResumeSessionMethod kit.Method = &methods.Method{ Name: "users.resume_session", Blocking: true, Handler: func(registry kit.Registry, r kit.Request, unblock func()) kit.Response { registry.Logger().Infof("data: %v", r.GetData()) data, _ := r.GetData().(map[string]interface{}) token, _ := data["token"].(string) if token == "" { return kit.NewErrorResponse("no_token", "Expected 'token' in data.", true) } user, session, err := registry.UserService().VerifySession(token) if err != nil { return kit.NewErrorResponse(err) } session.SetUser(user) curSession := r.GetSession() curSession.SetToken(token) curSession.SetValidUntil(session.GetValidUntil()) curSession.SetUser(user) return &kit.AppResponse{ Data: session, } }, }
View Source
var UnAuthenticateMethod kit.Method = &methods.Method{ Name: "users.unauthenticate", Blocking: true, Handler: func(registry kit.Registry, r kit.Request, unblock func()) kit.Response { if r.GetUser() == nil { return kit.NewErrorResponse("not_authenticated", "Can't un-authenticate a session which is not authenticated", true) } session := r.GetSession() session.SetUser(nil) if err := registry.UserService().SessionResource().Update(session, r.GetUser()); err != nil { return kit.NewErrorResponse(err) } return &kit.AppResponse{ Data: map[string]interface{}{}, } }, }
Functions ¶
func GetUserMigrations ¶
func GetUserMigrations(service kit.UserService) []db.Migration
Types ¶
type IntIdUserProfile ¶
type IntIdUserProfile struct {
db.IntIdModel
}
func (IntIdUserProfile) Collection ¶
func (p IntIdUserProfile) Collection() string
func (IntIdUserProfile) GetUser ¶
func (p IntIdUserProfile) GetUser() kit.User
func (IntIdUserProfile) GetUserId ¶
func (p IntIdUserProfile) GetUserId() interface{}
func (IntIdUserProfile) SetUser ¶
func (p IntIdUserProfile) SetUser(user kit.User)
func (*IntIdUserProfile) SetUserId ¶
func (p *IntIdUserProfile) SetUserId(id interface{}) error
type IntUserModel ¶
func (*IntUserModel) GetUser ¶
func (m *IntUserModel) GetUser() kit.User
func (*IntUserModel) GetUserId ¶
func (m *IntUserModel) GetUserId() interface{}
func (*IntUserModel) SetUser ¶
func (m *IntUserModel) SetUser(u kit.User)
func (*IntUserModel) SetUserId ¶
func (m *IntUserModel) SetUserId(id interface{}) error
type IntUserSession ¶
type IntUserSession struct { IntUserModel Session }
func (*IntUserSession) IsAnonymous ¶
func (s *IntUserSession) IsAnonymous() bool
type Permission ¶
type Permission struct {
Name string `db:"primary-key;max:200"`
}
func (Permission) Collection ¶
func (r Permission) Collection() string
func (Permission) GetId ¶
func (p Permission) GetId() interface{}
func (Permission) GetName ¶
func (r Permission) GetName() string
func (Permission) GetStrId ¶
func (p Permission) GetStrId() string
func (*Permission) SetId ¶
func (p *Permission) SetId(n interface{}) error
func (*Permission) SetName ¶
func (r *Permission) SetName(n string)
func (*Permission) SetStrId ¶
func (p *Permission) SetStrId(n string) error
type PermissionResourceHooks ¶
type PermissionResourceHooks struct {
resources.AdminResource
}
type Role ¶
type Role struct { Name string `db:"primary-key;max:200"` Permissions []*Permission `db:"m2m"` }
func (*Role) AddPermission ¶
func (*Role) ClearPermissions ¶
func (r *Role) ClearPermissions()
func (Role) Collection ¶
func (*Role) GetPermissions ¶
func (*Role) HasPermission ¶
func (*Role) RemovePermission ¶
func (*Role) SetPermissions ¶
type RoleResourceHooks ¶
type RoleResourceHooks struct {
resources.AdminResource
}
func (RoleResourceHooks) ApiAlterQuery ¶
type Service ¶
type Service struct { Users kit.Resource Profiles kit.Resource Sessions kit.Resource Tokens kit.Resource Roles kit.Resource Permissions kit.Resource AuthAdaptors map[string]kit.AuthAdaptor // contains filtered or unexported fields }
func NewService ¶
func (*Service) AddAuthAdaptor ¶
func (h *Service) AddAuthAdaptor(a kit.AuthAdaptor)
func (*Service) AuthAdaptor ¶
func (h *Service) AuthAdaptor(name string) kit.AuthAdaptor
func (*Service) AuthenticateUser ¶
func (*Service) BuildToken ¶
func (*Service) ChangePassword ¶
func (*Service) ConfirmEmail ¶
func (*Service) CreateUser ¶
func (*Service) FindUser ¶
FindUser tries to find a user based on either userId, user.Username or user.Email.
func (*Service) PermissionResource ¶
func (*Service) ProfileModel ¶
func (h *Service) ProfileModel() kit.UserProfile
func (*Service) ProfileResource ¶
func (*Service) ResetPassword ¶
func (*Service) RoleResource ¶
func (*Service) SendConfirmationEmail ¶
func (*Service) SendPasswordResetEmail ¶
func (*Service) SessionResource ¶
func (*Service) SetBackend ¶
func (*Service) SetPermissionResource ¶
func (*Service) SetProfileResource ¶
func (*Service) SetRegistry ¶
func (*Service) SetRoleResource ¶
func (*Service) SetSessionResource ¶
func (*Service) SetTokenResource ¶
func (*Service) SetUserResource ¶
func (Service) StartSession ¶
func (*Service) TokenResource ¶
func (*Service) UserResource ¶
type Session ¶
type Session struct { Token string `db:"primary-key;max:150"` Type string `db:"max:10"` StartedAt time.Time `db:"required"` ValidUntil time.Time `db:"required"` }
func (Session) Collection ¶
func (*Session) GetStartedAt ¶
func (*Session) GetValidUntil ¶
func (*Session) SetStartedAt ¶
func (*Session) SetValidUntil ¶
type SessionResourceHooks ¶
func (SessionResourceHooks) ApiCreate ¶
func (hooks SessionResourceHooks) ApiCreate(res kit.Resource, obj kit.Model, r kit.Request) kit.Response
Creating a session is equivalent to logging in.
func (SessionResourceHooks) ApiFindOne ¶
ApiFindOne verifies the session and returns user and profile in meta if valid.
type StrIdUserProfile ¶
type StrIdUserProfile struct {
db.StrIdModel
}
func (StrIdUserProfile) Collection ¶
func (p StrIdUserProfile) Collection() string
func (StrIdUserProfile) GetUser ¶
func (p StrIdUserProfile) GetUser() kit.User
func (StrIdUserProfile) GetUserId ¶
func (p StrIdUserProfile) GetUserId() interface{}
func (StrIdUserProfile) SetUser ¶
func (p StrIdUserProfile) SetUser(user kit.User)
func (*StrIdUserProfile) SetUserId ¶
func (p *StrIdUserProfile) SetUserId(id interface{}) error
type StrUserModel ¶
func (*StrUserModel) GetUser ¶
func (m *StrUserModel) GetUser() kit.User
func (*StrUserModel) GetUserId ¶
func (m *StrUserModel) GetUserId() interface{}
func (*StrUserModel) SetUser ¶
func (m *StrUserModel) SetUser(u kit.User)
func (*StrUserModel) SetUserId ¶
func (m *StrUserModel) SetUserId(id interface{}) error
type StrUserSession ¶
type StrUserSession struct { StrUserModel Session }
func (StrUserSession) IsAnonymous ¶
func (s StrUserSession) IsAnonymous() bool
type Token ¶
type Token struct { StrUserModel Token string `db:"primary-key"` Type string `db:"required"` ExpiresAt time.Time `db:"ignore-zero"` }
func (*Token) Collection ¶
func (*Token) GetExpiresAt ¶
func (*Token) SetExpiresAt ¶
type User ¶
type User struct { db.TimeStampedModel Active bool Username string `db:"unique;required"` Email string `db:"unique;required"` EmailConfirmed bool LastLogin time.Time `db:"ignore-zero"` Data string `db:"ignore-zero;max:10000"` Profile interface{} `db:"-"` Roles []*Role `db:"m2m;"` }
func (*User) ClearRoles ¶
func (u *User) ClearRoles()
func (User) Collection ¶
func (*User) GetCreatedAt ¶
func (*User) GetLastLogin ¶
func (User) GetProfile ¶
func (a User) GetProfile() kit.UserProfile
func (*User) GetUpdatedAt ¶
func (*User) GetUsername ¶
func (*User) HasPermission ¶
func (*User) IsEmailConfirmed ¶
func (*User) RemoveRole ¶
func (*User) SetCreatedAt ¶
func (*User) SetIsActive ¶
func (*User) SetIsEmailConfirmed ¶
func (*User) SetLastLogin ¶
func (*User) SetUpdatedAt ¶
func (*User) SetUsername ¶
type UserIntId ¶
type UserIntId struct { User db.IntIdModel }
func (*UserIntId) SetProfile ¶
func (u *UserIntId) SetProfile(p kit.UserProfile)
type UserResourceHooks ¶
type UserResourceHooks struct { }
func (UserResourceHooks) AllowDelete ¶
func (UserResourceHooks) AllowUpdate ¶
type UserStrId ¶
type UserStrId struct { User db.StrIdModel }
func (*UserStrId) SetProfile ¶
func (u *UserStrId) SetProfile(p kit.UserProfile)
Click to show internal directories.
Click to hide internal directories.