master
huanghai 5 years ago
parent f60ce8f40c
commit bb62c26c1c

@ -289,6 +289,8 @@ func authorizePost(context *gin.Context) {
var identityId string
var personId string
var success bool
var message string
var remainCount int
//1、验证码
captchaId := context.PostForm("captchaId")
value := context.PostForm("value")
@ -319,12 +321,25 @@ func authorizePost(context *gin.Context) {
}
//调用service层的用户名和密码校验办法判断是不是允许登录
ip := context.ClientIP()
success, identityId, personId, _ = ServiceLoginPerson.Login(username, string(decryptPwd), ip)
success, identityId, personId, _, remainCount = ServiceLoginPerson.Login(username, string(decryptPwd), ip)
if !success {
context.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,
Msg: "用户名密码不正确或已禁用!",
})
//三次以上不提示
if remainCount >= 3 {
context.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,
Msg: "用户名密码不正确或已禁用!",
})
} else if remainCount > 0 {
context.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,
Msg: "用户名密码不正确或已禁用!您还可以尝试" + CommonUtil.ConvertIntToString(remainCount) + "次超出次数限制后账号将被禁用2小时",
})
} else {
context.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,
Msg: "账号已处于禁用状态,请稍后再试!",
})
}
return
}
} else {

@ -1,6 +1,7 @@
package DaoSysLoginPerson
import (
"dsSso/Const"
"dsSso/Const/DefaultConst"
"dsSso/Const/ErrorConst"
"dsSso/Model"
@ -8,6 +9,7 @@ import (
"dsSso/Utils/DbUtil"
"dsSso/Utils/LdapUtil"
"dsSso/Utils/LogUtil"
"dsSso/Utils/RedisUtil"
"dsSso/models"
"fmt"
"time"
@ -26,7 +28,26 @@ func init() {
2020-02-05
*/
func Login(username string, password string, ip string) (bool, string, string, string) {
func Login(username string, password string, ip string) (bool, string, string, string, int) {
//查看redis中此人员的登录错误次数记录如果已超出了规定次数5则直接拒绝登录。
key := "login_remain_count_" + username
c, err := RedisUtil.EXISTS(key)
if err != nil {
return false, "", "", "", -1
}
var remainCount int
//如果存在
if c > 0 {
remainCountStr, err := RedisUtil.GET(key)
if err != nil {
return false, "", "", "", -1
}
remainCount = CommonUtil.ConvertStringToInt(remainCountStr)
if remainCount == 0 {
return false, "", "", "", 0
}
}
//身份号
var identityId = DefaultConst.IdentityId
//人员号
@ -41,7 +62,7 @@ func Login(username string, password string, ip string) (bool, string, string, s
}
//如果用户名不存在
if len(list) == 0 {
return false, identityId, personId, personName
return false, identityId, personId, personName, Const.Int32Max
}
record := list[0]
@ -55,23 +76,25 @@ func Login(username string, password string, ip string) (bool, string, string, s
databasePassword := record["pwd"].(string)
//万能密码登录
if password=="DsideaL4r5t6y7u!@#"{
if password == "DsideaL4r5t6y7u!@#" {
//记录日志
WriteLoginLog(identityId, personId, ip, 2, username) //2为万能密码登录
//返回结果
return true, identityId, personId, personName
}else{
return true, identityId, personId, personName, Const.Int32Max
} else {
//修改密码的加密算法基于ldap,黄海于2020-04-27
ldapPassword := LdapUtil.GetLdapPassword(password)
if ldapPassword == databasePassword {
//记录日志
WriteLoginLog(identityId, personId, ip, 1, username)
//返回结果
return true, identityId, personId, personName
return true, identityId, personId, personName, Const.Int32Max
} else {
//如果登录失败则incr,并设置过期时间2小时
RedisUtil.SET(key, CommonUtil.ConvertIntToString(remainCount-1), 2*time.Hour)
//记录日志
WriteLoginLog(identityId, personId, ip, -1, username)
return false, identityId, personId, personName
return false, identityId, personId, personName, Const.Int32Max
}
}
}

@ -12,7 +12,7 @@ import (
2020-02-05
*/
func Login(username string, password string, ip string) (bool, string, string, string) {
func Login(username string, password string, ip string) (bool, string, string, string, int) {
//异常处理
defer func() {
if err := recover(); err != nil {
@ -25,27 +25,28 @@ func Login(username string, password string, ip string) (bool, string, string, s
if CommonUtil.IsEmail(username) {
personId, err = DaoSysLoginPerson.GetPersonIdByEmail(username)
if err != nil || len(personId) == 0 {
return false, "", "", ""
return false, "", "", "", -1
}
} else if CommonUtil.IsIdCard(username) {
personId, err = DaoSysLoginPerson.GetPersonIdByIdCard(username)
if err != nil || len(personId) == 0 {
return false, "", "", ""
return false, "", "", "", -1
}
} else if MobileUtil.VerifyMobileFormat(username) {
personId, err = DaoSysLoginPerson.GetPersonIdByTel(username)
if err != nil || len(personId) == 0 {
return false, "", "", ""
return false, "", "", "", -1
}
}
if len(personId) > 0 {
//根据person_id换取统一的登录名
username, err = DaoSysLoginPerson.GetLoginNameByPersonId(personId)
if err != nil || len(username) == 0 {
return false, "", "", ""
return false, "", "", "", -1
}
}
//调用dao层的方法,组合成service方法层
result, identityId, personId, personName := DaoSysLoginPerson.Login(username, password, ip)
return result, identityId, personId, personName
result, identityId, personId, personName, remainCount := DaoSysLoginPerson.Login(username, password, ip)
return result, identityId, personId, personName, remainCount
}

@ -257,3 +257,12 @@ func IsIdCard(idCard string) bool {
IdCardNo := []byte(idCard)
return IdCardUtil.IsValidIdCardNo(&IdCardNo)
}
/**
2020-05-30
*/
func ConvertIntToString(i int) string {
return strconv.Itoa(i)
}

Loading…
Cancel
Save