mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 03:35:48 +08:00
fix log
This commit is contained in:
parent
fc5aefe435
commit
7d1707ca7c
@ -40,8 +40,14 @@ func main() {
|
||||
demoRouterGroup.POST("/login", register.Login)
|
||||
demoRouterGroup.POST("/reset_password", register.ResetPassword)
|
||||
}
|
||||
cmsRouterGroup := r.Group("/cms")
|
||||
{
|
||||
cmsRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode)
|
||||
cmsRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode)
|
||||
cmsRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes)
|
||||
}
|
||||
defaultPorts := config.Config.Demo.Port
|
||||
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 42233 as port")
|
||||
ginPort := flag.Int("port", defaultPorts[0], "get ginServerPort from cmd,default 10004 as port")
|
||||
flag.Parse()
|
||||
fmt.Println("start demo api server, port: ", *ginPort)
|
||||
address := "0.0.0.0:" + strconv.Itoa(*ginPort)
|
||||
|
112
internal/demo/register/invitation_code.go
Normal file
112
internal/demo/register/invitation_code.go
Normal file
@ -0,0 +1,112 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
apiStruct "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type InvitationCode struct {
|
||||
InvitationCode string `json:"invitationCode"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UserID string `json:"userID"`
|
||||
LastTime time.Time `json:"lastTime"`
|
||||
Status int32 `json:"status"`
|
||||
}
|
||||
|
||||
type GenerateInvitationCodeReq struct {
|
||||
CodesNum int `json:"codesNum" binding:"required"`
|
||||
CodeLen int `json:"codeLen" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GenerateInvitationCodeResp struct {
|
||||
Codes []string `json:"codes"`
|
||||
}
|
||||
|
||||
func GenerateInvitationCode(c *gin.Context) {
|
||||
req := GenerateInvitationCodeReq{}
|
||||
resp := GenerateInvitationCodeResp{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
var err error
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
resp.Codes, err = imdb.BatchCreateInvitationCodes(req.CodesNum, req.CodeLen)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "BatchCreateInvitationCodes failed", req.CodesNum, req.CodeLen)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
||||
|
||||
type QueryInvitationCodeReq struct {
|
||||
Code string `json:"code" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type QueryInvitationCodeResp struct {
|
||||
InvitationCode
|
||||
}
|
||||
|
||||
func QueryInvitationCode(c *gin.Context) {
|
||||
req := QueryInvitationCodeReq{}
|
||||
resp := QueryInvitationCodeResp{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
invitation, err := imdb.GetInvitationCode(req.Code)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetInvitationCode failed", req.Code)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
|
||||
return
|
||||
}
|
||||
resp.UserID = invitation.UserID
|
||||
resp.CreateTime = invitation.CreateTime
|
||||
resp.Status = invitation.Status
|
||||
resp.LastTime = invitation.LastTime
|
||||
resp.InvitationCode.InvitationCode = invitation.InvitationCode
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
||||
|
||||
type GetInvitationCodesReq struct {
|
||||
Status int32 `json:"status" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
apiStruct.Pagination
|
||||
}
|
||||
|
||||
type GetInvitationCodesResp struct {
|
||||
apiStruct.Pagination
|
||||
codes []InvitationCode
|
||||
}
|
||||
|
||||
func GetInvitationCodes(c *gin.Context) {
|
||||
req := GetInvitationCodesReq{}
|
||||
resp := GetInvitationCodesResp{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
codes, err := imdb.GetInvitationCodes(req.ShowNumber, req.PageNumber, req.Status)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetInvitationCode failed", req.ShowNumber, req.PageNumber, req.Status)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "Verification code error!"})
|
||||
return
|
||||
}
|
||||
resp.Pagination.PageNumber = req.PageNumber
|
||||
resp.Pagination.ShowNumber = req.ShowNumber
|
||||
utils.CopyStructFields(codes, resp.codes)
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
137
internal/demo/register/ip_limit.go
Normal file
137
internal/demo/register/ip_limit.go
Normal file
@ -0,0 +1,137 @@
|
||||
package register
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type QueryIPReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
IP string `json:"ip"`
|
||||
}
|
||||
|
||||
type QueryIPResp struct {
|
||||
IP string `json:"ip"`
|
||||
RegisterNum int `json:"num"`
|
||||
UserIDList []string `json:"userIDList"`
|
||||
Status int
|
||||
}
|
||||
|
||||
func QueryIP(c *gin.Context) {
|
||||
req := QueryIPReq{}
|
||||
resp := QueryIPResp{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
ips, err := imdb.QueryUserIPLimits(req.IP)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetInvitationCode failed", req.IP)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "QueryUserIPLimits error!"})
|
||||
return
|
||||
}
|
||||
resp.IP = req.IP
|
||||
resp.RegisterNum = len(ips)
|
||||
for _, ip := range ips {
|
||||
resp.UserIDList = append(resp.UserIDList, ip.UserID)
|
||||
}
|
||||
b, _ := imdb.IsLimitLoginIp(req.IP)
|
||||
if b == true {
|
||||
resp.Status = 1
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
|
||||
}
|
||||
|
||||
type GetIPListReq struct {
|
||||
}
|
||||
|
||||
type GetIPListResp struct {
|
||||
}
|
||||
|
||||
func GetIPList(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
type AddIPLimitReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
IP string `json:"ip"`
|
||||
LimitTime int32 `json:"limitTime"`
|
||||
}
|
||||
|
||||
type AddIPLimitResp struct {
|
||||
}
|
||||
|
||||
func AddIPLimit(c *gin.Context) {
|
||||
req := AddIPLimitReq{}
|
||||
//resp := AddIPLimitResp{}
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
|
||||
if err := imdb.InsertOneIntoIpLimits(db.IpLimit{
|
||||
Ip: req.IP,
|
||||
LimitRegister: 1,
|
||||
LimitLogin: 1,
|
||||
CreateTime: time.Now(),
|
||||
LimitTime: time.Time{},
|
||||
}); err != nil {
|
||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP, req.LimitTime)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB, "errMsg": "InsertOneIntoIpLimits error!"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": ""})
|
||||
}
|
||||
|
||||
type RemoveIPLimitReq struct {
|
||||
}
|
||||
|
||||
type RemoveIPLimitResp struct {
|
||||
}
|
||||
|
||||
func RemoveIPLimit(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// ===========================================sk 写
|
||||
|
||||
type QueryUserIDIPLimitReq struct {
|
||||
UserID string `json:"userID" binding:"required"`
|
||||
}
|
||||
|
||||
type QueryUserIDIPLimitResp struct {
|
||||
}
|
||||
|
||||
func QueryUserIDIPLimit(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
type AddUserIPLimitReq struct {
|
||||
}
|
||||
|
||||
type AddUserIPLimitResp struct {
|
||||
}
|
||||
|
||||
// 添加ip 特定用户才能登录 user_ip_limits 表
|
||||
func AddUserIPLimit(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
type RemoveUserIPLimitReq struct {
|
||||
}
|
||||
|
||||
type RemoveUserIPLimitResp struct {
|
||||
}
|
||||
|
||||
// 删除ip 特定用户才能登录 user_ip_limits 表
|
||||
func RemoveUserIPLimit(c *gin.Context) {
|
||||
|
||||
}
|
@ -5,9 +5,10 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
http2 "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"encoding/json"
|
||||
@ -41,6 +42,17 @@ func SetPassword(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var ip string
|
||||
Limited, LimitError := imdb.IsLimitRegisterIp(ip)
|
||||
if LimitError != nil {
|
||||
log.Error(params.OperationID, utils.GetSelfFuncName(), LimitError, ip)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
}
|
||||
if Limited {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
|
||||
}
|
||||
|
||||
var account string
|
||||
if params.Email != "" {
|
||||
account = params.Email
|
||||
@ -65,7 +77,7 @@ func SetPassword(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
if config.Config.Demo.NeedInvitationCode {
|
||||
err := im_mysql_model.CheckInvitationCode(params.InvitationCode)
|
||||
err := imdb.CheckInvitationCode(params.InvitationCode)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.InvitationError, "errMsg": "邀请码错误"})
|
||||
}
|
||||
@ -120,12 +132,20 @@ func SetPassword(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
|
||||
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID, params.AreaCode)
|
||||
err = imdb.SetPassword(account, params.Password, params.Ex, userID, params.AreaCode)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if config.Config.Demo.NeedInvitationCode {
|
||||
//判断一下验证码的使用情况
|
||||
LockSucc := imdb.TryLockInvitationCode(params.InvitationCode, userID)
|
||||
if LockSucc {
|
||||
imdb.FinishInvitationCode(params.InvitationCode, userID)
|
||||
}
|
||||
}
|
||||
|
||||
log.Info(params.OperationID, "end setPassword", account, params.Password)
|
||||
// demo onboarding
|
||||
if params.UserID == "" && config.Config.Demo.OnboardProcess {
|
||||
|
@ -30,13 +30,6 @@ func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq)
|
||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||
}
|
||||
log.Debug(req.OperationID, "copy ", user, req.UserInfo)
|
||||
Limited, LimitError := imdb.IsLimitRegisterIp(req.UserInfo.CreateIp)
|
||||
if LimitError != nil {
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: LimitError.Error()}}, nil
|
||||
}
|
||||
if Limited {
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.RegisterLimit, ErrMsg: "Register Limit"}}, nil
|
||||
}
|
||||
err := imdb.UserRegister(user)
|
||||
if err != nil {
|
||||
if err == constant.InvitationMsg {
|
||||
|
6
pkg/base_info/pagination.go
Normal file
6
pkg/base_info/pagination.go
Normal file
@ -0,0 +1,6 @@
|
||||
package base_info
|
||||
|
||||
type Pagination struct {
|
||||
PageNumber int32 `json:"pageNumber" binding:"required"`
|
||||
ShowNumber int32 `json:"showNumber" binding:"required"`
|
||||
}
|
@ -2,6 +2,7 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
_ "gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -46,7 +47,11 @@ func AddUserRegisterAddFriendIDList(userIDList ...string) error {
|
||||
for _, v := range userIDList {
|
||||
list = append(list, db.RegisterAddFriend{UserID: v})
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Create(list).Error
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Create(list)
|
||||
if int(result.RowsAffected) < len(userIDList) {
|
||||
return errors.New("some line insert failed")
|
||||
}
|
||||
err := result.Error
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
"github.com/jinzhu/gorm"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
@ -10,15 +11,17 @@ import (
|
||||
/**
|
||||
* 批量生成邀请码
|
||||
*/
|
||||
func BatchCreateInvitationCodes(CodeNums int, CodeLen int) error {
|
||||
func BatchCreateInvitationCodes(CodeNums int, CodeLen int) ([]string, error) {
|
||||
i := CodeNums
|
||||
var codes []string
|
||||
for {
|
||||
if i == 0 {
|
||||
break
|
||||
}
|
||||
code := CreateRandomString(CodeLen)
|
||||
invitation := new(db.Invitation)
|
||||
invitation.CreateTime = time.Now()
|
||||
invitation.InvitationCode = CreateRandomString(CodeLen)
|
||||
invitation.InvitationCode = code
|
||||
invitation.LastTime = time.Now()
|
||||
invitation.Status = 0
|
||||
invitation.UserID = ""
|
||||
@ -29,8 +32,9 @@ func BatchCreateInvitationCodes(CodeNums int, CodeLen int) error {
|
||||
if result.RowsAffected > 0 {
|
||||
i = i - 1
|
||||
}
|
||||
codes = append(codes, code)
|
||||
}
|
||||
return nil
|
||||
return codes, nil
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,9 +58,9 @@ func CheckInvitationCode(code string) error {
|
||||
/**
|
||||
* 尝试加锁模式解决邀请码抢占的问题
|
||||
*/
|
||||
func TryLockInvitationCode(Code string, UserId string) bool {
|
||||
func TryLockInvitationCode(Code string, UserID string) bool {
|
||||
Data := make(map[string]interface{}, 0)
|
||||
Data["user_id"] = UserId
|
||||
Data["user_id"] = UserID
|
||||
Data["status"] = 1
|
||||
Data["last_time"] = time.Now()
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("invitations").Where("invitation_code=? and user_id=? and status=?", Code, "", 0).Updates(Data)
|
||||
@ -79,6 +83,17 @@ func FinishInvitationCode(Code string, UserId string) bool {
|
||||
return result.RowsAffected > 0
|
||||
}
|
||||
|
||||
func GetInvitationCode(code string) (*db.Invitation, error) {
|
||||
invitation := &db.Invitation{
|
||||
InvitationCode: code,
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(invitation).Find(invitation).Error
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
return invitation, nil
|
||||
}
|
||||
return invitation, err
|
||||
}
|
||||
|
||||
func CreateRandomString(strlen int) string {
|
||||
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
bytes := []byte(str)
|
||||
@ -89,3 +104,10 @@ func CreateRandomString(strlen int) string {
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
func GetInvitationCodes(pageNumber, showNumber, status int32) ([]db.Invitation, error) {
|
||||
var invitationList []db.Invitation
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(db.Invitation{}).Limit(int(showNumber)).Offset(int(showNumber*(pageNumber-1))).Where("status=?", status).
|
||||
Order("create_time desc").Find(&invitationList).Error
|
||||
return invitationList, err
|
||||
}
|
||||
|
40
pkg/common/db/mysql_model/im_mysql_model/ip_model.go
Normal file
40
pkg/common/db/mysql_model/im_mysql_model/ip_model.go
Normal file
@ -0,0 +1,40 @@
|
||||
package im_mysql_model
|
||||
|
||||
import "Open_IM/pkg/common/db"
|
||||
|
||||
func IsLimitRegisterIp(RegisterIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_register=? and limit_time>now()", RegisterIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func IsLimitLoginIp(LoginIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_login=? and limit_time>now()", LoginIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func IsLimitUserLoginIp(userID string, LoginIp string) (bool, error) {
|
||||
//如果已经存在则放行
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("ip=? and user_id=?", LoginIp, userID).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count == 0, nil
|
||||
}
|
||||
|
||||
func QueryUserIPLimits(ip string) ([]db.UserIpLimit, error) {
|
||||
var ips []db.UserIpLimit
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("ip=?", ip).Find(&ips).Error
|
||||
return ips, err
|
||||
}
|
||||
|
||||
func InsertOneIntoIpLimits(ipLimits db.IpLimit) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Create(ipLimits).Error
|
||||
}
|
@ -46,20 +46,10 @@ func UserRegister(user db.User) error {
|
||||
user.LastLoginTime = time.Now()
|
||||
user.LoginTimes = 0
|
||||
user.LastLoginIp = user.CreateIp
|
||||
if config.Config.Demo.NeedInvitationCode {
|
||||
//判断一下验证码的使用情况
|
||||
LockSucc := TryLockInvitationCode(user.InvitationCode, user.UserID)
|
||||
if !LockSucc {
|
||||
return constant.InvitationMsg
|
||||
}
|
||||
}
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config.Config.Demo.NeedInvitationCode {
|
||||
FinishInvitationCode(user.InvitationCode, user.UserID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -288,30 +278,3 @@ func GetBlockUsersNumCount() (int32, error) {
|
||||
}
|
||||
return int32(count), nil
|
||||
}
|
||||
|
||||
func IsLimitRegisterIp(RegisterIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_register=? and limit_time>now()", RegisterIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func IsLimitLoginIp(LoginIp string) (bool, error) {
|
||||
//如果已经存在则限制
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("ip_limits").Where("ip=? and limit_login=? and limit_time>now()", LoginIp, 1).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func IsLimitUserLoginIp(userID string, LoginIp string) (bool, error) {
|
||||
//如果已经存在则放行
|
||||
var count int64
|
||||
if err := db.DB.MysqlDB.DefaultGormDB().Table("user_ip_limits").Where("ip=? and user_id=?", LoginIp, userID).Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count == 0, nil
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ fi
|
||||
|
||||
check=$(ps aux | grep -w ./${cron_task_name} | grep -v grep | wc -l)
|
||||
if [ $check -ge 1 ]; then
|
||||
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is cron_task_name"${COLOR_SUFFIX}
|
||||
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImCronTask"${COLOR_SUFFIX}
|
||||
else
|
||||
echo -e ${RED_PREFIX}"cron_task_name service does not start normally"${COLOR_SUFFIX}
|
||||
echo -e ${RED_PREFIX}"please check ../logs/openIM.log "${COLOR_SUFFIX}
|
||||
|
Loading…
x
Reference in New Issue
Block a user