User / Account model split, User and account now seperate entities, collaborators are now AccountUsers

This commit is contained in:
Torkel Ödegaard
2015-01-19 18:01:04 +01:00
parent f1996a9f1f
commit 90925273a0
29 changed files with 592 additions and 705 deletions
+8 -8
View File
@@ -14,18 +14,18 @@ type AuthOptions struct {
ReqSignedIn bool
}
func getRequestAccountId(c *Context) int64 {
accountId := c.Session.Get("accountId")
func getRequestUserId(c *Context) int64 {
userId := c.Session.Get("userId")
if accountId != nil {
return accountId.(int64)
if userId != nil {
return userId.(int64)
}
// TODO: figure out a way to secure this
if c.Query("render") == "1" {
accountId := c.QueryInt64("accountId")
c.Session.Set("accountId", accountId)
return accountId
userId := c.QueryInt64("userId")
c.Session.Set("userId", userId)
return userId
}
return 0
@@ -54,7 +54,7 @@ func RoleAuth(roles ...m.RoleType) macaron.Handler {
return func(c *Context) {
ok := false
for _, role := range roles {
if role == c.UserRole {
if role == c.AccountRole {
ok = true
break
}
+7 -13
View File
@@ -31,10 +31,10 @@ func GetContextHandler() macaron.Handler {
}
// try get account id from request
if accountId := getRequestAccountId(ctx); accountId != 0 {
query := m.GetSignedInUserQuery{AccountId: accountId}
if userId := getRequestUserId(ctx); userId != 0 {
query := m.GetSignedInUserQuery{UserId: userId}
if err := bus.Dispatch(&query); err != nil {
log.Error(3, "Failed to get user by id, %v, %v", accountId, err)
log.Error(3, "Failed to get user by id, %v, %v", userId, err)
} else {
ctx.IsSignedIn = true
ctx.SignedInUser = query.Result
@@ -47,20 +47,14 @@ func GetContextHandler() macaron.Handler {
return
} else {
tokenInfo := tokenQuery.Result
query := m.GetSignedInUserQuery{AccountId: tokenInfo.AccountId}
if err := bus.Dispatch(&query); err != nil {
ctx.JsonApiErr(401, "Invalid token", err)
return
}
ctx.IsSignedIn = true
ctx.SignedInUser = query.Result
ctx.SignedInUser = &m.SignedInUser{}
// api key role
ctx.UserRole = tokenInfo.Role
// TODO: fix this
ctx.AccountRole = tokenInfo.Role
ctx.ApiKeyId = tokenInfo.Id
ctx.UsingAccountId = ctx.AccountId
ctx.UsingAccountName = ctx.UserName
ctx.AccountId = tokenInfo.AccountId
}
}