正在显示
16 个修改的文件
包含
314 行增加
和
53 行删除
| 1 | #app的名称 | 1 | #app的名称 |
| 2 | appname = ability | 2 | appname = ability |
| 3 | #运行模式 | 3 | #运行模式 |
| 4 | -runmode =${ProRunMode||test} | 4 | +runmode =${ProRunMode||dev} |
| 5 | #是否自动渲染页面 | 5 | #是否自动渲染页面 |
| 6 | autorender = false | 6 | autorender = false |
| 7 | #是否复制请求body | 7 | #是否复制请求body |
| @@ -9,6 +9,7 @@ copyrequestbody = true | @@ -9,6 +9,7 @@ copyrequestbody = true | ||
| 9 | #开启应用内文档 | 9 | #开启应用内文档 |
| 10 | EnableDocs = false | 10 | EnableDocs = false |
| 11 | 11 | ||
| 12 | + | ||
| 12 | include "dev.conf" | 13 | include "dev.conf" |
| 13 | include "prod.conf" | 14 | include "prod.conf" |
| 14 | include "local.conf" | 15 | include "local.conf" |
| @@ -2,10 +2,15 @@ package controllers | @@ -2,10 +2,15 @@ package controllers | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | + "fmt" | ||
| 5 | "oppmg/common/log" | 6 | "oppmg/common/log" |
| 6 | "oppmg/protocol" | 7 | "oppmg/protocol" |
| 7 | serveauth "oppmg/services/auth" | 8 | serveauth "oppmg/services/auth" |
| 8 | "oppmg/storage/redisdata" | 9 | "oppmg/storage/redisdata" |
| 10 | + "strconv" | ||
| 11 | + "time" | ||
| 12 | + | ||
| 13 | + "github.com/GeeTeam/gt3-golang-sdk/geetest" | ||
| 9 | ) | 14 | ) |
| 10 | 15 | ||
| 11 | type AuthController struct { | 16 | type AuthController struct { |
| @@ -117,15 +122,15 @@ func (c *AuthController) Me() { | @@ -117,15 +122,15 @@ func (c *AuthController) Me() { | ||
| 117 | companyid := c.GetCompanyId() | 122 | companyid := c.GetCompanyId() |
| 118 | userinfo, err := serveauth.UserBaseInfo(userid, companyid) | 123 | userinfo, err := serveauth.UserBaseInfo(userid, companyid) |
| 119 | if err != nil { | 124 | if err != nil { |
| 120 | - log.Error("%s", err) | 125 | + log.Error("获取用户数据失败") |
| 121 | } | 126 | } |
| 122 | menus, err := serveauth.GetUserHasMenu(userid, companyid) | 127 | menus, err := serveauth.GetUserHasMenu(userid, companyid) |
| 123 | if err != nil { | 128 | if err != nil { |
| 124 | - log.Error("%s", err) | 129 | + log.Error("获取用户菜单") |
| 125 | } | 130 | } |
| 126 | companys, err := serveauth.UserHasCompanys(userid) | 131 | companys, err := serveauth.UserHasCompanys(userid) |
| 127 | if err != nil { | 132 | if err != nil { |
| 128 | - log.Error("%s", err) | 133 | + log.Error("获取用户的公司") |
| 129 | } | 134 | } |
| 130 | data := map[string]interface{}{ | 135 | data := map[string]interface{}{ |
| 131 | "user": userinfo, | 136 | "user": userinfo, |
| @@ -135,3 +140,53 @@ func (c *AuthController) Me() { | @@ -135,3 +140,53 @@ func (c *AuthController) Me() { | ||
| 135 | msg = protocol.NewReturnResponse(data, nil) | 140 | msg = protocol.NewReturnResponse(data, nil) |
| 136 | return | 141 | return |
| 137 | } | 142 | } |
| 143 | + | ||
| 144 | +const ( | ||
| 145 | + captchaID = "48a6ebac4ebc6642d68c217fca33eb4d" | ||
| 146 | + privateKey = "4f1c085290bec5afdc54df73535fc361" | ||
| 147 | +) | ||
| 148 | + | ||
| 149 | +func (c *AuthController) RegisterGeetest() { | ||
| 150 | + geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second) | ||
| 151 | + status, responseBt := geetest.PreProcess("", "") | ||
| 152 | + c.SetSession("geetest_status", status) | ||
| 153 | + c.Ctx.Output.Body(responseBt) | ||
| 154 | + return | ||
| 155 | +} | ||
| 156 | + | ||
| 157 | +func (c *AuthController) ValidateGeetest() { | ||
| 158 | + type Parameter struct { | ||
| 159 | + GeetestChallenge string `form:"geetest_challenge"` | ||
| 160 | + GeetestValidate string `form:"geetest_validate"` | ||
| 161 | + GeetestSeccode string `form:"geetest_seccode"` | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + var ( | ||
| 165 | + param Parameter | ||
| 166 | + geetestRes bool | ||
| 167 | + status int | ||
| 168 | + ) | ||
| 169 | + err := c.ParseForm(¶m) | ||
| 170 | + if err != nil { | ||
| 171 | + log.Error("解析表单数据失败;%s", err) | ||
| 172 | + } | ||
| 173 | + val := c.GetSession("geetest_status") | ||
| 174 | + status, _ = strconv.Atoi(fmt.Sprint(val)) | ||
| 175 | + geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second) | ||
| 176 | + if status == 1 { | ||
| 177 | + geetestRes = geetest.SuccessValidate(param.GeetestChallenge, param.GeetestValidate, param.GeetestSeccode, "", "") | ||
| 178 | + } else { | ||
| 179 | + geetestRes = geetest.FailbackValidate(param.GeetestChallenge, param.GeetestValidate, param.GeetestSeccode) | ||
| 180 | + } | ||
| 181 | + res := make(map[string]interface{}) | ||
| 182 | + if geetestRes { | ||
| 183 | + res["code"] = 0 | ||
| 184 | + res["msg"] = "Success" | ||
| 185 | + } else { | ||
| 186 | + res["code"] = -100 | ||
| 187 | + res["msg"] = "Failed" | ||
| 188 | + } | ||
| 189 | + responseBt, _ := json.Marshal(res) | ||
| 190 | + c.Ctx.Output.Body(responseBt) | ||
| 191 | + return | ||
| 192 | +} |
| @@ -20,14 +20,14 @@ type BaseController struct { | @@ -20,14 +20,14 @@ type BaseController struct { | ||
| 20 | 20 | ||
| 21 | //Prepare 实现beego.ControllerInterface 的接口 | 21 | //Prepare 实现beego.ControllerInterface 的接口 |
| 22 | func (this *BaseController) Prepare() { | 22 | func (this *BaseController) Prepare() { |
| 23 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") | ||
| 24 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
| 25 | - if this.Ctx.Input.Method() == "OPTIONS" { | ||
| 26 | - this.Ctx.ResponseWriter.WriteHeader(204) | ||
| 27 | - this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
| 28 | - //this.Ctx.WriteString("") | ||
| 29 | - return | ||
| 30 | - } | 23 | + // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") |
| 24 | + // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*") | ||
| 25 | + // if this.Ctx.Input.Method() == "OPTIONS" { | ||
| 26 | + // this.Ctx.ResponseWriter.WriteHeader(204) | ||
| 27 | + // this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") | ||
| 28 | + // //this.Ctx.WriteString("") | ||
| 29 | + // return | ||
| 30 | + // } | ||
| 31 | p := this.Ctx.Input.GetData("RouterPattern") | 31 | p := this.Ctx.Input.GetData("RouterPattern") |
| 32 | fmt.Println("====>r:", p) | 32 | fmt.Println("====>r:", p) |
| 33 | } | 33 | } |
| @@ -415,7 +415,6 @@ func (c *CompanyController) InitCompany() { | @@ -415,7 +415,6 @@ func (c *CompanyController) InitCompany() { | ||
| 415 | } else { | 415 | } else { |
| 416 | err = protocol.NewErrWithMessage("1") | 416 | err = protocol.NewErrWithMessage("1") |
| 417 | } | 417 | } |
| 418 | - | ||
| 419 | msg = protocol.NewReturnResponse(nil, err) | 418 | msg = protocol.NewReturnResponse(nil, err) |
| 420 | return | 419 | return |
| 421 | } | 420 | } |
| @@ -440,6 +439,42 @@ func (c *CompanyController) GetCompanyForUCenter() { | @@ -440,6 +439,42 @@ func (c *CompanyController) GetCompanyForUCenter() { | ||
| 440 | return | 439 | return |
| 441 | } | 440 | } |
| 442 | 441 | ||
| 442 | +//获取用户详情 | ||
| 443 | +//@router /user/info | ||
| 444 | +func (c *CompanyController) UserDetail() { | ||
| 445 | + var msg *protocol.ResponseMessage | ||
| 446 | + defer func() { | ||
| 447 | + c.ResposeJson(msg) | ||
| 448 | + }() | ||
| 449 | + type Parameter struct { | ||
| 450 | + UserCompanyId int64 `json:"user_company_id"` | ||
| 451 | + } | ||
| 452 | + var param Parameter | ||
| 453 | + if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 454 | + log.Error("json 解析失败 err:%s", err) | ||
| 455 | + msg = protocol.BadRequestParam("1") | ||
| 456 | + return | ||
| 457 | + } | ||
| 458 | + userdata, _ := servecompany.GetUserData(param.UserCompanyId) | ||
| 459 | + departs := servecompany.GetUserDepartment(param.UserCompanyId) | ||
| 460 | + positions := servecompany.GetUserPosition(param.UserCompanyId) | ||
| 461 | + roles := servecompany.GetUserRole(param.UserCompanyId) | ||
| 462 | + type ResponseUserDetail struct { | ||
| 463 | + protocol.UserInfoBase | ||
| 464 | + Departs []protocol.DepartmentBase `json:"departs"` | ||
| 465 | + Positions []protocol.PositionBase `json:"positions"` | ||
| 466 | + Roles []protocol.RoleBase `json:"roles"` | ||
| 467 | + } | ||
| 468 | + data := ResponseUserDetail{ | ||
| 469 | + UserInfoBase: userdata, | ||
| 470 | + Departs: departs, | ||
| 471 | + Positions: positions, | ||
| 472 | + Roles: roles, | ||
| 473 | + } | ||
| 474 | + msg = protocol.NewReturnResponse(data, nil) | ||
| 475 | + return | ||
| 476 | +} | ||
| 477 | + | ||
| 443 | //DepartmentUser 获取部门下成员 | 478 | //DepartmentUser 获取部门下成员 |
| 444 | //@router /department/user [post] | 479 | //@router /department/user [post] |
| 445 | func (c *CompanyController) DepartmentUser() { | 480 | func (c *CompanyController) DepartmentUser() { |
| @@ -489,15 +524,6 @@ func (c *CompanyController) CurrentCompanyInfo() { | @@ -489,15 +524,6 @@ func (c *CompanyController) CurrentCompanyInfo() { | ||
| 489 | defer func() { | 524 | defer func() { |
| 490 | c.ResposeJson(msg) | 525 | c.ResposeJson(msg) |
| 491 | }() | 526 | }() |
| 492 | - // type Parameter struct { | ||
| 493 | - // Logo string `json:"string"` | ||
| 494 | - // } | ||
| 495 | - // var param Parameter | ||
| 496 | - // if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 497 | - // log.Error("json 解析失败 err:%s", err) | ||
| 498 | - // msg = protocol.BadRequestParam("1") | ||
| 499 | - // return | ||
| 500 | - // } | ||
| 501 | companyid := c.GetCompanyId() | 527 | companyid := c.GetCompanyId() |
| 502 | companybase, err := servecompany.CompanyBaseInfo(companyid) | 528 | companybase, err := servecompany.CompanyBaseInfo(companyid) |
| 503 | msg = protocol.NewReturnResponse(companybase, err) | 529 | msg = protocol.NewReturnResponse(companybase, err) |
| @@ -4,6 +4,7 @@ go 1.13 | @@ -4,6 +4,7 @@ go 1.13 | ||
| 4 | 4 | ||
| 5 | require ( | 5 | require ( |
| 6 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 | 6 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 |
| 7 | + github.com/GeeTeam/gt3-golang-sdk v0.0.0-20190704102600-e89c6d964c8f | ||
| 7 | github.com/astaxie/beego v1.11.1 | 8 | github.com/astaxie/beego v1.11.1 |
| 8 | github.com/dgrijalva/jwt-go v3.2.0+incompatible | 9 | github.com/dgrijalva/jwt-go v3.2.0+incompatible |
| 9 | github.com/go-redis/redis v6.15.6+incompatible | 10 | github.com/go-redis/redis v6.15.6+incompatible |
| 1 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 h1:StMrA6UQ5Cm6206DxXGuV/NMqSIOIDoMXMYt8JPe1lE= | 1 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 h1:StMrA6UQ5Cm6206DxXGuV/NMqSIOIDoMXMYt8JPe1lE= |
| 2 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2/go.mod h1:EfRHD2k+Kd7ijnqlwOrH1IifwgWB9yYJ0pdXtBZmlpU= | 2 | github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2/go.mod h1:EfRHD2k+Kd7ijnqlwOrH1IifwgWB9yYJ0pdXtBZmlpU= |
| 3 | +github.com/GeeTeam/gt3-golang-sdk v0.0.0-20190704102600-e89c6d964c8f h1:FpIAcTBZpoM5uD2+zKbTyT+6Oz0efWw4ZWnr8FtdQ+g= | ||
| 4 | +github.com/GeeTeam/gt3-golang-sdk v0.0.0-20190704102600-e89c6d964c8f/go.mod h1:vqCh/LExdPmL5SULXE/9DHbuE4t3iLkzRYoNGxEvg/o= | ||
| 3 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= | 5 | github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= |
| 4 | github.com/astaxie/beego v1.11.1 h1:6DESefxW5oMcRLFRKi53/6exzup/IR6N4EzzS1n6CnQ= | 6 | github.com/astaxie/beego v1.11.1 h1:6DESefxW5oMcRLFRKi53/6exzup/IR6N4EzzS1n6CnQ= |
| 5 | github.com/astaxie/beego v1.11.1/go.mod h1:i69hVzgauOPSw5qeyF4GVZhn7Od0yG5bbCGzmhbWxgQ= | 7 | github.com/astaxie/beego v1.11.1/go.mod h1:i69hVzgauOPSw5qeyF4GVZhn7Od0yG5bbCGzmhbWxgQ= |
| @@ -12,6 +12,10 @@ import ( | @@ -12,6 +12,10 @@ import ( | ||
| 12 | _ "github.com/go-sql-driver/mysql" | 12 | _ "github.com/go-sql-driver/mysql" |
| 13 | ) | 13 | ) |
| 14 | 14 | ||
| 15 | +func init() { | ||
| 16 | + beego.BConfig.WebConfig.Session.SessionOn = true | ||
| 17 | +} | ||
| 18 | + | ||
| 15 | func main() { | 19 | func main() { |
| 16 | common.ResetCommonConfig() | 20 | common.ResetCommonConfig() |
| 17 | log.Debug("加载配置%s", config.MConfig.ConfigName) | 21 | log.Debug("加载配置%s", config.MConfig.ConfigName) |
| @@ -91,7 +91,7 @@ var AllowOption = func(ctx *context.Context) { | @@ -91,7 +91,7 @@ var AllowOption = func(ctx *context.Context) { | ||
| 91 | AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization", | 91 | AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization", |
| 92 | "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息 | 92 | "x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息 |
| 93 | ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息 | 93 | ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息 |
| 94 | - AllowCredentials: false, //不允许共享AuthTuffic证书 | 94 | + AllowCredentials: true, //不允许共享AuthTuffic证书 |
| 95 | AllowAllOrigins: true, //允许的请求来源 | 95 | AllowAllOrigins: true, //允许的请求来源 |
| 96 | }) | 96 | }) |
| 97 | f(ctx) | 97 | f(ctx) |
| @@ -90,7 +90,7 @@ type Template struct { | @@ -90,7 +90,7 @@ type Template struct { | ||
| 90 | Code string `json:"code" valid:"Required; MaxSize(6)"` | 90 | Code string `json:"code" valid:"Required; MaxSize(6)"` |
| 91 | ChanceTypeId int `json:"chanceTypeId" valid:"Required;"` //机会类型编号 | 91 | ChanceTypeId int `json:"chanceTypeId" valid:"Required;"` //机会类型编号 |
| 92 | Name string `json:"name" valid:"Required;"` | 92 | Name string `json:"name" valid:"Required;"` |
| 93 | - Doc string `json:"doc" valid:"Required;"` | 93 | + Doc string `json:"doc"` |
| 94 | Icon string `json:"icon" valid:"Required;"` | 94 | Icon string `json:"icon" valid:"Required;"` |
| 95 | InputList []*InputElement `json:"inputList" valid:"Required;"` | 95 | InputList []*InputElement `json:"inputList" valid:"Required;"` |
| 96 | } | 96 | } |
| @@ -51,3 +51,9 @@ type DepartAndUser struct { | @@ -51,3 +51,9 @@ type DepartAndUser struct { | ||
| 51 | Departments []DepartmentBase `json:"departments"` | 51 | Departments []DepartmentBase `json:"departments"` |
| 52 | Members []DepartmentMember `json:"members"` | 52 | Members []DepartmentMember `json:"members"` |
| 53 | } | 53 | } |
| 54 | + | ||
| 55 | +type UserInfoBase struct { | ||
| 56 | + UserCompanyId int64 `json:"user_company_id"` | ||
| 57 | + Name string `json:"name"` | ||
| 58 | + Phone string `json:"phone"` | ||
| 59 | +} |
| @@ -125,7 +125,7 @@ type ResponseCompanyBase struct { | @@ -125,7 +125,7 @@ type ResponseCompanyBase struct { | ||
| 125 | type CenterCompanyInfo struct { | 125 | type CenterCompanyInfo struct { |
| 126 | CompanyId int64 `json:"company_id"` //总后台的公司id | 126 | CompanyId int64 `json:"company_id"` //总后台的公司id |
| 127 | CompanyName string `json:"company_name"` // | 127 | CompanyName string `json:"company_name"` // |
| 128 | - AdminId int64 `json:"admin_id"` //统一用户中心的用户id | 128 | + // AdminId int64 `json:"admin_id"` //统一用户中心的用户id |
| 129 | AdminAccount string `json:"admin_account"` | 129 | AdminAccount string `json:"admin_account"` |
| 130 | AdminName string `json:"admin_name"` | 130 | AdminName string `json:"admin_name"` |
| 131 | Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】 | 131 | Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】 |
| @@ -46,6 +46,7 @@ func init() { | @@ -46,6 +46,7 @@ func init() { | ||
| 46 | beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), | 46 | beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), |
| 47 | beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), | 47 | beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), |
| 48 | beego.NSRouter("/allow_forbid", &controllers.CompanyController{}, "post:UserAllowForbid"), | 48 | beego.NSRouter("/allow_forbid", &controllers.CompanyController{}, "post:UserAllowForbid"), |
| 49 | + beego.NSRouter("/info", &controllers.CompanyController{}, "post:UserDetail"), | ||
| 49 | ), | 50 | ), |
| 50 | beego.NSNamespace("/auth", | 51 | beego.NSNamespace("/auth", |
| 51 | beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), | 52 | beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), |
| @@ -89,6 +90,8 @@ func init() { | @@ -89,6 +90,8 @@ func init() { | ||
| 89 | beego.NSBefore(middleware.AllowOption), | 90 | beego.NSBefore(middleware.AllowOption), |
| 90 | beego.NSBefore(middleware.LogRequestData), | 91 | beego.NSBefore(middleware.LogRequestData), |
| 91 | beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"), | 92 | beego.NSRouter("/login", &controllers.AuthController{}, "post:Login"), |
| 93 | + beego.NSRouter("/startCaptcha", &controllers.AuthController{}, "post:RegisterGeetest"), | ||
| 94 | + beego.NSRouter("/verifyCaptcha", &controllers.AuthController{}, "post:ValidateGeetest"), | ||
| 92 | ) | 95 | ) |
| 93 | nsUcenter := beego.NewNamespace("/ucenter", | 96 | nsUcenter := beego.NewNamespace("/ucenter", |
| 94 | beego.NSBefore(middleware.LogRequestData), | 97 | beego.NSBefore(middleware.LogRequestData), |
| 1 | package company | 1 | package company |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "fmt" | ||
| 5 | "oppmg/common/log" | 4 | "oppmg/common/log" |
| 6 | "oppmg/models" | 5 | "oppmg/models" |
| 7 | "oppmg/protocol" | 6 | "oppmg/protocol" |
| 7 | + "oppmg/services/ucenter" | ||
| 8 | "time" | 8 | "time" |
| 9 | 9 | ||
| 10 | "github.com/astaxie/beego/orm" | 10 | "github.com/astaxie/beego/orm" |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | -// type CenterCompanyInfo struct { | ||
| 14 | -// CompanyId int64 | ||
| 15 | -// CompanyName string | ||
| 16 | -// AdminId int64 | ||
| 17 | -// AdminAccount string | ||
| 18 | -// AdminName string | ||
| 19 | -// } | ||
| 20 | - | ||
| 21 | -// func GetCenterCompanyInfo(companyid int64) (CenterCompanyInfo, error) { | ||
| 22 | - | ||
| 23 | -// //TODO 调用统一用户中心的数据 | ||
| 24 | -// data := CenterCompanyInfo{ | ||
| 25 | -// CompanyId: 9999 + companyid, | ||
| 26 | -// CompanyName: "调试用公司数据", | ||
| 27 | -// AdminId: 9999 + companyid, | ||
| 28 | -// AdminAccount: "调试用自己修改", | ||
| 29 | -// AdminName: "调试用自己修改", | ||
| 30 | -// } | ||
| 31 | -// return data, nil | ||
| 32 | -// } | ||
| 33 | - | ||
| 34 | //InitCompanyInfo 初始化公司 | 13 | //InitCompanyInfo 初始化公司 |
| 35 | -//@uCompanyid 从统一用户中心获取的公司id companyid, | ||
| 36 | func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error { | 14 | func InitCompanyInfo(centerCompany protocol.CenterCompanyInfo) error { |
| 37 | // var ( | 15 | // var ( |
| 38 | // centerCompany CenterCompanyInfo | 16 | // centerCompany CenterCompanyInfo |
| @@ -159,7 +137,7 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | @@ -159,7 +137,7 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | ||
| 159 | newUser = &models.User{} | 137 | newUser = &models.User{} |
| 160 | ) | 138 | ) |
| 161 | err = o.QueryTable(&models.User{}). | 139 | err = o.QueryTable(&models.User{}). |
| 162 | - Filter("user_center_id", centerCompany.AdminId). | 140 | + Filter("phone", centerCompany.AdminAccount). |
| 163 | Filter("delete_at", 0). | 141 | Filter("delete_at", 0). |
| 164 | One(newUser) | 142 | One(newUser) |
| 165 | if err == nil { | 143 | if err == nil { |
| @@ -177,16 +155,21 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | @@ -177,16 +155,21 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode | ||
| 177 | return nil, err | 155 | return nil, err |
| 178 | } | 156 | } |
| 179 | } else if err == orm.ErrNoRows { | 157 | } else if err == orm.ErrNoRows { |
| 158 | + ucenterUser, err := ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "") | ||
| 159 | + if err != nil { | ||
| 160 | + log.Error("获取统一用户中心数据失败 :%s", err) | ||
| 161 | + } | ||
| 180 | //添加用户 | 162 | //添加用户 |
| 181 | newUser = &models.User{ | 163 | newUser = &models.User{ |
| 182 | Phone: centerCompany.AdminAccount, | 164 | Phone: centerCompany.AdminAccount, |
| 183 | - UserCenterId: centerCompany.AdminId, | ||
| 184 | NickName: centerCompany.AdminName, | 165 | NickName: centerCompany.AdminName, |
| 166 | + Icon: ucenterUser.Data.Avatar, | ||
| 167 | + Accid: ucenterUser.Data.Accid, | ||
| 168 | + UserCenterId: ucenterUser.Data.Id, | ||
| 169 | + CsAccount: ucenterUser.Data.CustomerAccount, | ||
| 185 | } | 170 | } |
| 186 | - id, err := models.AddUser(newUser, o) | ||
| 187 | - fmt.Println("-=====>user_id=", id) | 171 | + _, err = models.AddUser(newUser, o) |
| 188 | if err != nil { | 172 | if err != nil { |
| 189 | - | ||
| 190 | log.Error("添加用户数据失败:%s", err) | 173 | log.Error("添加用户数据失败:%s", err) |
| 191 | return nil, err | 174 | return nil, err |
| 192 | } | 175 | } |
| @@ -614,6 +614,30 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase { | @@ -614,6 +614,30 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase { | ||
| 614 | return data | 614 | return data |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | +func GetUserData(usercompanyid int64) (protocol.UserInfoBase, error) { | ||
| 618 | + var ( | ||
| 619 | + ucompany *models.UserCompany | ||
| 620 | + err error | ||
| 621 | + uinfo protocol.UserInfoBase | ||
| 622 | + ) | ||
| 623 | + ucompany, err = models.GetUserCompanyById(usercompanyid) | ||
| 624 | + if err != nil { | ||
| 625 | + log.Error("获取GetUserCompanyById失败 :%s", err) | ||
| 626 | + return uinfo, err | ||
| 627 | + } | ||
| 628 | + userdata, err := models.GetUserById(ucompany.UserId) | ||
| 629 | + if err != nil { | ||
| 630 | + log.Error("获取GetUserById 失败:%s", err) | ||
| 631 | + return uinfo, err | ||
| 632 | + } | ||
| 633 | + uinfo = protocol.UserInfoBase{ | ||
| 634 | + UserCompanyId: ucompany.Id, | ||
| 635 | + Name: ucompany.NickName, | ||
| 636 | + Phone: userdata.Phone, | ||
| 637 | + } | ||
| 638 | + return uinfo, nil | ||
| 639 | +} | ||
| 640 | + | ||
| 617 | //禁用用户 | 641 | //禁用用户 |
| 618 | func UserForbid(userCompanyids []int64, companyid int64) error { | 642 | func UserForbid(userCompanyids []int64, companyid int64) error { |
| 619 | if len(userCompanyids) == 0 { | 643 | if len(userCompanyids) == 0 { |
| 1 | +package geetest | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "crypto/md5" | ||
| 5 | + "encoding/hex" | ||
| 6 | + "encoding/json" | ||
| 7 | + "errors" | ||
| 8 | + "io/ioutil" | ||
| 9 | + "net/http" | ||
| 10 | + "net/url" | ||
| 11 | + "strings" | ||
| 12 | + "time" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type GeetestLib struct { | ||
| 16 | + CaptchaID string | ||
| 17 | + PrivateKey string | ||
| 18 | + Client *http.Client | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +type FailbackRegisterRespnse struct { | ||
| 22 | + Success int `json:"success"` | ||
| 23 | + GT string `json:"gt"` | ||
| 24 | + Challenge string `json:"challenge"` | ||
| 25 | + NewCaptcha int `json:"new_captcha"` | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +const ( | ||
| 29 | + geetestHost = "http://api.geetest.com" | ||
| 30 | + registerURL = geetestHost + "/register.php" | ||
| 31 | + validateURL = geetestHost + "/validate.php" | ||
| 32 | +) | ||
| 33 | + | ||
| 34 | +func MD5Encode(input string) string { | ||
| 35 | + md5Instant := md5.New() | ||
| 36 | + md5Instant.Write([]byte(input)) | ||
| 37 | + return hex.EncodeToString(md5Instant.Sum(nil)) | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +// 初始化 GeetestLib | ||
| 41 | +func NewGeetestLib(capthcaID string, privateKey string, timeOut time.Duration) (geetest GeetestLib){ | ||
| 42 | + client := &http.Client{Timeout: timeOut} | ||
| 43 | + geetest = GeetestLib{capthcaID, privateKey, client} | ||
| 44 | + return | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +func (g *GeetestLib) getFailBackRegisterResponse(success int, challenge string) []byte { | ||
| 48 | + if challenge == "" { | ||
| 49 | + challenge = hex.EncodeToString(md5.New().Sum(nil)) | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + response := FailbackRegisterRespnse{ | ||
| 53 | + success, | ||
| 54 | + g.CaptchaID, | ||
| 55 | + challenge, | ||
| 56 | + 1, | ||
| 57 | + } | ||
| 58 | + res, _ := json.Marshal(response) | ||
| 59 | + return res | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +func (g *GeetestLib) do(req *http.Request) (body []byte, err error) { | ||
| 63 | + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 64 | + var resp *http.Response | ||
| 65 | + if resp, err = g.Client.Do(req); err != nil { | ||
| 66 | + return | ||
| 67 | + } | ||
| 68 | + defer resp.Body.Close() | ||
| 69 | + if resp.StatusCode >= http.StatusInternalServerError { | ||
| 70 | + err = errors.New("http status code 5xx") | ||
| 71 | + return | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + if body, err = ioutil.ReadAll(resp.Body); err != nil { | ||
| 75 | + return | ||
| 76 | + } | ||
| 77 | + return | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +func (g *GeetestLib) PreProcess(userID string, userIP string) (int8, []byte) { | ||
| 81 | + params := url.Values{} | ||
| 82 | + params.Add("gt", g.CaptchaID) | ||
| 83 | + params.Add("new_captcha", "1") | ||
| 84 | + if userID != "" { | ||
| 85 | + params.Add("user_id", userID) | ||
| 86 | + } | ||
| 87 | + if userIP != "" { | ||
| 88 | + params.Add("ip_adress", userIP) | ||
| 89 | + } | ||
| 90 | + req, _ := http.NewRequest("GET", registerURL+"?"+params.Encode(), nil) | ||
| 91 | + body, err := g.do(req) | ||
| 92 | + if err != nil { | ||
| 93 | + return 0, g.getFailBackRegisterResponse(0, "") | ||
| 94 | + } | ||
| 95 | + challenge := string(body) | ||
| 96 | + if len(challenge) != 32 { | ||
| 97 | + return 0, g.getFailBackRegisterResponse(0, "") | ||
| 98 | + } else { | ||
| 99 | + challenge = MD5Encode(challenge + g.PrivateKey) | ||
| 100 | + return 1, g.getFailBackRegisterResponse(1, challenge) | ||
| 101 | + } | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +func (g *GeetestLib) checkParas(challenge string, validate string, seccode string) bool { | ||
| 105 | + if challenge == "" || validate == "" || seccode == "" { | ||
| 106 | + return false | ||
| 107 | + } | ||
| 108 | + return true | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +func (g *GeetestLib) checkSuccessRes(challenge string, validate string) bool { | ||
| 112 | + return MD5Encode(g.PrivateKey+"geetest"+challenge) == validate | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +func (g *GeetestLib) checkFailbackRes(challenge string, validate string) bool { | ||
| 116 | + return MD5Encode(challenge) == validate | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +func (g *GeetestLib) SuccessValidate(challenge string, validate string, seccode string, userID string, userIP string) bool { | ||
| 120 | + if !g.checkParas(challenge, validate, seccode) { | ||
| 121 | + return false | ||
| 122 | + } | ||
| 123 | + if !g.checkSuccessRes(challenge, validate) { | ||
| 124 | + return false | ||
| 125 | + } | ||
| 126 | + params := url.Values{} | ||
| 127 | + params.Add("seccode", seccode) | ||
| 128 | + params.Add("challenge", challenge) | ||
| 129 | + params.Add("captchaid", g.CaptchaID) | ||
| 130 | + params.Add("sdk", "golang_v1.0.0") | ||
| 131 | + if userID != "" { | ||
| 132 | + params.Add("user_id", userID) | ||
| 133 | + } | ||
| 134 | + if userIP != "" { | ||
| 135 | + params.Add("ip_adress", userIP) | ||
| 136 | + } | ||
| 137 | + req, _ := http.NewRequest("POST", validateURL, strings.NewReader(params.Encode())) | ||
| 138 | + body, err := g.do(req) | ||
| 139 | + if err != nil { | ||
| 140 | + return false | ||
| 141 | + } | ||
| 142 | + res := string(body) | ||
| 143 | + return res == MD5Encode(seccode) | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +func (g *GeetestLib) FailbackValidate(challenge string, validate string, seccode string) bool { | ||
| 147 | + if !g.checkParas(challenge, validate, seccode) { | ||
| 148 | + return false | ||
| 149 | + } | ||
| 150 | + if !g.checkFailbackRes(challenge, validate) { | ||
| 151 | + return false | ||
| 152 | + } | ||
| 153 | + return true | ||
| 154 | +} |
| 1 | # github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 | 1 | # github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 |
| 2 | github.com/360EntSecGroup-Skylar/excelize/v2 | 2 | github.com/360EntSecGroup-Skylar/excelize/v2 |
| 3 | +# github.com/GeeTeam/gt3-golang-sdk v0.0.0-20190704102600-e89c6d964c8f | ||
| 4 | +github.com/GeeTeam/gt3-golang-sdk/geetest | ||
| 3 | # github.com/astaxie/beego v1.11.1 | 5 | # github.com/astaxie/beego v1.11.1 |
| 4 | github.com/astaxie/beego | 6 | github.com/astaxie/beego |
| 5 | github.com/astaxie/beego/config | 7 | github.com/astaxie/beego/config |
-
请 注册 或 登录 后发表评论