master
huanghai 5 years ago
parent 0e6074f673
commit 47b7129858

@ -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

@ -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{

@ -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
}

@ -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
}

@ -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)
}
}
/**
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)
}

@ -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()
}

@ -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)
}
Loading…
Cancel
Save