More context data for api calls
This commit is contained in:
parent
5ab2296187
commit
d9465d9330
@ -3,10 +3,11 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"multitenantStack/models"
|
||||||
companydb "multitenantStack/services/companydb"
|
companydb "multitenantStack/services/companydb"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// BaseAPIController operations for APIs
|
// BaseAPIController operations for APIs
|
||||||
@ -14,7 +15,15 @@ type BaseAPIController struct {
|
|||||||
BaseController
|
BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
var jwtSession jwt.MapClaims
|
type SessionData struct {
|
||||||
|
Email string
|
||||||
|
CompanyName string
|
||||||
|
CompanyUserID int
|
||||||
|
Exp time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var jwtSession SessionData
|
||||||
|
var currentUser *models.CompanyUser
|
||||||
var companyDB *sql.DB
|
var companyDB *sql.DB
|
||||||
var o orm.Ormer
|
var o orm.Ormer
|
||||||
|
|
||||||
@ -36,7 +45,18 @@ func (c *BaseAPIController) Prepare() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jwtSession = token
|
jwtSession.Email = token["email"].(string)
|
||||||
|
jwtSession.CompanyName = token["companyName"].(string)
|
||||||
|
jwtSession.CompanyUserID = token["companyUserID"].(int)
|
||||||
|
jwtSession.Exp = token["exp"].(time.Time)
|
||||||
|
|
||||||
|
companyUser, err := models.GetCompanyUserById(o, int(jwtSession.CompanyUserID))
|
||||||
|
if err != nil {
|
||||||
|
c.ServeJSONError("Error retrieving Company User")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
currentUser = companyUser
|
||||||
|
|
||||||
companyDB = db
|
companyDB = db
|
||||||
o, err = orm.NewOrmWithDB("postgres", "company", companyDB)
|
o, err = orm.NewOrmWithDB("postgres", "company", companyDB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user