master
huanghai 5 years ago
parent 43544e9d3d
commit 1eb665ac8f

@ -323,7 +323,8 @@ func authorizePost(context *gin.Context) {
return
}
//调用service层的用户名和密码校验办法判断是不是允许登录
success, identityId, personId, _ = ServiceLoginPerson.Login(username, string(decryptPwd))
ip:=context.ClientIP()
success, identityId, personId, _ = ServiceLoginPerson.Login(username, string(decryptPwd),ip)
if !success {
context.JSON(http.StatusOK, Model.Res{
Code: http.StatusNotImplemented,

@ -12,6 +12,7 @@ import (
var loginModel Model.Selector
var tableName = "t_sys_loginperson"
var db = DbUtil.Engine
func init() {
_, loginModel = loginModel.Get(tableName)
@ -22,7 +23,7 @@ func init() {
2020-02-05
*/
func Login(username string, password string) (bool, string, string, string) {
func Login(username string, password string, ip string) (bool, string, string, string) {
//身份号
var identityId = DefaultConst.IdentityId
//人员号
@ -31,7 +32,7 @@ func Login(username string, password string) (bool, string, string, string) {
var personName = ""
//通过用户名查找人员ID
var sql = "select * from t_sys_loginperson where login_name=? and b_use=1"
list, err := DbUtil.Engine.SQL(sql, username).Query().List()
list, err := db.SQL(sql, username).Query().List()
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, err.Error())
}
@ -52,12 +53,42 @@ func Login(username string, password string) (bool, string, string, string) {
//修改密码的加密算法基于ldap,黄海于2020-04-27
ldapPassword := LdapUtil.GetLdapPassword(password)
if ldapPassword == databasePassword {
//记录日志
WriteLoginLog(identityId, personId, ip, 1, username)
//返回结果
return true, identityId, personId, personName
} else {
//记录日志
WriteLoginLog(identityId, personId, ip, -1, username)
return false, identityId, personId, personName
}
}
/**
:
2020-07-08
*/
func WriteLoginLog(identityId string, personId string, ip string, loginState int, loginName string) {
//表名
var tableName string
//管理员或教师
if identityId == "1" || identityId == "2" {
tableName = "t_base_teacher"
} else if identityId == "3" {
tableName = "t_base_student"
} else {
tableName = "t_base_parent"
}
//查询出结果
sql := "select province_code,city_code,district_code,bureau_id from " + tableName + " where person_id=?"
list, _ := db.SQL(sql, personId).Query().List()
sql = `insert into t_sys_loginperson_log(identity_id,person_id,ip_address,province_code,city_code,district_code,bureau_id,login_state,login_name) values(?,?,?,?,?,?,?,?,?,?)`
db.SQL(sql, identityId, personId, ip, list[0]["province_code"].(string),
list[0]["city_code"].(string), list[0]["district_code"].(string), list[0]["bureau_id"].(string), loginState, loginName).Execute()
}
/**
ID
@ -65,7 +96,7 @@ func Login(username string, password string) (bool, string, string, string) {
*/
func GetPersonInfoById(identityId string, personId string) map[string]interface{} {
sql := "select bureau_id from t_sys_loginperson where identity_id=? and person_id=?"
list, _ := DbUtil.Engine.SQL(sql, identityId, personId).Query().List()
list, _ := db.SQL(sql, identityId, personId).Query().List()
if len(list) > 0 {
return list[0]
} else {

@ -9,9 +9,9 @@ import (
2020-02-05
*/
func Login(username string, password string) (bool, string, string, string) {
func Login(username string, password string,ip string) (bool, string, string, string) {
//调用dao层的方法,组合成service方法层
result, identityId, personId, personName := DaoSysLoginPerson.Login(username, password)
result, identityId, personId, personName := DaoSysLoginPerson.Login(username, password,ip)
return result, identityId, personId, personName
}

Loading…
Cancel
Save