management system add api

This commit is contained in:
Gordon
2021-09-26 14:26:45 +08:00
parent 98ed0234fc
commit b27fc2ba35
18 changed files with 275 additions and 174 deletions
+5 -4
View File
@@ -108,7 +108,10 @@ type config struct {
}
}
}
Manager struct {
AppManagerUid []string `yaml:"appManagerUid"`
Secrets []string `yaml:"secrets"`
}
Kafka struct {
Ws2mschat struct {
Addr []string `yaml:"addr"`
@@ -124,9 +127,7 @@ type config struct {
MsgToPush string `yaml:"msgToPush"`
}
}
AppManagerUid string
Secret string
Secret string `yaml:"secret"`
MultiLoginPolicy struct {
OnlyOneTerminalAccess bool `yaml:"onlyOneTerminalAccess"`
MobileAndPCTerminalAccessButOtherTerminalKickEachOther bool `yaml:"mobileAndPCTerminalAccessButOtherTerminalKickEachOther"`
+2
View File
@@ -69,3 +69,5 @@ var ContentType2PushContent = map[int64]string{
Video: "[video]",
File: "[file]",
}
const FriendAcceptTip = "You have successfully become friends, so start chatting"
@@ -1,12 +1,28 @@
package im_mysql_model
import (
"Open_IM/src/common/config"
"Open_IM/src/common/db"
pbAuth "Open_IM/src/proto/auth"
"Open_IM/src/utils"
_ "github.com/jinzhu/gorm/dialects/mysql"
"time"
)
func init() {
//init managers
var pb pbAuth.UserRegisterReq
for k, v := range config.Config.Manager.AppManagerUid {
if !IsExistUser(v) {
pb.UID = v
pb.Name = "AppManager" + utils.IntToString(k+1)
err := UserRegister(&pb)
if err != nil {
panic(err)
}
}
}
}
func UserRegister(pb *pbAuth.UserRegisterReq) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
@@ -113,3 +129,19 @@ func SelectAllUID() ([]string, error) {
}
return uid, nil
}
func IsExistUser(uid string) bool {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return false
}
var number int32
err = dbConn.Raw("select count(*) from `user` where uid = ?", uid).Count(&number).Error
if err != nil {
return false
}
if number != 1 {
return false
}
return true
}