|
|
|
|
package custom
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/api/admin/systemuser"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/staff"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/commonus"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|
|
|
|
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
|
|
|
|
"github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//自定义登录
|
|
|
|
|
func (cu *CustomHandle) CustomLogin(c *gin.Context) {
|
|
|
|
|
var l systemReq.Login
|
|
|
|
|
_ = c.ShouldBindJSON(&l)
|
|
|
|
|
if err := utils.Verify(l, utils.LoginVerify); err != nil {
|
|
|
|
|
response.FailWithMessage(err.Error(), c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
|
|
|
// store
|
|
|
|
|
// if store.Verify(l.CaptchaId, l.Captcha, true) {
|
|
|
|
|
userErr, user := staff.GetUserWork(l.Username, l.Password)
|
|
|
|
|
if userErr != true {
|
|
|
|
|
// // global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Any("err", err))
|
|
|
|
|
response.Result(101, userErr, "登陆失败! 用户名不存在或者密码错误!!", c)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
if user.State == 2 {
|
|
|
|
|
response.Result(102, userErr, "登陆失败! 该账号已经被禁用!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if user.State == 3 {
|
|
|
|
|
response.Result(102, userErr, "登陆失败! 该账号不存在!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if user.HireSet != 1 {
|
|
|
|
|
response.Result(102, userErr, "登陆失败! 该员工已经离职!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var md5JiaMi commonus.Md5Encryption
|
|
|
|
|
md5JiaMi.Md5EncryptionInit(userAgent)
|
|
|
|
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
sha1Str := user.KeyStr + user.Number + user.Password + md5Token
|
|
|
|
|
sha1Token := commonus.Sha1Encryption(sha1Str)
|
|
|
|
|
|
|
|
|
|
saveData := commonus.MapOut()
|
|
|
|
|
saveData["key"] = user.KeyStr
|
|
|
|
|
saveData["token"] = sha1Token
|
|
|
|
|
saveData["userinfo"] = user
|
|
|
|
|
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
|
|
|
writeRedisData := map[string]interface{}{
|
|
|
|
|
"userkey": user.KeyStr,
|
|
|
|
|
"usernumber": user.Number,
|
|
|
|
|
"userpwd": user.Password,
|
|
|
|
|
"usertoken": sha1Token,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// global.GVA_INDEX_USERKEY = user.Key
|
|
|
|
|
|
|
|
|
|
redisClient.HashMsetAdd("system:Identification_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+user.KeyStr, writeRedisData)
|
|
|
|
|
|
|
|
|
|
userInfo := commonus.MapOut()
|
|
|
|
|
userInfo["id"] = user.Id
|
|
|
|
|
userInfo["number"] = user.Number
|
|
|
|
|
userInfo["departmentid"] = user.DepartmentId
|
|
|
|
|
userInfo["workshopid"] = user.WorkshopId
|
|
|
|
|
userInfo["postid"] = user.PostId
|
|
|
|
|
userInfo["key"] = user.Key
|
|
|
|
|
userInfo["group"] = user.Group
|
|
|
|
|
userInfo["tema"] = user.Tema
|
|
|
|
|
userInfo["workwechatid"] = user.WorkWechatId
|
|
|
|
|
userInfo["wechatid"] = user.WechatId
|
|
|
|
|
userInfo["name"] = user.Name
|
|
|
|
|
userInfo["nickname"] = user.NickName
|
|
|
|
|
|
|
|
|
|
redisUserClient := redishandel.RunRedis()
|
|
|
|
|
redisUserClient.SetRedisTime(0)
|
|
|
|
|
redisUserClient.HashMsetAdd("system:userContent_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+user.KeyStr, userInfo)
|
|
|
|
|
// // b.tokenNext(c, *user)
|
|
|
|
|
response.Result(0, saveData, "登录成功!", c)
|
|
|
|
|
}
|
|
|
|
|
// } else {
|
|
|
|
|
// response.FailWithMessage("验证码错误", c)
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//自定义登录
|
|
|
|
|
func (cu *CustomHandle) SystemLogin(c *gin.Context) {
|
|
|
|
|
var l systemReq.Login
|
|
|
|
|
_ = c.ShouldBindJSON(&l)
|
|
|
|
|
if err := utils.Verify(l, utils.LoginVerify); err != nil {
|
|
|
|
|
response.FailWithMessage(err.Error(), c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
|
|
|
// store
|
|
|
|
|
// if store.Verify(l.CaptchaId, l.Captcha, true) {
|
|
|
|
|
userErr, user := systemuser.GetSysAdminLoginInfo(l.Username, l.Password)
|
|
|
|
|
if userErr != true {
|
|
|
|
|
// // global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Any("err", err))
|
|
|
|
|
response.Result(101, userErr, "登陆失败! 用户名不存在或者密码错误!!", c)
|
|
|
|
|
return
|
|
|
|
|
} else {
|
|
|
|
|
if user.State == 2 {
|
|
|
|
|
response.Result(102, userErr, "登陆失败! 该账号已经被禁用!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if user.State == 3 {
|
|
|
|
|
response.Result(102, userErr, "登陆失败! 该账号不存在!", c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var md5JiaMi commonus.Md5Encryption
|
|
|
|
|
md5JiaMi.Md5EncryptionInit(userAgent)
|
|
|
|
|
md5Token := md5JiaMi.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
sha1Str := user.KeyStr + user.Name + user.PassWord + md5Token
|
|
|
|
|
sha1Token := commonus.Sha1Encryption(sha1Str)
|
|
|
|
|
|
|
|
|
|
saveData := commonus.MapOut()
|
|
|
|
|
saveData["key"] = user.KeyStr
|
|
|
|
|
saveData["token"] = sha1Token
|
|
|
|
|
saveData["userinfo"] = user
|
|
|
|
|
|
|
|
|
|
redisClient := redishandel.RunRedis()
|
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
|
|
|
writeRedisData := map[string]interface{}{
|
|
|
|
|
"userkey": user.KeyStr,
|
|
|
|
|
"usernumber": user.Name,
|
|
|
|
|
"userpwd": user.PassWord,
|
|
|
|
|
"usertoken": sha1Token,
|
|
|
|
|
"jurisdiction": user.Jurisdiction,
|
|
|
|
|
"menuOper": user.MenuOper,
|
|
|
|
|
"wand": user.Wand,
|
|
|
|
|
}
|
|
|
|
|
redisClient.HashMsetAdd("system:SystemIdentification_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+user.KeyStr, writeRedisData)
|
|
|
|
|
|
|
|
|
|
adminRedisData := map[string]interface{}{
|
|
|
|
|
"userkey": user.KeyStr,
|
|
|
|
|
"usernumber": user.Name,
|
|
|
|
|
"userpwd": user.PassWord,
|
|
|
|
|
"usertoken": sha1Token,
|
|
|
|
|
"jurisdiction": user.Jurisdiction,
|
|
|
|
|
"menuOper": user.MenuOper,
|
|
|
|
|
"wand": user.Wand,
|
|
|
|
|
"name": user.NameAttr,
|
|
|
|
|
"groupname": user.GroupName,
|
|
|
|
|
"group": user.Group,
|
|
|
|
|
"attribute": user.Attribute,
|
|
|
|
|
"branchfactoryname": user.BranchFactoryName,
|
|
|
|
|
"role": user.Role,
|
|
|
|
|
"roleName": user.RoleName,
|
|
|
|
|
}
|
|
|
|
|
redisAdminClient := redishandel.RunRedis()
|
|
|
|
|
redisAdminClient.SetRedisTime(0)
|
|
|
|
|
redisAdminClient.HashMsetAdd("system:SystemAdminInfo_"+global.GVA_CONFIG.RedisPrefix.Alias+"_"+user.KeyStr, adminRedisData)
|
|
|
|
|
|
|
|
|
|
global.GVA_ADMIN_USERKEY = user.Key
|
|
|
|
|
// // b.tokenNext(c, *user)
|
|
|
|
|
var surisdictionStr []string
|
|
|
|
|
var surisdictionInt []int64
|
|
|
|
|
jsonErr := json.Unmarshal([]byte(user.Jurisdiction), &surisdictionStr)
|
|
|
|
|
if jsonErr == nil {
|
|
|
|
|
for _, jurVal := range surisdictionStr {
|
|
|
|
|
jurValInt, jurValErr := strconv.ParseInt(jurVal, 10, 64)
|
|
|
|
|
if jurValErr == nil {
|
|
|
|
|
surisdictionInt = append(surisdictionInt, jurValInt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
global.Gva_Authority_Authentication = surisdictionInt
|
|
|
|
|
var menuOperStr []string
|
|
|
|
|
var menuOperInts []int64
|
|
|
|
|
jsonErrSun := json.Unmarshal([]byte(user.MenuOper), &menuOperStr)
|
|
|
|
|
if jsonErrSun == nil {
|
|
|
|
|
for _, menuOperVal := range menuOperStr {
|
|
|
|
|
menuOperInt, menuOperErr := strconv.ParseInt(menuOperVal, 10, 64)
|
|
|
|
|
if menuOperErr == nil {
|
|
|
|
|
menuOperInts = append(menuOperInts, menuOperInt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
global.Gva_Authority_Authentication_Subsidiary = menuOperInts
|
|
|
|
|
saveData["Jurisdiction"] = global.Gva_Authority_Authentication
|
|
|
|
|
saveData["MenuOper"] = global.Gva_Authority_Authentication_Subsidiary
|
|
|
|
|
|
|
|
|
|
// saveData["jsonErr"] = jsonErr
|
|
|
|
|
// saveData["jsonErrSun"] = jsonErrSun
|
|
|
|
|
|
|
|
|
|
response.Result(0, saveData, "登录成功!", c)
|
|
|
|
|
}
|
|
|
|
|
// } else {
|
|
|
|
|
// response.FailWithMessage("验证码错误", c)
|
|
|
|
|
// }
|
|
|
|
|
}
|