|
|
package DaoSysLoginPerson
|
|
|
|
|
|
import (
|
|
|
"dsSso/Const/DefaultConst"
|
|
|
"dsSso/Const/ErrorConst"
|
|
|
"dsSso/Model"
|
|
|
"dsSso/Utils/CommonUtil"
|
|
|
"dsSso/Utils/DbUtil"
|
|
|
"dsSso/Utils/LdapUtil"
|
|
|
"dsSso/Utils/LogUtil"
|
|
|
"dsSso/models"
|
|
|
"fmt"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
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()
|
|
|
|
|
|
//调用orm进行保存
|
|
|
var tLog models.TSysLoginpersonLog
|
|
|
tLog.BureauId = list[0]["bureau_id"].(string)
|
|
|
tLog.IdentityId = CommonUtil.ConvertStringToInt32(identityId)
|
|
|
tLog.PersonId = personId
|
|
|
tLog.ProvinceCode = list[0]["province_code"].(string)
|
|
|
tLog.CityCode = list[0]["city_code"].(string)
|
|
|
tLog.DistrictCode = list[0]["district_code"].(string)
|
|
|
tLog.IpAddress = ip
|
|
|
tLog.LoginName = loginName
|
|
|
tLog.LoginState = int32(loginState)
|
|
|
tLog.LoginTime = time.Now()
|
|
|
_, err := db.Insert(tLog)
|
|
|
if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
}
|
|
|
}
|