More context data for api calls

This commit is contained in:
Lukas Bachschwell 2018-11-15 18:10:24 +01:00
parent 5ab2296187
commit d9465d9330

View File

@ -3,10 +3,11 @@ package controllers
import (
"database/sql"
"fmt"
"multitenantStack/models"
companydb "multitenantStack/services/companydb"
"time"
"github.com/astaxie/beego/orm"
jwt "github.com/dgrijalva/jwt-go"
)
// BaseAPIController operations for APIs
@ -14,7 +15,15 @@ type BaseAPIController struct {
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 o orm.Ormer
@ -36,7 +45,18 @@ func (c *BaseAPIController) Prepare() {
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
o, err = orm.NewOrmWithDB("postgres", "company", companyDB)
if err != nil {