|
@@ -3,13 +3,11 @@ package auth |
|
@@ -3,13 +3,11 @@ package auth |
3
|
import (
|
3
|
import (
|
4
|
"crypto/sha1"
|
4
|
"crypto/sha1"
|
5
|
"encoding/hex"
|
5
|
"encoding/hex"
|
6
|
- "encoding/json"
|
|
|
7
|
"fmt"
|
6
|
"fmt"
|
8
|
"io"
|
7
|
"io"
|
9
|
"oppmg/common/log"
|
8
|
"oppmg/common/log"
|
10
|
"oppmg/models"
|
9
|
"oppmg/models"
|
11
|
"oppmg/protocol"
|
10
|
"oppmg/protocol"
|
12
|
- "oppmg/services/ucenter"
|
|
|
13
|
"oppmg/storage/redisdata"
|
11
|
"oppmg/storage/redisdata"
|
14
|
"oppmg/utils"
|
12
|
"oppmg/utils"
|
15
|
"strings"
|
13
|
"strings"
|
|
@@ -201,9 +199,15 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
@@ -201,9 +199,15 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
201
|
log.Debug("no company")
|
199
|
log.Debug("no company")
|
202
|
return logintoken, protocol.NewErrWithMessage("10022")
|
200
|
return logintoken, protocol.NewErrWithMessage("10022")
|
203
|
}
|
201
|
}
|
|
|
202
|
+ //获取上一次登录的公司
|
|
|
203
|
+ uAuth, err := models.GetUserAuthByUser(userdata.Id)
|
|
|
204
|
+ if err == nil {
|
|
|
205
|
+ companyid = uAuth.CurrentCompanyId
|
|
|
206
|
+ } else {
|
204
|
companyid = companys[0].Id
|
207
|
companyid = companys[0].Id
|
|
|
208
|
+ }
|
205
|
// var uclientReturn *ucenter.ResponseLogin
|
209
|
// var uclientReturn *ucenter.ResponseLogin
|
206
|
- // uclientReturn, err = requestUCenterLogin(account, password)
|
210
|
+ // uclientReturn, err = ucenter.RequestUCenterLogin(account, password)
|
207
|
// if err != nil {
|
211
|
// if err != nil {
|
208
|
// return logintoken, protocol.NewErrWithMessage("10021")
|
212
|
// return logintoken, protocol.NewErrWithMessage("10021")
|
209
|
// }
|
213
|
// }
|
|
@@ -223,31 +227,6 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
@@ -223,31 +227,6 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
223
|
return logintoken, err
|
227
|
return logintoken, err
|
224
|
}
|
228
|
}
|
225
|
|
229
|
|
226
|
-func requestUCenterLogin(account, password string) (*ucenter.ResponseLogin, error) {
|
|
|
227
|
- var uclientReturn *ucenter.ResponseLogin
|
|
|
228
|
- param := ucenter.RequesLogin{
|
|
|
229
|
- Type: 1,
|
|
|
230
|
- Phone: account,
|
|
|
231
|
- Password: password,
|
|
|
232
|
- }
|
|
|
233
|
- uclient := ucenter.NewUCenterClient()
|
|
|
234
|
- btBody, err := uclient.Call(param)
|
|
|
235
|
- if err != nil {
|
|
|
236
|
- log.Error("统一用户中心请求失败 err:%s", err)
|
|
|
237
|
- return nil, protocol.NewErrWithMessage("1")
|
|
|
238
|
- }
|
|
|
239
|
- err = json.Unmarshal(btBody, &uclientReturn)
|
|
|
240
|
- if err != nil {
|
|
|
241
|
- log.Error("解析统一用户中心响应失败 err:%s", err)
|
|
|
242
|
- return nil, protocol.NewErrWithMessage("1")
|
|
|
243
|
- }
|
|
|
244
|
- if !(uclientReturn.Code == ucenter.ResponseCode0 &&
|
|
|
245
|
- uclientReturn.Msg == ucenter.ResponseMsgOk) {
|
|
|
246
|
- return nil, protocol.NewErrWithMessage("10021")
|
|
|
247
|
- }
|
|
|
248
|
- return uclientReturn, nil
|
|
|
249
|
-}
|
|
|
250
|
-
|
|
|
251
|
type companybase struct {
|
230
|
type companybase struct {
|
252
|
Id int64 `orm:"column(id)"`
|
231
|
Id int64 `orm:"column(id)"`
|
253
|
Name string `orm:"coumn(name)"`
|
232
|
Name string `orm:"coumn(name)"`
|
|
@@ -288,7 +267,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
@@ -288,7 +267,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
288
|
var (
|
267
|
var (
|
289
|
err error
|
268
|
err error
|
290
|
userinfo *models.User
|
269
|
userinfo *models.User
|
291
|
- companylist []companybase
|
270
|
+
|
292
|
meInfo protocol.ResponseMeInfo
|
271
|
meInfo protocol.ResponseMeInfo
|
293
|
currentCompany *models.Company
|
272
|
currentCompany *models.Company
|
294
|
)
|
273
|
)
|
|
@@ -302,11 +281,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
@@ -302,11 +281,7 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
302
|
log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
281
|
log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
303
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
282
|
return meInfo, protocol.NewErrWithMessage("1", err)
|
304
|
}
|
283
|
}
|
305
|
- companylist, err = getUserCompanyReal(userid)
|
|
|
306
|
- if err != nil {
|
|
|
307
|
- log.Error("getUserCompanyReal(%d) err:%s", userid, err)
|
|
|
308
|
- return meInfo, protocol.NewErrWithMessage("1", err)
|
|
|
309
|
- }
|
284
|
+
|
310
|
meInfo = protocol.ResponseMeInfo{
|
285
|
meInfo = protocol.ResponseMeInfo{
|
311
|
NickName: userinfo.NickName,
|
286
|
NickName: userinfo.NickName,
|
312
|
Icon: userinfo.Icon,
|
287
|
Icon: userinfo.Icon,
|
|
@@ -314,12 +289,42 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
|
@@ -314,12 +289,42 @@ func UserBaseInfo(userid, companyid int64) (protocol.ResponseMeInfo, error) { |
314
|
Companyname: currentCompany.Name,
|
289
|
Companyname: currentCompany.Name,
|
315
|
Logo: currentCompany.Logo,
|
290
|
Logo: currentCompany.Logo,
|
316
|
}
|
291
|
}
|
|
|
292
|
+
|
|
|
293
|
+ return meInfo, nil
|
|
|
294
|
+}
|
|
|
295
|
+
|
|
|
296
|
+func UserHasCompanys(userid int64) ([]protocol.MeCompany, error) {
|
|
|
297
|
+ var (
|
|
|
298
|
+ companylist []companybase
|
|
|
299
|
+ err error
|
|
|
300
|
+ mecompanys []protocol.MeCompany
|
|
|
301
|
+ )
|
|
|
302
|
+ companylist, err = getUserCompanyReal(userid)
|
|
|
303
|
+ if err != nil {
|
|
|
304
|
+ log.Error("getUserCompanyReal(%d) err:%s", userid, err)
|
|
|
305
|
+ return nil, protocol.NewErrWithMessage("1", err)
|
|
|
306
|
+ }
|
317
|
for _, v := range companylist {
|
307
|
for _, v := range companylist {
|
318
|
t := protocol.MeCompany{
|
308
|
t := protocol.MeCompany{
|
319
|
Id: v.Id,
|
309
|
Id: v.Id,
|
320
|
Name: v.Name,
|
310
|
Name: v.Name,
|
321
|
}
|
311
|
}
|
322
|
- meInfo.Companys = append(meInfo.Companys, t)
|
312
|
+ mecompanys = append(mecompanys, t)
|
323
|
}
|
313
|
}
|
324
|
- return meInfo, nil
|
314
|
+ return mecompanys, nil
|
|
|
315
|
+}
|
|
|
316
|
+
|
|
|
317
|
+func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) {
|
|
|
318
|
+ const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code
|
|
|
319
|
+ FROM menu WHERE enabled=1 ORDER BY sort `
|
|
|
320
|
+ var (
|
|
|
321
|
+ list []protocol.PermissionItem
|
|
|
322
|
+ err error
|
|
|
323
|
+ )
|
|
|
324
|
+ err = utils.ExecuteQueryAll(&list, datasql)
|
|
|
325
|
+ if err != nil {
|
|
|
326
|
+ log.Error("EXECUTE SQL err:%s", err)
|
|
|
327
|
+ return nil, protocol.NewErrWithMessage("1")
|
|
|
328
|
+ }
|
|
|
329
|
+ return list, nil
|
325
|
} |
330
|
} |