From 1eb665ac8f6f86b08cbf9efd02c9d0f7b92ae471 Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Wed, 8 Jul 2020 17:29:33 +0800 Subject: [PATCH] 'commit' --- .../ControllerOauth2/ControllerOauth2.go | 3 +- .../DaoSysLoginPerson/DaoSysLoginPerson.go | 37 +++++++++++++++++-- .../ServiceLoginPerson/ServiceLoginPerson.go | 4 +- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go index 61528c9f..ad1feeee 100644 --- a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go +++ b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go @@ -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, diff --git a/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go b/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go index cc9d014a..fee1bbbf 100644 --- a/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go +++ b/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go @@ -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 { diff --git a/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go b/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go index 2808f55e..d658b68c 100644 --- a/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go +++ b/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go @@ -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 }