作者 唐旭辉

跨域设置

@@ -378,16 +378,24 @@ func (c *CompanyController) InitCompany() { @@ -378,16 +378,24 @@ func (c *CompanyController) InitCompany() {
378 defer func() { 378 defer func() {
379 c.ResposeJson(msg) 379 c.ResposeJson(msg)
380 }() 380 }()
381 - type Parameter struct {  
382 - CompanyId int64 `json:"company_id"`  
383 - }  
384 - var param Parameter 381 +
  382 + var param protocol.CenterCompanyInfo
385 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 383 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
386 log.Error("json 解析失败 err:%s", err) 384 log.Error("json 解析失败 err:%s", err)
387 msg = protocol.BadRequestParam("1") 385 msg = protocol.BadRequestParam("1")
388 return 386 return
389 } 387 }
390 - err := servecompany.InitCompanyInfo(param.CompanyId) 388 + var (
  389 + err error
  390 + )
  391 + if ok := param.IsEnable(); ok {
  392 + err = servecompany.InitCompanyInfo(param)
  393 + } else if ok := param.IsForbid(); ok {
  394 +
  395 + } else {
  396 + err = protocol.NewErrWithMessage("1")
  397 + }
  398 +
391 msg = protocol.NewReturnResponse(nil, err) 399 msg = protocol.NewReturnResponse(nil, err)
392 return 400 return
393 } 401 }
@@ -81,11 +81,13 @@ var AllowOption = func(ctx *context.Context) { @@ -81,11 +81,13 @@ var AllowOption = func(ctx *context.Context) {
81 return 81 return
82 } 82 }
83 f := cors.Allow(&cors.Options{ 83 f := cors.Allow(&cors.Options{
84 - AllowOrigins: []string{"*"}, //允许的请求来源  
85 - AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型  
86 - AllowHeaders: []string{"*"}, //允许的头部信息  
87 - ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息  
88 - AllowCredentials: false, //不允许共享AuthTuffic证书 84 + AllowOrigins: []string{"*"}, //允许的请求来源
  85 + AllowMethods: []string{"POST", "GET", "OPTIONS", "PUT", "DELETE"}, //允许的请求类型
  86 + AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin",
  87 + "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken"}, //允许的头部信息
  88 + ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
  89 + AllowCredentials: false,
  90 + AllowAllOrigins: true, //不允许共享AuthTuffic证书
89 }) 91 })
90 f(ctx) 92 f(ctx)
91 ctx.Output.Body([]byte("{}")) 93 ctx.Output.Body([]byte("{}"))
@@ -111,3 +111,15 @@ func GetCompanyByUser(userid int64) ([]Company, error) { @@ -111,3 +111,15 @@ func GetCompanyByUser(userid int64) ([]Company, error) {
111 } 111 }
112 return companys, err 112 return companys, err
113 } 113 }
  114 +
  115 +func GetCompanyByUCenter(uCenterId int64) (*Company, error) {
  116 + var (
  117 + err error
  118 + )
  119 + data := &Company{}
  120 + o := orm.NewOrm()
  121 + err = o.QueryTable(&Company{}).
  122 + Filter("user_center_id", uCenterId).
  123 + One(data)
  124 + return data, err
  125 +}
@@ -120,3 +120,26 @@ type ResponseCompanyBase struct { @@ -120,3 +120,26 @@ type ResponseCompanyBase struct {
120 Name string `json:"name"` 120 Name string `json:"name"`
121 Logo string `json:"logo"` 121 Logo string `json:"logo"`
122 } 122 }
  123 +
  124 +type CenterCompanyInfo struct {
  125 + CompanyId int64 `json:"company_id"`
  126 + CompanyName string `json:"company_name"`
  127 + AdminId int64 `json:"admin_id"`
  128 + AdminAccount string `json:"admin_account"`
  129 + AdminName string `json:"admin_name"`
  130 + Status int8 `json:"status"`
  131 +}
  132 +
  133 +func (c CenterCompanyInfo) IsEnable() bool {
  134 + if c.Status == 1 {
  135 + return true
  136 + }
  137 + return false
  138 +}
  139 +
  140 +func (c CenterCompanyInfo) IsForbid() bool {
  141 + if c.Status == 2 {
  142 + return true
  143 + }
  144 + return false
  145 +}
@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "encoding/hex" 5 "encoding/hex"
6 "fmt" 6 "fmt"
7 "io" 7 "io"
8 - "oppmg/common/config"  
9 "oppmg/common/log" 8 "oppmg/common/log"
10 "oppmg/models" 9 "oppmg/models"
11 "oppmg/protocol" 10 "oppmg/protocol"
@@ -17,15 +16,6 @@ import ( @@ -17,15 +16,6 @@ import (
17 "github.com/astaxie/beego/orm" 16 "github.com/astaxie/beego/orm"
18 ) 17 )
19 18
20 -//GetAccessToken 获取accessToken  
21 -func GetAccessToken(param protocol.RequestCheckSmsCode) (*protocol.DataUserInfo, error) {  
22 - data := &protocol.DataUserInfo{}  
23 - err := protocol.NewErrWithMessage("00000")  
24 - log.Info("log 打印")  
25 - log.Info("%+v", config.MConfig)  
26 - return data, err  
27 -}  
28 -  
29 //ValidatePassword ... 19 //ValidatePassword ...
30 //from:待校验的密码;to:比对用的密文 20 //from:待校验的密码;to:比对用的密文
31 func validatePassword(from, to string) bool { 21 func validatePassword(from, to string) bool {
@@ -39,47 +29,6 @@ func validatePassword(from, to string) bool { @@ -39,47 +29,6 @@ func validatePassword(from, to string) bool {
39 return false 29 return false
40 } 30 }
41 31
42 -//LoginAuth 登录认证  
43 -//TODO 登录校验逻辑修改  
44 -// func LoginAuthByPassword(account, password string) (protocol.LoginAuthToken, error) {  
45 -// var (  
46 -// user *models.User  
47 -// companys []models.Company  
48 -// mcompany models.Company  
49 -// loginToken protocol.LoginAuthToken  
50 -// err error  
51 -// )  
52 -// user, err = models.GetUserByPhone(account)  
53 -// if err != nil {  
54 -// log.Error(err.Error())  
55 -// return loginToken, protocol.NewErrWithMessage("10021", err)  
56 -// }  
57 -// if ok := validatePassword(password, user.Passwd); !ok {  
58 -// return loginToken, protocol.NewErrWithMessage("10021", err)  
59 -// }  
60 -// if ok := user.IsEnable(); !ok {  
61 -// return loginToken, protocol.NewErrWithMessage("10022")  
62 -// }  
63 -// companys, err = models.GetCompanyByUser(user.Id)  
64 -// if err != nil {  
65 -// e := fmt.Errorf("GetCompanyByUser(%d) err:%s", user.Id, err)  
66 -// log.Error(e.Error())  
67 -// return loginToken, protocol.NewErrWithMessage("1")  
68 -// }  
69 -// if len(companys) <= 0 {  
70 -// log.Error("can not found company")  
71 -// return loginToken, protocol.NewErrWithMessage("1")  
72 -// }  
73 -// mcompany = companys[0]  
74 -// loginToken, err = GenerateAuthToken(user.Id, mcompany.Id)  
75 -// if err != nil {  
76 -// e := fmt.Errorf("GenerateAuthToken err:%s", err)  
77 -// log.Error(e.Error())  
78 -// return loginToken, protocol.NewErrWithMessage("1")  
79 -// }  
80 -// return loginToken, nil  
81 -// }  
82 -  
83 //ResetLoginToken token存数据库 32 //ResetLoginToken token存数据库
84 func ResetLoginToken(loginToken protocol.LoginAuthToken) error { 33 func ResetLoginToken(loginToken protocol.LoginAuthToken) error {
85 var ( 34 var (
@@ -9,38 +9,38 @@ import ( @@ -9,38 +9,38 @@ import (
9 "github.com/astaxie/beego/orm" 9 "github.com/astaxie/beego/orm"
10 ) 10 )
11 11
12 -type CenterCompanyInfo struct {  
13 - CompanyId int64  
14 - CompanyName string  
15 - AdminId int64  
16 - AdminAccount string  
17 - AdminName string  
18 -} 12 +// type CenterCompanyInfo struct {
  13 +// CompanyId int64
  14 +// CompanyName string
  15 +// AdminId int64
  16 +// AdminAccount string
  17 +// AdminName string
  18 +// }
19 19
20 -func GetCenterCompanyInfo(companyid int64) (CenterCompanyInfo, error) { 20 +// func GetCenterCompanyInfo(companyid int64) (CenterCompanyInfo, error) {
21 21
22 - //TODO 调用统一用户中心的数据  
23 - data := CenterCompanyInfo{  
24 - CompanyId: 9999 + companyid,  
25 - CompanyName: "调试用公司数据",  
26 - AdminId: 9999 + companyid,  
27 - AdminAccount: "调试用自己修改",  
28 - AdminName: "调试用自己修改",  
29 - }  
30 - return data, nil  
31 -} 22 +// //TODO 调用统一用户中心的数据
  23 +// data := CenterCompanyInfo{
  24 +// CompanyId: 9999 + companyid,
  25 +// CompanyName: "调试用公司数据",
  26 +// AdminId: 9999 + companyid,
  27 +// AdminAccount: "调试用自己修改",
  28 +// AdminName: "调试用自己修改",
  29 +// }
  30 +// return data, nil
  31 +// }
32 32
33 //InitCompanyInfo 初始化公司 33 //InitCompanyInfo 初始化公司
34 //@uCompanyid 从统一用户中心获取的公司id companyid, 34 //@uCompanyid 从统一用户中心获取的公司id companyid,
35 -func InitCompanyInfo(uCompanyid int64) error {  
36 - var (  
37 - centerCompany CenterCompanyInfo  
38 - err error  
39 - )  
40 - centerCompany, err = GetCenterCompanyInfo(uCompanyid)  
41 - if err != nil {  
42 - return protocol.NewErrWithMessage("10051")  
43 - } 35 +func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error {
  36 + // var (
  37 + // centerCompany CenterCompanyInfo
  38 + // err error
  39 + // )
  40 + // centerCompany, err = GetCenterCompanyInfo(uCompanyid)
  41 + // if err != nil {
  42 + // return protocol.NewErrWithMessage("10051")
  43 + // }
44 var ( 44 var (
45 newDeparment *models.Department 45 newDeparment *models.Department
46 //newUserDepart = &models.UserDepartment{} 46 //newUserDepart = &models.UserDepartment{}
@@ -49,6 +49,7 @@ func InitCompanyInfo(uCompanyid int64) error { @@ -49,6 +49,7 @@ func InitCompanyInfo(uCompanyid int64) error {
49 newUser *models.User 49 newUser *models.User
50 newCompany *models.Company 50 newCompany *models.Company
51 newUserCompany *models.UserCompany 51 newUserCompany *models.UserCompany
  52 + err error
52 ) 53 )
53 o := orm.NewOrm() 54 o := orm.NewOrm()
54 o.Begin() 55 o.Begin()
@@ -112,7 +113,7 @@ func InitCompanyInfo(uCompanyid int64) error { @@ -112,7 +113,7 @@ func InitCompanyInfo(uCompanyid int64) error {
112 return nil 113 return nil
113 } 114 }
114 115
115 -func initCompany(centerCompany CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) { 116 +func initCompany(centerCompany protocol.CenterCompanyInfo, admininfo *models.User, o orm.Ormer) (*models.Company, error) {
116 var ( 117 var (
117 err error 118 err error
118 newCompany = &models.Company{} 119 newCompany = &models.Company{}
@@ -152,7 +153,7 @@ func initCompany(centerCompany CenterCompanyInfo, admininfo *models.User, o orm. @@ -152,7 +153,7 @@ func initCompany(centerCompany CenterCompanyInfo, admininfo *models.User, o orm.
152 return newCompany, nil 153 return newCompany, nil
153 } 154 }
154 155
155 -func initAdminUser(centerCompany CenterCompanyInfo, o orm.Ormer) (*models.User, error) { 156 +func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*models.User, error) {
156 var ( 157 var (
157 err error 158 err error
158 newUser = &models.User{} 159 newUser = &models.User{}
@@ -437,3 +438,15 @@ func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) { @@ -437,3 +438,15 @@ func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) {
437 } 438 }
438 return companyinfo, nil 439 return companyinfo, nil
439 } 440 }
  441 +
  442 +func ForbidCompany(ucenterCompany int64) error {
  443 + // var (
  444 + // err error
  445 + // companyData *models.Company
  446 + // )
  447 + // companyData, err = models.GetCompanyByUCenter(ucenterCompany)
  448 + // if err == orm.ErrNoRows {
  449 + // // log.Info()
  450 + // }
  451 + return nil
  452 +}