From 47b7129858062217b6e84a3b320433198b8996a7 Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Wed, 29 Jul 2020 08:20:55 +0800 Subject: [PATCH] 'commit' --- dsSso/Config/Config.ini | 2 +- .../ControllerRecaptcha.go | 2 +- .../DaoSysLoginPerson/DaoSysLoginPerson.go | 101 ++++++++++++++++++ .../ServiceLoginPerson/ServiceLoginPerson.go | 39 ++++++- dsSso/Utils/CommonUtil/CommonUtil.go | 25 ++++- dsSso/Utils/IdCardUtil/IdCardUtil.go | 12 +++ dsSso/Utils/MobileUtil/MobileUtil.go | 11 ++ 7 files changed, 185 insertions(+), 7 deletions(-) create mode 100644 dsSso/Utils/IdCardUtil/IdCardUtil.go create mode 100644 dsSso/Utils/MobileUtil/MobileUtil.go diff --git a/dsSso/Config/Config.ini b/dsSso/Config/Config.ini index bf564e85..07bb1788 100644 --- a/dsSso/Config/Config.ini +++ b/dsSso/Config/Config.ini @@ -2,7 +2,6 @@ ip = 10.10.14.187 port = 22066 database = base_db_dev -#database = base_db user = root pwd = DsideaL147258369 @@ -26,6 +25,7 @@ KafkaAccessLogTopic = dsAccessLog [server] #gin服务器的端口 port = 8000 + # 验证码的有效时间,单位:秒 CaptchaExpireTime = 120 diff --git a/dsSso/Controller/ControllerRecaptcha/ControllerRecaptcha.go b/dsSso/Controller/ControllerRecaptcha/ControllerRecaptcha.go index afdb5d71..8c763b99 100644 --- a/dsSso/Controller/ControllerRecaptcha/ControllerRecaptcha.go +++ b/dsSso/Controller/ControllerRecaptcha/ControllerRecaptcha.go @@ -15,7 +15,7 @@ func Serve(w http.ResponseWriter, r *http.Request, id string, width, height int) w.Header().Set("Expires", "0") var content bytes.Buffer w.Header().Set("Content-Type", "image/png") - //设置到REDIS + //设置到Redis captcha.SetCustomStore(&RedisStoreBean) captcha.WriteImage(&content, id, width, height) if content.Bytes()==nil{ diff --git a/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go b/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go index cf3c79be..4b2613d9 100644 --- a/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go +++ b/dsSso/Dao/DaoSysLoginPerson/DaoSysLoginPerson.go @@ -104,3 +104,104 @@ func WriteLoginLog(identityId string, personId string, ip string, loginState int fmt.Println(err.Error()) } } + +/** +功能:根据邮箱获取人员ID +作者:黄海 +时间:2020-07-29 +*/ +func GetPersonIdByEmail(email string) (string, error) { + //目前的系统设计,只支持教师有邮箱 + sql := `select person_id from t_base_teacher where b_use=1 and dzxx=?` + list, err := db.SQL(sql, email).Query().List() + if err != nil { + return "获取人员信息失败!", err + } + //如果没有找到指定邮箱的人员 + if len(list) == 0 { + return "", nil + } + //如果找到了 + return list[0]["person_id"].(string), nil +} + +/** +功能:根据身份证号获取人员ID +作者:黄海 +时间:2020-07-29 +*/ +func GetPersonIdByIdCard(idCard string) (string, error) { + //目前的系统设计,支持教师+学生 + sql := `select person_id from t_base_teacher where b_use=1 and sfzjh=?` + list, err := db.SQL(sql, idCard).Query().List() + if err != nil { + return "获取教师身份证号信息失败!", err + } + //如果没有找到指定身份证号的人员 + if len(list) == 0 { + //继续判断是不是在学生的身份证号 + sql := `select person_id from t_base_student where b_use=1 and sfzjh=?` + list, err = db.SQL(sql, idCard).Query().List() + if err != nil { + return "获取学生身份证号信息失败!", err + } + if len(list) == 0 { + return "", nil + } else { + //如果找到了 + return list[0]["person_id"].(string), nil + } + } else { + //如果找到了 + return list[0]["person_id"].(string), nil + } +} + +/** +功能:根据手机号获取人员ID +作者:黄海 +时间:2020-07-29 +*/ +func GetPersonIdByTel(tel string) (string, error) { + //目前的系统设计,支持教师+家长 + sql := `select person_id from t_base_teacher where b_use=1 and lxdh=?` + list, err := db.SQL(sql, tel).Query().List() + if err != nil { + return "获取教师手机号信息失败!", err + } + //如果没有找到指定身份证号的人员 + if len(list) == 0 { + //继续判断是不是在学生的身份证号 + sql := `select person_id from t_base_parent where b_use=1 and lxdh=?` + list, err = db.SQL(sql, tel).Query().List() + if err != nil { + return "获取家长手机号信息失败!", err + } + if len(list) == 0 { + return "", nil + } else { + //如果找到了 + return list[0]["person_id"].(string), nil + } + } else { + //如果找到了 + return list[0]["person_id"].(string), nil + } +} + +/** +功能:根据人员ID获取人员的登录名 +作者:黄海 +时间:2020-07-29 +*/ +func GetLoginNameByPersonId(personId string) (string, error) { + sql := `select login_name from t_sys_loginperson where b_use=1 and person_id=?` + list, err := db.SQL(sql, personId).Query().List() + if err != nil { + return "获取人员登录名失败!", err + } + if len(list) == 0 { + return "", nil + } + return list[0]["login_name"].(string), nil +} diff --git a/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go b/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go index aae8450d..e1c864aa 100644 --- a/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go +++ b/dsSso/Service/ServiceLoginPerson/ServiceLoginPerson.go @@ -2,6 +2,9 @@ package ServiceLoginPerson import ( "dsSso/Dao/DaoSysLoginPerson" + "dsSso/Utils/CommonUtil" + "dsSso/Utils/MobileUtil" + "fmt" ) /** @@ -9,10 +12,38 @@ import ( 作者:黄海 时间:2020-02-05 */ -func Login(username string, password string,ip string) (bool, string, string, string) { +func Login(username string, password string, ip string) (bool, string, string, string) { + //异常处理 + defer func() { + if err := recover(); err != nil { + fmt.Printf("%s\n", err) + } + }() + var personId string + var err error + //1、判断是不是身份证件号,是不是邮箱,是不是联系电话 + if CommonUtil.IsEmail(username) { + personId, err = DaoSysLoginPerson.GetPersonIdByEmail(username) + if err != nil || len(personId) == 0 { + return false, "", "", "" + } + } else if CommonUtil.IsIdCard(username) { + personId, err = DaoSysLoginPerson.GetPersonIdByIdCard(username) + if err != nil || len(personId) == 0 { + return false, "", "", "" + } + } else if MobileUtil.VerifyMobileFormat(username) { + personId, err = DaoSysLoginPerson.GetPersonIdByTel(username) + if err != nil || len(personId) == 0 { + return false, "", "", "" + } + } + //根据person_id换取统一的登录名 + username, err = DaoSysLoginPerson.GetLoginNameByPersonId(personId) + if err != nil || len(username) == 0 { + return false, "", "", "" + } //调用dao层的方法,组合成service方法层 - result, identityId, personId, personName := DaoSysLoginPerson.Login(username, password,ip) + result, identityId, personId, personName := DaoSysLoginPerson.Login(username, password, ip) return result, identityId, personId, personName } - - diff --git a/dsSso/Utils/CommonUtil/CommonUtil.go b/dsSso/Utils/CommonUtil/CommonUtil.go index 8bf694c8..9531413b 100644 --- a/dsSso/Utils/CommonUtil/CommonUtil.go +++ b/dsSso/Utils/CommonUtil/CommonUtil.go @@ -3,12 +3,14 @@ package CommonUtil import ( "bufio" "bytes" + "dsSso/Utils/IdCardUtil" "errors" "log" "net" "net/http" "os" "os/exec" + "regexp" "strconv" "strings" "time" @@ -233,4 +235,25 @@ func ConvertStringToInt(s string) int { func ConvertStringToInt32(s string) int32 { int, _ := strconv.Atoi(s) return int32(int) -} \ No newline at end of file +} + +/** +功能:判断是不是合法的Email +作者:黄海 +时间:2020-03-23 +*/ +func IsEmail(email string) bool { + pattern := `^[0-9a-z][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}[0-9a-z]\.){1,4}[a-z]{2,4}$` + reg := regexp.MustCompile(pattern) + return reg.MatchString(email) +} + +/** +功能:判断是不是合法的身份证号 +作者:黄海 +时间:2020-06-16 +*/ +func IsIdCard(idCard string) bool { + IdCardNo := []byte(idCard) + return IdCardUtil.IsValidIdCardNo(&IdCardNo) +} diff --git a/dsSso/Utils/IdCardUtil/IdCardUtil.go b/dsSso/Utils/IdCardUtil/IdCardUtil.go new file mode 100644 index 00000000..23450fb2 --- /dev/null +++ b/dsSso/Utils/IdCardUtil/IdCardUtil.go @@ -0,0 +1,12 @@ +package IdCardUtil + +import ( + "github.com/bluesky335/IDCheck/IdNumber" +) + + +// Check IdCard number valid. +func IsValidIdCardNo(IdCardNo *[]byte) bool { + var id = IdNumber.New(string(*IdCardNo)) + return id.IsValid() +} diff --git a/dsSso/Utils/MobileUtil/MobileUtil.go b/dsSso/Utils/MobileUtil/MobileUtil.go new file mode 100644 index 00000000..b8a984f0 --- /dev/null +++ b/dsSso/Utils/MobileUtil/MobileUtil.go @@ -0,0 +1,11 @@ +package MobileUtil + +import "regexp" + +//mobile verify +func VerifyMobileFormat(mobileNum string) bool { + regular := "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$" + + reg := regexp.MustCompile(regular) + return reg.MatchString(mobileNum) +}