You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package DaoSysLoginPerson
import (
"dsSso/Const/DefaultConst"
"dsSso/Const/ErrorConst"
"dsSso/Model"
"dsSso/Utils/CommonUtil"
"dsSso/Utils/DbUtil"
"dsSso/Utils/LdapUtil"
"dsSso/Utils/LogUtil"
)
var loginModel Model.Selector
var tableName = "t_sys_loginperson"
var db = DbUtil.Engine
func init() {
_, loginModel = loginModel.Get(tableName)
}
/**
功能:验证用户名和密码是否正确
作者:黄海
时间2020-02-05
*/
func Login(username string, password string, ip string) (bool, string, string, string) {
//身份号
var identityId = DefaultConst.IdentityId
//人员号
var personId = DefaultConst.PersonId
//姓名
var personName = ""
//通过用户名查找人员ID
var sql = "select * from t_sys_loginperson where login_name=? and b_use=1"
list, err := db.SQL(sql, username).Query().List()
if err != nil {
LogUtil.Error(ErrorConst.SqlQueryError, err.Error())
}
//如果用户名不存在
if len(list) == 0 {
return false, identityId, personId, personName
}
record := list[0]
//身份号
identityId = CommonUtil.ConvertInt64ToString(record["identity_id"].(int64))
//人员号
personId = record["person_id"].(string)
//人员姓名
personName = record["person_name"].(string)
//数据库中的密码
databasePassword := record["pwd"].(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()
}