@ -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 - 0 8
* /
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 {