作者 唐旭辉

跨域设置

... ... @@ -378,16 +378,24 @@ func (c *CompanyController) InitCompany() {
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
CompanyId int64 `json:"company_id"`
}
var param Parameter
var param protocol.CenterCompanyInfo
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
err := servecompany.InitCompanyInfo(param.CompanyId)
var (
err error
)
if ok := param.IsEnable(); ok {
err = servecompany.InitCompanyInfo(param)
} else if ok := param.IsForbid(); ok {
} else {
err = protocol.NewErrWithMessage("1")
}
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -83,9 +83,11 @@ var AllowOption = func(ctx *context.Context) {
f := cors.Allow(&cors.Options{
AllowOrigins: []string{"*"}, //允许的请求来源
AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
AllowHeaders: []string{"*"}, //允许的头部信息
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin",
"x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken"}, //允许的头部信息
ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
AllowCredentials: false, //不允许共享AuthTuffic证书
AllowCredentials: false,
AllowAllOrigins: true, //不允许共享AuthTuffic证书
})
f(ctx)
ctx.Output.Body([]byte("{}"))
... ...
... ... @@ -111,3 +111,15 @@ func GetCompanyByUser(userid int64) ([]Company, error) {
}
return companys, err
}
func GetCompanyByUCenter(uCenterId int64) (*Company, error) {
var (
err error
)
data := &Company{}
o := orm.NewOrm()
err = o.QueryTable(&Company{}).
Filter("user_center_id", uCenterId).
One(data)
return data, err
}
... ...
... ... @@ -120,3 +120,26 @@ type ResponseCompanyBase struct {
Name string `json:"name"`
Logo string `json:"logo"`
}
type CenterCompanyInfo struct {
CompanyId int64 `json:"company_id"`
CompanyName string `json:"company_name"`
AdminId int64 `json:"admin_id"`
AdminAccount string `json:"admin_account"`
AdminName string `json:"admin_name"`
Status int8 `json:"status"`
}
func (c CenterCompanyInfo) IsEnable() bool {
if c.Status == 1 {
return true
}
return false
}
func (c CenterCompanyInfo) IsForbid() bool {
if c.Status == 2 {
return true
}
return false
}
... ...
... ... @@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
"oppmg/common/config"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
... ... @@ -17,15 +16,6 @@ import (
"github.com/astaxie/beego/orm"
)
//GetAccessToken 获取accessToken
func GetAccessToken(param protocol.RequestCheckSmsCode) (*protocol.DataUserInfo, error) {
data := &protocol.DataUserInfo{}
err := protocol.NewErrWithMessage("00000")
log.Info("log 打印")
log.Info("%+v", config.MConfig)
return data, err
}
//ValidatePassword ...
//from:待校验的密码;to:比对用的密文
func validatePassword(from, to string) bool {
... ... @@ -39,47 +29,6 @@ func validatePassword(from, to string) bool {
return false
}
//LoginAuth 登录认证
//TODO 登录校验逻辑修改
// func LoginAuthByPassword(account, password string) (protocol.LoginAuthToken, error) {
// var (
// user *models.User
// companys []models.Company
// mcompany models.Company
// loginToken protocol.LoginAuthToken
// err error
// )
// user, err = models.GetUserByPhone(account)
// if err != nil {
// log.Error(err.Error())
// return loginToken, protocol.NewErrWithMessage("10021", err)
// }
// if ok := validatePassword(password, user.Passwd); !ok {
// return loginToken, protocol.NewErrWithMessage("10021", err)
// }
// if ok := user.IsEnable(); !ok {
// return loginToken, protocol.NewErrWithMessage("10022")
// }
// companys, err = models.GetCompanyByUser(user.Id)
// if err != nil {
// e := fmt.Errorf("GetCompanyByUser(%d) err:%s", user.Id, err)
// log.Error(e.Error())
// return loginToken, protocol.NewErrWithMessage("1")
// }
// if len(companys) <= 0 {
// log.Error("can not found company")
// return loginToken, protocol.NewErrWithMessage("1")
// }
// mcompany = companys[0]
// loginToken, err = GenerateAuthToken(user.Id, mcompany.Id)
// if err != nil {
// e := fmt.Errorf("GenerateAuthToken err:%s", err)
// log.Error(e.Error())
// return loginToken, protocol.NewErrWithMessage("1")
// }
// return loginToken, nil
// }
//ResetLoginToken token存数据库
func ResetLoginToken(loginToken protocol.LoginAuthToken) error {
var (
... ...
... ... @@ -9,38 +9,38 @@ import (
"github.com/astaxie/beego/orm"
)
type CenterCompanyInfo struct {
CompanyId int64
CompanyName string
AdminId int64
AdminAccount string
AdminName string
}
// type CenterCompanyInfo struct {
// CompanyId int64
// CompanyName string
// AdminId int64
// AdminAccount string
// AdminName string
// }
func GetCenterCompanyInfo(companyid int64) (CenterCompanyInfo, error) {
// func GetCenterCompanyInfo(companyid int64) (CenterCompanyInfo, error) {
//TODO 调用统一用户中心的数据
data := CenterCompanyInfo{
CompanyId: 9999 + companyid,
CompanyName: "调试用公司数据",
AdminId: 9999 + companyid,
AdminAccount: "调试用自己修改",
AdminName: "调试用自己修改",
}
return data, nil
}
// //TODO 调用统一用户中心的数据
// data := CenterCompanyInfo{
// CompanyId: 9999 + companyid,
// CompanyName: "调试用公司数据",
// AdminId: 9999 + companyid,
// AdminAccount: "调试用自己修改",
// AdminName: "调试用自己修改",
// }
// return data, nil
// }
//InitCompanyInfo 初始化公司
//@uCompanyid 从统一用户中心获取的公司id companyid,
func InitCompanyInfo(uCompanyid int64) error {
var (
centerCompany CenterCompanyInfo
err error
)
centerCompany, err = GetCenterCompanyInfo(uCompanyid)
if err != nil {
return protocol.NewErrWithMessage("10051")
}
func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {
// var (
// centerCompany CenterCompanyInfo
// err error
// )
// centerCompany, err = GetCenterCompanyInfo(uCompanyid)
// if err != nil {
// return protocol.NewErrWithMessage("10051")
// }
var (
newDeparment *models.Department
//newUserDepart = &models.UserDepartment{}
... ... @@ -49,6 +49,7 @@ func InitCompanyInfo(uCompanyid int64) error {
newUser *models.User
newCompany *models.Company
newUserCompany *models.UserCompany
err error
)
o := orm.NewOrm()
o.Begin()
... ... @@ -112,7 +113,7 @@ func InitCompanyInfo(uCompanyid int64) error {
return nil
}
func initCompany(centerCompany CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) {
func initCompany(centerCompany protocol.CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) {
var (
err error
newCompany = &models.Company{}
... ... @@ -152,7 +153,7 @@ func initCompany(centerCompany CenterCompanyInfo, admininfo *models.User, o orm.
return newCompany, nil
}
func initAdminUser(centerCompany CenterCompanyInfo, o orm.Ormer) (*models.User, error) {
func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*models.User, error) {
var (
err error
newUser = &models.User{}
... ... @@ -437,3 +438,15 @@ func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) {
}
return companyinfo, nil
}
func ForbidCompany(ucenterCompany int64) error {
// var (
// err error
// companyData *models.Company
// )
// companyData, err = models.GetCompanyByUCenter(ucenterCompany)
// if err == orm.ErrNoRows {
// // log.Info()
// }
return nil
}
... ...