...
|
...
|
@@ -3,13 +3,11 @@ package auth |
|
|
import (
|
|
|
"crypto/sha1"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/services/ucenter"
|
|
|
"oppmg/storage/redisdata"
|
|
|
"oppmg/utils"
|
|
|
"strings"
|
...
|
...
|
@@ -201,9 +199,15 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
log.Debug("no company")
|
|
|
return logintoken, protocol.NewErrWithMessage("10022")
|
|
|
}
|
|
|
//获取上一次登录的公司
|
|
|
uAuth, err := models.GetUserAuthByUser(userdata.Id)
|
|
|
if err == nil {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
} else {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
// var uclientReturn *ucenter.ResponseLogin
|
|
|
// uclientReturn, err = requestUCenterLogin(account, password)
|
|
|
// uclientReturn, err = ucenter.RequestUCenterLogin(account, password)
|
|
|
// if err != nil {
|
|
|
// return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
// }
|
...
|
...
|
@@ -223,31 +227,6 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
return logintoken, err
|
|
|
}
|
|
|
|
|
|
func requestUCenterLogin(account, password string) (*ucenter.ResponseLogin, error) {
|
|
|
var uclientReturn *ucenter.ResponseLogin
|
|
|
param := ucenter.RequesLogin{
|
|
|
Type: 1,
|
|
|
Phone: account,
|
|
|
Password: password,
|
|
|
}
|
|
|
uclient := ucenter.NewUCenterClient()
|
|
|
btBody, err := uclient.Call(param)
|
|
|
if err != nil {
|
|
|
log.Error("统一用户中心请求失败 err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
err = json.Unmarshal(btBody, &uclientReturn)
|
|
|
if err != nil {
|
|
|
log.Error("解析统一用户中心响应失败 err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if !(uclientReturn.Code == ucenter.ResponseCode0 &&
|
|
|
uclientReturn.Msg == ucenter.ResponseMsgOk) {
|
|
|
return nil, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
return uclientReturn, nil
|
|
|
}
|
|
|
|
|
|
type companybase struct {
|
|
|
Id int64 `orm:"column(id)"`
|
|
|
Name string `orm:"coumn(name)"`
|
...
|
...
|
@@ -288,7 +267,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
|
var (
|
|
|
err error
|
|
|
userinfo *models.User
|
|
|
companylist []companybase
|
|
|
|
|
|
meInfo protocol.ResponseMeInfo
|
|
|
currentCompany *models.Company
|
|
|
)
|
...
|
...
|
@@ -302,11 +281,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
|
log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
|
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
companylist, err = getUserCompanyReal(userid)
|
|
|
if err != nil {
|
|
|
log.Error("getUserCompanyReal(%d) err:%s", userid, err)
|
|
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
|
|
|
meInfo = protocol.ResponseMeInfo{
|
|
|
NickName: userinfo.NickName,
|
|
|
Icon: userinfo.Icon,
|
...
|
...
|
@@ -314,12 +289,42 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
|
Companyname: currentCompany.Name,
|
|
|
Logo: currentCompany.Logo,
|
|
|
}
|
|
|
|
|
|
return meInfo, nil
|
|
|
}
|
|
|
|
|
|
func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) {
|
|
|
var (
|
|
|
companylist []companybase
|
|
|
err error
|
|
|
mecompanys []protocol.MeCompany
|
|
|
)
|
|
|
companylist, err = getUserCompanyReal(userid)
|
|
|
if err != nil {
|
|
|
log.Error("getUserCompanyReal(%d) err:%s", userid, err)
|
|
|
return nil, protocol.NewErrWithMessage("1", err)
|
|
|
}
|
|
|
for _, v := range companylist {
|
|
|
t := protocol.MeCompany{
|
|
|
Id: v.Id,
|
|
|
Name: v.Name,
|
|
|
}
|
|
|
meInfo.Companys = append(meInfo.Companys, t)
|
|
|
mecompanys = append(mecompanys, t)
|
|
|
}
|
|
|
return meInfo, nil
|
|
|
return mecompanys, nil
|
|
|
}
|
|
|
|
|
|
func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) {
|
|
|
const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code
|
|
|
FROM menu WHERE enabled=1 ORDER BY sort `
|
|
|
var (
|
|
|
list []protocol.PermissionItem
|
|
|
err error
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&list, datasql)
|
|
|
if err != nil {
|
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return list, nil
|
|
|
} |
...
|
...
|
|