作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

#app的名称
appname = ability
#运行模式
runmode =${ProRunMode||dev}
runmode =${RUN_MODE||dev}
#是否自动渲染页面
autorender = false
#是否复制请求body
... ...
... ... @@ -2,7 +2,7 @@
config_name = "dev"
#----beego的默认配置 开始---
#端口号
httpport = 8080
httpport = 8080
#开启应用内监控
EnableAdmin = false
AdminPort = 8088
... ... @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn"
# 上传文件保存路径
file_save_path = "/var/www/opp/file"
file_host = "http://mmm-opp-dev.fjmaimaimai.com"
file_host = "http://mmm-oppmg-dev.fjmaimaimai.com"
file_host_path = "/file/opp"
# 审批流程修改 消息发布
message_publish = "audit_change"
... ...
... ... @@ -34,7 +34,7 @@ ucenter_secret = "cykbjnfqgctn"
# 上传文件保存路径
file_save_path = "/var/www/opp/file"
file_host = "http://mmm-opp-dev.fjmaimaimai.com"
file_host = "http://mmm-oppmg-test.fjmaimaimai.com"
file_host_path = "/file/opp"
# 审批流程修改 消息发布
message_publish = "audit_change"
... ...
... ... @@ -37,7 +37,10 @@ func (c *AuthController) RefreshToken() {
return
}
err = serveauth.ResetLoginTokenRedis(logintoken)
msg = protocol.NewReturnResponse(logintoken, err)
data := protocol.ResponseLogin{
Access: logintoken,
}
msg = protocol.NewReturnResponse(data, err)
return
}
... ... @@ -72,13 +75,51 @@ func (c *AuthController) Login() {
if err != nil {
log.Error("token 信息记录redis失败")
}
data := map[string]interface{}{
"access": logintoken,
data := protocol.ResponseLogin{
Access: logintoken,
}
msg = protocol.NewReturnResponse(data, nil)
return
}
// LoginSms 登录
// @router /login [post]
func (c *AuthController) LoginSms() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestLogin
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
// if len(param.Account) == 0 || len(param.Password) == 0 {
// msg = protocol.BadRequestParam("10021")
// return
// }
// logintoken, err := serveauth.LoginAuthByUCenter(param.Account, param.Password)
// if err != nil {
// msg = protocol.NewReturnResponse(nil, err)
// return
// }
// err = serveauth.ResetLoginToken(logintoken)
// if err != nil {
// log.Error("token 信息记录数据库失败")
// }
// err = serveauth.ResetLoginTokenRedis(logintoken)
// if err != nil {
// log.Error("token 信息记录redis失败")
// }
// data := map[string]interface{}{
// "access": logintoken,
// }
// msg = protocol.NewReturnResponse(data, nil)
return
}
//ChangeCompany 切换公司
//@Router /change_company [post]
func (c *AuthController) ChangeCompany() {
... ... @@ -103,11 +144,18 @@ func (c *AuthController) ChangeCompany() {
msg = protocol.NewReturnResponse(nil, err)
return
}
err = serveauth.ResetLoginToken(logintoken)
if err != nil {
log.Error("token 信息记录数据库失败")
}
err = redisdata.SetLoginToken(logintoken, userid, param.CompanyId)
if err != nil {
log.Error("redisdata.SetLoginToken err:%s", err)
}
msg = protocol.NewReturnResponse(logintoken, err)
data := protocol.ResponseLogin{
Access: logintoken,
}
msg = protocol.NewReturnResponse(data, err)
return
}
... ... @@ -142,13 +190,14 @@ func (c *AuthController) Me() {
}
const (
captchaID = "48a6ebac4ebc6642d68c217fca33eb4d"
privateKey = "4f1c085290bec5afdc54df73535fc361"
captchaID = "33a2abf9c5df0d6bc3b89fb39280114b"
privateKey = "13320fd2b10199e9a2440a4fbb4d46f7"
)
func (c *AuthController) RegisterGeetest() {
geetest := geetest.NewGeetestLib(captchaID, privateKey, 2*time.Second)
status, responseBt := geetest.PreProcess("", "")
userip := c.Ctx.Input.IP()
status, responseBt := geetest.PreProcess("", userip)
c.SetSession("geetest_status", status)
c.Ctx.Output.Body(responseBt)
return
... ...
... ... @@ -20,14 +20,14 @@ type BaseController struct {
//Prepare 实现beego.ControllerInterface 的接口
func (this *BaseController) Prepare() {
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
// if this.Ctx.Input.Method() == "OPTIONS" {
// this.Ctx.ResponseWriter.WriteHeader(204)
// this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
// //this.Ctx.WriteString("")
// return
// }
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*")
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "*")
if this.Ctx.Input.Method() == "OPTIONS" {
this.Ctx.ResponseWriter.WriteHeader(204)
this.Ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
this.Ctx.WriteString("")
return
}
p := this.Ctx.Input.GetData("RouterPattern")
fmt.Println("====>r:", p)
}
... ...
... ... @@ -420,6 +420,7 @@ func (c *CompanyController) InitCompany() {
return
}
// GetCompanyForUCenter 总后台调用
//@router /ucenter/company/info [post]
func (c *CompanyController) GetCompanyForUCenter() {
var msg *protocol.ResponseMessage
... ... @@ -427,6 +428,28 @@ func (c *CompanyController) GetCompanyForUCenter() {
c.ResposeJson(msg)
}()
type Paremeter struct {
Companyid int64 `json:"company_id"`
CompanyName string `json:"company_name"`
}
var param Paremeter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
err := servecompany.CompanyEditFromUcenter(param.Companyid, param.CompanyName)
msg = protocol.NewReturnResponse(nil, err)
return
}
//EditCompanyForUCenter
//@router /ucenter/company/edit [post]
func (c *CompanyController) EditCompanyForUCenter() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Paremeter struct {
Companyid int64 `json:"company_id"`
}
var param Paremeter
... ...
... ... @@ -59,6 +59,7 @@ func saveFile(fileData *multipart.FileHeader, fileType string) (hostpath string,
subfix := path.Ext(fileData.Filename)
mfileName := fmt.Sprint(utils.GenerateIDBySonyflake())
mfileName = fmt.Sprintf("%d_%s%s", time.Now().Unix(), mfileName, subfix)
log.Debug("文件保存地址%s", filepath.Join(savepath, mfileName))
dst, err := os.Create(filepath.Join(savepath, mfileName))
defer dst.Close()
if err != nil {
... ...
... ... @@ -51,7 +51,7 @@ var AuthToken = func(ctx *context.Context) {
}
mtoken, err = serveauth.ValidJWTToken(accesstoken)
if err == nil {
storetoken, err = redisdata.GetLoginToken(mtoken.UID)
storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID)
if err != nil {
log.Error("redisdata.GetLoginToken err:%s", err)
msg = protocol.NewMessage("10024")
... ... @@ -91,7 +91,7 @@ var AllowOption = func(ctx *context.Context) {
AllowHeaders: []string{"Origin", "Accept", "Content-Type", "Authorization",
"x-mmm-cid", "x-mmm-uid", "x-mmm-accesstoken", "x-mmm-refreshtoken", "x-requested-with"}, //允许的头部信息
ExposeHeaders: []string{"Content-Length"}, //允许暴露的头信息
AllowCredentials: true, //不允许共享AuthTuffic证书
AllowCredentials: false, //不允许共享AuthTuffic证书
AllowAllOrigins: true, //允许的请求来源
})
f(ctx)
... ...
... ... @@ -28,7 +28,7 @@ type RequestLogin struct {
//ResponseLogin 登录响应
type ResponseLogin struct {
LoginAuthToken
Access LoginAuthToken `json:"access"`
}
type LoginAuthToken struct {
... ... @@ -62,4 +62,5 @@ type ResponseMeInfo struct {
type MeCompany struct {
Id int64 `json:"id"`
Name string `json:"name"`
Logo string `json:"logo"`
}
... ...
... ... @@ -2,8 +2,8 @@ package protocol
//RequestPageInfo 分页获取数据
type RequestPageInfo struct {
PageIndex int `json:"page_index"`
PageSize int `json:"page_size"`
PageIndex int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
//ResponsePageInfo 分页信息
... ...
... ... @@ -112,6 +112,7 @@ type UserListItem struct {
Positions string `json:"positions" orm:"-"`
Roles string `json:"roles" orm:"-"`
Departments string `json:"departments" orm:"-"`
Phone string `json:"phone" orm:"column(phone)"`
Enable int8 `json:"enable" orm:"column(enable)"`
}
... ... @@ -123,9 +124,8 @@ type ResponseCompanyBase struct {
//CenterCompanyInfo 统一用户中心调用的公司数据
type CenterCompanyInfo struct {
CompanyId int64 `json:"company_id"` //总后台的公司id
CompanyName string `json:"company_name"` //
// AdminId int64 `json:"admin_id"` //统一用户中心的用户id
CompanyId int64 `json:"company_id"` //总后台的公司id
CompanyName string `json:"company_name"` //
AdminAccount string `json:"admin_account"`
AdminName string `json:"admin_name"`
Status int8 `json:"status"` //公司的状态 【1:启用】【2:禁用】
... ...
package protocol
var NullData = struct{}{}
var (
NullData = struct{}{}
NullSlice = []interface{}{}
)
//CustomErrParse 解析自定义错误结构体
type CustomErrParse interface {
... ... @@ -94,9 +97,9 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) {
if data == nil {
data = NullData
}
if eRR == nil {
msg = NewMessage("0")
msg.Data = data
return msg
}
... ...
... ... @@ -97,6 +97,7 @@ func init() {
beego.NSBefore(middleware.LogRequestData),
beego.NSRouter("/company", &controllers.CompanyController{}, "post:InitCompany"),
beego.NSRouter("/company/info", &controllers.CompanyController{}, "post:GetCompanyForUCenter"),
beego.NSRouter("/company/edit", &controllers.CompanyController{}, "post:EditCompanyForUCenter"),
)
beego.AddNamespace(nsV1)
... ...
... ... @@ -158,7 +158,7 @@ func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) {
log.Debug("token失效 err:%s", err)
return logintoken, protocol.NewErrWithMessage("10024")
}
storetoken, err = redisdata.GetLoginToken(mtoken.UID)
storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID)
if err != nil {
log.Error("redis err:%s", err)
return logintoken, protocol.NewErrWithMessage("10024")
... ... @@ -308,6 +308,7 @@ func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) {
t := protocol.MeCompany{
Id: v.Id,
Name: v.Name,
Logo: v.Logo,
}
mecompanys = append(mecompanys, t)
}
... ...
... ... @@ -155,9 +155,10 @@ func initAdminUser(centerCompany protocol.CenterCompanyInfo, o orm.Ormer) (*mode
return nil, err
}
} else if err == orm.ErrNoRows {
ucenterUser, err := ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "")
ucenterUser, err := ucenter.RequestUCenterAddUser(centerCompany.AdminAccount, centerCompany.AdminName, "http://这是默认图.jpeg")
if err != nil {
log.Error("获取统一用户中心数据失败 :%s", err)
return nil, err
}
//添加用户
newUser = &models.User{
... ... @@ -403,6 +404,23 @@ func CompanyInfoEdit(companyid int64, logo string) error {
return nil
}
//
func CompanyEditFromUcenter(companyid int64, companyname string) error {
companyinfo, err := models.GetCompanyByUCenter(companyid)
if err != nil {
log.Error("获取公司数据失败")
return protocol.NewErrWithMessage("1")
}
companyinfo.Name = companyname
err = models.UpdateCompanyById(companyinfo, []string{"Name"})
if err != nil {
log.Info("更新公司数据失败:%s", err)
return protocol.NewErrWithMessage("1")
}
return nil
}
func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) {
var (
err error
... ...
... ... @@ -377,25 +377,26 @@ func GetDepartmentUser(companyid int64, departmentid int64) ([]protocol.DepartUs
department *models.Department
err error
)
var (
returnData []protocol.DepartUserBase
)
department, err = models.GetDepartmentById(departmentid)
if err != nil {
log.Error("获取部门失败:%s", err)
return nil, nil
return returnData, nil
}
if department.CompanyId != companyid {
log.Error("deparment.CompanyId err")
return nil, protocol.NewErrWithMessage("1")
return returnData, protocol.NewErrWithMessage("1")
}
const dataSql string = `SELECT b.nick_name,a.user_company_id FROM user_department AS a
JOIN user_company AS b ON a.user_company_id = b.id
WHERE a.department_id=? AND b.delete_at=0 AND a.enable_status = 1 `
var (
returnData []protocol.DepartUserBase
)
err = utils.ExecuteQueryAll(&returnData, dataSql, department.Id)
if err != nil {
log.Error("EXECUTE SQL err:%s", err)
return nil, protocol.NewErrWithMessage("1")
return returnData, protocol.NewErrWithMessage("1")
}
return returnData, nil
}
... ...
... ... @@ -493,7 +493,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
return protocol.NewErrWithMessage("1")
}
for _, v := range updateIds {
e := redisdata.DeleteLoginToken(v.UserId)
e := redisdata.DeleteLoginToken(v.UserId, companyid)
if e != nil {
log.Error(e.Error())
}
... ... @@ -517,7 +517,7 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
)
cond = append(cond, param.Companyid)
if len(param.NickName) > 0 {
whereString += ` AND b.nick_name LIKE ? `
whereString += ` AND a.nick_name LIKE ? `
likeCond := "%" + param.NickName + "%"
cond = append(cond, likeCond)
}
... ... @@ -538,9 +538,9 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
}
for k, v := range result {
var (
pname []string
dname []string
rname []string
pname = make([]string, 0)
dname = make([]string, 0)
rname = make([]string, 0)
)
positions := GetUserPosition(v.UserCompanydId)
for i := range positions {
... ... @@ -570,7 +570,7 @@ func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase {
WHERE a.enable_status =1 AND a.user_company_id =? `
var (
err error
data []protocol.DepartmentBase
data = make([]protocol.DepartmentBase, 0)
)
err = utils.ExecuteQueryAll(&data, datasql, usercompanyid)
if err != nil {
... ... @@ -676,7 +676,7 @@ func UserForbid(userCompanyids []int64, companyid int64) error {
}
log.Info("更新记录数:%d", num)
for _, v := range updateIds {
e := redisdata.DeleteLoginToken(v.UserId)
e := redisdata.DeleteLoginToken(v.UserId, companyid)
if e != nil {
log.Error(e.Error())
}
... ...
... ... @@ -43,6 +43,7 @@ func (client UCenterClient) buildHeader() http.Header {
h.Set("nonce", "")
h.Set("curTime", nowTime)
h.Set("checkSum", checksum)
h.Set("Accept", "application/json")
return h
}
... ... @@ -64,7 +65,7 @@ func (client UCenterClient) httpDo(path string, mathod string, posts []byte) ([]
}
req.Header = client.buildHeader()
resp, err := httpclient.Do(req)
log.Info("====>Send To URL:%s", reqURL)
log.Info("====>Send To UCenter:%s", string(posts))
// log.Info("====>Send Header:%v", req.Header)
if err != nil {
... ...
package redisdata
import "fmt"
const (
KEY_PREFIX string = "oppmg_" //统一前缀
KEY_USER_TOKEN string = "token" //登录token存储
... ... @@ -10,3 +12,8 @@ type RedisLoginToken struct {
RefreshToken string `json:"refresh_token"`
CurrentCompany int64 `json:"current_company"`
}
func GetKeyLoginToken(userid int64, companyid int64) string {
key := fmt.Sprintf("%s%s:%d_%d", KEY_PREFIX, KEY_USER_TOKEN, userid, companyid)
return key
}
... ...
... ... @@ -2,7 +2,6 @@ package redisdata
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/common/redis"
"oppmg/protocol"
... ... @@ -26,12 +25,12 @@ func SetLoginToken(param protocol.LoginAuthToken, userid int64, companyid int64)
}
value, _ = json.Marshal(data)
exp = param.RefreshExpires - nowTime
key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
key = GetKeyLoginToken(userid, companyid)
err = client.Set(key, string(value), time.Duration(exp)*time.Second).Err()
return err
}
func GetLoginToken(userid int64) (RedisLoginToken, error) {
func GetLoginToken(userid int64, companyid int64) (RedisLoginToken, error) {
client := redis.GetRedis()
var (
key string
... ... @@ -39,7 +38,7 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) {
err error
result RedisLoginToken
)
key = fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
key = GetKeyLoginToken(userid, companyid)
value, err = client.Get(key).Result()
if err != nil {
return result, err
... ... @@ -53,9 +52,9 @@ func GetLoginToken(userid int64) (RedisLoginToken, error) {
return result, nil
}
func ExistLoginToken(userid int64) bool {
func ExistLoginToken(userid int64, companyid int64) bool {
client := redis.GetRedis()
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
key := GetKeyLoginToken(userid, companyid)
value := client.Exists(key).Val()
if value > 0 {
return true
... ... @@ -63,17 +62,17 @@ func ExistLoginToken(userid int64) bool {
return false
}
func DeleteLoginToken(userid int64) error {
func DeleteLoginToken(userid int64, companyid int64) error {
client := redis.GetRedis()
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
key := GetKeyLoginToken(userid, companyid)
err := client.Del(key).Err()
return err
}
// 刷新token 的有效期
func RefreshLoginTokenExpires(userid int64) error {
func RefreshLoginTokenExpires(userid int64, companyid int64) error {
client := redis.GetRedis()
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
key := GetKeyLoginToken(userid, companyid)
result, err := client.Exists(key).Result()
if err != nil {
return err
... ...