1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-08-06 22:32:51 +02:00

Completed virtual user login and switch accounts

This commit is contained in:
Lee Brown
2019-08-04 21:28:02 -08:00
parent bb9820ffcc
commit ba96e8b367
23 changed files with 1541 additions and 176 deletions

View File

@ -66,6 +66,34 @@ func (m *UserAccount) Response(ctx context.Context) *UserAccountResponse {
return r
}
// HasRole checks if the entry has a role.
func (m *UserAccount) HasRole(role UserAccountRole) bool {
if m == nil {
return false
}
for _, r := range m.Roles {
if r == role {
return true
}
}
return false
}
// UserAccounts a list of UserAccounts.
type UserAccounts []*UserAccount
// Response transforms a list of UserAccounts to a list of UserAccountResponses.
func (m *UserAccounts) Response(ctx context.Context) []*UserAccountResponse {
var l []*UserAccountResponse
if m != nil && len(*m) > 0 {
for _, n := range *m {
l = append(l, n.Response(ctx))
}
}
return l
}
// UserAccountCreateRequest defines the information is needed to associate a user to an
// account. Users are global to the application and each users access can be managed
// on an account level. If a current entry exists in the database but is archived,