del: 移除旧代码假系统数据库备份
This commit is contained in:
@@ -11,8 +11,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"be.ems/lib/log"
|
||||
"be.ems/lib/oauth"
|
||||
"be.ems/src/modules/system/model"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"xorm.io/xorm"
|
||||
@@ -29,7 +27,7 @@ type Menu struct {
|
||||
Title string `json:"title"`
|
||||
Icon string `json:"icon"`
|
||||
Href string `json:"href"`
|
||||
ParentId int `json:"parent_id`
|
||||
ParentId int `json:"parent_id"`
|
||||
Remark int `json:"remark"`
|
||||
}
|
||||
|
||||
@@ -149,7 +147,7 @@ func ConstructInsertSQL(tableName string, insertData interface{}) (string, []str
|
||||
for c, v := range r.(map[string]interface{}) {
|
||||
log.Tracef("c: %v v: %v", c, v)
|
||||
if cl == "" {
|
||||
cl = fmt.Sprintf("%s", c)
|
||||
cl = fmt.Sprint(c)
|
||||
} else {
|
||||
cl = fmt.Sprintf("%s, %s", cl, c)
|
||||
}
|
||||
@@ -510,33 +508,6 @@ const (
|
||||
MeasureTaskStatusDeleted = "Deleted"
|
||||
)
|
||||
|
||||
type MTask struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
|
||||
NeSet struct {
|
||||
NEs []string `json:"nes"`
|
||||
} `json:"neSet" xorm:"ne_set"`
|
||||
KpiSet struct {
|
||||
Code string `json:"Code"`
|
||||
KPIs []string `json:"KPIs`
|
||||
} `json:"kpiSet" xorm:"kpi_set"`
|
||||
StartTime string `json:"startTime" xorm:"start_time"`
|
||||
EndTime string `json:"endTime" xorm:"end_time"`
|
||||
Periods []struct {
|
||||
Start string `json:"start"`
|
||||
End string `json:"end"`
|
||||
} `json:"Periods" xorm:"periods`
|
||||
Schedule struct {
|
||||
Type string `json:"type"`
|
||||
Days []int `json:"days"`
|
||||
} `json:"schedule" xorm:"schedule"`
|
||||
GranulOption string `json:"granulOption" xorm:"granul_option"`
|
||||
Status string `json:"status" xorm:"status"`
|
||||
CreateTime string `json:"createTime" xorm:"create_time"`
|
||||
UpdateTime string `json:"updateTime" xorm:"update_time"`
|
||||
DeleteTime string `json:"deleteTime xorm:"delete_time"`
|
||||
}
|
||||
|
||||
type ScheduleJ struct {
|
||||
Type string `json:"Type"`
|
||||
Days []int `json:"Days"`
|
||||
@@ -665,40 +636,6 @@ func XormUpdateTableByWhere(whereCondition string, tableName string, tbInfo inte
|
||||
return affected, nil
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Id int `json:"id" xorm:"pk 'id' autoincr"`
|
||||
AccountId string `json:"accountId"`
|
||||
Name string `json:"name" xorm:"name"`
|
||||
Sn string `json:"sn"`
|
||||
Gender string `json:"gender"`
|
||||
Description string `json:"description"`
|
||||
TelephoneNumber string `json:"telephoneNumber" xorm:"telephone_number"`
|
||||
Mobile string `json:"mobile"`
|
||||
Email string `json:"email" xorm:"email"`
|
||||
StartTime string `json:"startTime" xorm:"start_time"`
|
||||
EndTime string `json:"endTime" xorm:"end_time"`
|
||||
IdCardNumber string `json:"idCardNumber"`
|
||||
EmployeeNumber string `json:"employeeNumber"`
|
||||
Organize string `json:"organize"`
|
||||
EmployeeType string `json:"employeeType"`
|
||||
SupporterCorpName string `json:"supporterCorpName"`
|
||||
RealName string `json:"realName" xorm:"real_name"`
|
||||
Password string `json:"password" xorm:"password"`
|
||||
PasswordSha512 string `json:"passwordSha512"`
|
||||
ChangePasswordFlag int `json:"changePasswordFlag"`
|
||||
PasswordExpiration string `json:"passwordExpiration"`
|
||||
Status string `json:"status"`
|
||||
UserExpiration string `json:"userExpiration"`
|
||||
GroupName string `json:"groupId" xorm:"group_name"`
|
||||
Profile string `json:"profile" xorm:"profile"`
|
||||
Phone string `json:"phone" xorm:"phone"`
|
||||
CreateTime string `json:"createTime" xorm:"create_time"`
|
||||
UpdateTime string `json:"updateTime" xorm:"update_time"`
|
||||
|
||||
// 角色对象组
|
||||
Roles []model.SysRole `json:"roles" xorm:"-"`
|
||||
}
|
||||
|
||||
// 记录密码登录错误次数
|
||||
func pwdErrCountAdd(accountId, profileStr string, reset bool) int {
|
||||
if profileStr == "" {
|
||||
@@ -803,117 +740,6 @@ func pwdErrCountAdd(accountId, profileStr string, reset bool) int {
|
||||
return count
|
||||
}
|
||||
|
||||
func XormCheckLoginUser(name, password, cryptArgo string) (bool, *User, error) {
|
||||
log.Info("XormCheckLoginUser processing... ")
|
||||
|
||||
user := new(User)
|
||||
// has, err := xEngine.Table("user").Where("name='%s' and password=PASSWORD('%s')", name, password).Get(user)
|
||||
switch cryptArgo {
|
||||
case "mysql":
|
||||
has, err := xEngine.SQL("select * from user where account_id=? and password=PASSWORD(?)", name, password).Exist()
|
||||
if err != nil || has == false {
|
||||
log.Error("Failed to check user from database:", err)
|
||||
|
||||
return false, nil, err
|
||||
}
|
||||
case "md5":
|
||||
has, err := xEngine.
|
||||
SQL("select * from user where account_id=? and password=MD5(?)", name, password).Exist()
|
||||
if err != nil || has == false {
|
||||
log.Error("Failed to check user from database:", err)
|
||||
return false, nil, err
|
||||
}
|
||||
case "bcrypt":
|
||||
has, err := xEngine.Table("user").Where("account_id=?", name).Get(user)
|
||||
if err != nil || !has {
|
||||
log.Error("Failed to get user from database:", err)
|
||||
return false, nil, err
|
||||
}
|
||||
if oauth.BcryptCompare(user.Password, password) != nil {
|
||||
err := errors.New("Incorrect user name or password")
|
||||
log.Error(err)
|
||||
// 记录错误
|
||||
errCoutn := pwdErrCountAdd(user.AccountId, user.Profile, false)
|
||||
if errCoutn > 3 {
|
||||
// 登录失败次数过多,请30分钟后重试
|
||||
return false, nil, errors.New("Login failed too many times, please retry after 30 minutes")
|
||||
}
|
||||
return false, nil, err
|
||||
}
|
||||
// 重置错误次数
|
||||
pwdErrCountAdd(user.AccountId, user.Profile, true)
|
||||
default:
|
||||
errMsg := "Incorrect crypt algoritmo"
|
||||
log.Error("crypt:%s", errMsg)
|
||||
return false, nil, errors.New(errMsg)
|
||||
}
|
||||
|
||||
// enum('Active','Closed','Locked','Pending')
|
||||
errMsg := ""
|
||||
switch user.Status {
|
||||
case "Closed":
|
||||
errMsg = "Account disabled" // 账户已禁用
|
||||
case "Locked":
|
||||
errMsg = "Account locked" // 账户已锁定
|
||||
case "Pending":
|
||||
// errMsg = "账户已挂起"
|
||||
_, err := xEngine.Exec("UPDATE user SET status = 'Active' WHERE account_id = ?", user.AccountId)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
}
|
||||
if errMsg != "" {
|
||||
log.Error("user Status:%s", errMsg)
|
||||
return false, nil, errors.New(errMsg)
|
||||
}
|
||||
|
||||
// 密码到期时间
|
||||
if user.PasswordExpiration != "" {
|
||||
arr := strings.Split(user.PasswordExpiration, " ")
|
||||
if len(arr) > 0 {
|
||||
t, err := time.Parse("2006-01-02", arr[0])
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if t.Before(time.Now()) {
|
||||
errMsg := "Password expiration time" // 密码到期时间
|
||||
// 读取配置信息
|
||||
result, err := XormGetConfig("Security", "pwdStrong")
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
data := make(map[string]any)
|
||||
err = json.Unmarshal([]byte(result["value_json"].(string)), &data)
|
||||
if err != nil {
|
||||
log.Error("json Unmarshal:%s", errMsg)
|
||||
return false, nil, err
|
||||
}
|
||||
errMsg = data["outTimeMsg"].(string)
|
||||
log.Error("PasswordExpiration:%s", errMsg)
|
||||
return false, nil, errors.New(errMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 用户到期时间
|
||||
if user.UserExpiration != "" {
|
||||
arr := strings.Split(user.UserExpiration, " ")
|
||||
if len(arr) > 0 {
|
||||
t, err := time.Parse("2006-01-02", arr[0])
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
if t.Before(time.Now()) {
|
||||
errMsg := "User account expiration" // 用户账户到期
|
||||
log.Error("UserExpiration:%s", errMsg)
|
||||
return false, nil, errors.New(errMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true, user, nil
|
||||
}
|
||||
|
||||
func XormIsExistUser(accid string) (bool, error) {
|
||||
log.Info("XormIsExistUser processing... ")
|
||||
|
||||
@@ -1000,22 +826,22 @@ func XormInsertSession(name, host, token string, expires uint32, sessionFlag str
|
||||
if err != nil {
|
||||
return affected, err
|
||||
}
|
||||
if exist == true {
|
||||
affected, err = xSession.Table("session").Where("account_id = ? and host = ?", name, host).Update(session)
|
||||
if exist {
|
||||
affected, _ = xSession.Table("session").Where("account_id = ? and host = ?", name, host).Update(session)
|
||||
} else {
|
||||
affected, err = xSession.InsertOne(session)
|
||||
affected, _ = xSession.InsertOne(session)
|
||||
}
|
||||
} else { // single session for a user
|
||||
exist, err := xEngine.Table("session").Where("status = 'online' and account_id = ?", name).Exist()
|
||||
if err != nil {
|
||||
return affected, err
|
||||
}
|
||||
if exist == true {
|
||||
if exist {
|
||||
// todo...
|
||||
err := errors.New("user is logged in")
|
||||
return -1, err
|
||||
} else {
|
||||
affected, err = xSession.InsertOne(session)
|
||||
affected, _ = xSession.InsertOne(session)
|
||||
}
|
||||
}
|
||||
xSession.Commit()
|
||||
|
||||
Reference in New Issue
Block a user