parent
3d4e0a0479
commit
e439ef4ddd
@ -1,142 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type paramsGetUsersOnlineStatus struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=200"`
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
}
|
||||
|
||||
func GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := paramsGetUsersOnlineStatus{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
log.NewError(params.OperationID, "parse token failed ", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "secret failed"})
|
||||
return
|
||||
}
|
||||
|
||||
req := &pbRelay.GetUsersOnlineStatusReq{
|
||||
OperationID: params.OperationID,
|
||||
UserIDList: params.UserIDList,
|
||||
}
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
log.NewDebug(params.OperationID, "GetUsersOnlineStatus req come here", params.UserIDList)
|
||||
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
continue
|
||||
} else {
|
||||
if reply.ErrCode == 0 {
|
||||
wsResult = append(wsResult, reply.SuccessResult...)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
//Online data merge of each node
|
||||
for _, v1 := range params.UserIDList {
|
||||
flag = false
|
||||
temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
for _, v2 := range wsResult {
|
||||
if v2.UserID == v1 {
|
||||
flag = true
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OnlineStatus
|
||||
temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
}
|
||||
}
|
||||
if !flag {
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OfflineStatus
|
||||
}
|
||||
respResult = append(respResult, temp)
|
||||
}
|
||||
log.NewDebug(params.OperationID, "Finished merged data", respResult)
|
||||
resp := gin.H{"errCode": 0, "errMsg": "", "successResult": respResult}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserInfo(c *gin.Context) {
|
||||
log.InfoByKv("api get userinfo init...", "")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsStruct{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbUser.GetUserInfoReq{
|
||||
UserIDList: params.UIDList,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.InfoByKv("api get user info is server", c.PostForm("OperationID"), c.Request.Header.Get("token"))
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"errorCode": 500,
|
||||
"errorMsg": "call rpc server failed",
|
||||
})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call get user info rpc server success", params.OperationID)
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
userInfoList := make([]userInfo, 0)
|
||||
for _, user := range RpcResp.Data {
|
||||
var ui userInfo
|
||||
ui.UID = user.Uid
|
||||
ui.Name = user.Name
|
||||
ui.Icon = user.Icon
|
||||
ui.Gender = user.Gender
|
||||
ui.Mobile = user.Mobile
|
||||
ui.Birth = user.Birth
|
||||
ui.Email = user.Email
|
||||
ui.Ex = user.Ex
|
||||
userInfoList = append(userInfoList, ui)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByKv("api get user info return success", params.OperationID, "args=%s", RpcResp.String())
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/utils"
|
||||
|
||||
// rpc "Open_IM/pkg/proto/relay"
|
||||
api "Open_IM/pkg/base_info"
|
||||
rpc "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//
|
||||
//func GetUsersOnlineStatus(c *gin.Context) {
|
||||
// params := api.GetUsersOnlineStatusReq{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if params.Secret != config.Config.Secret {
|
||||
// log.NewError(params.OperationID, "parse token failed ", params.Secret, config.Config.Secret)
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "secret failed"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// req := &pbRelay.GetUsersOnlineStatusReq{
|
||||
// OperationID: params.OperationID,
|
||||
// UserIDList: params.UserIDList,
|
||||
// }
|
||||
// var wsResult []*rpc.GetUsersOnlineStatusResp_SuccessResult
|
||||
// var respResult []*rpc.GetUsersOnlineStatusResp_SuccessResult
|
||||
// flag := false
|
||||
// log.NewDebug(params.OperationID, "GetUsersOnlineStatus req come here", params.UserIDList)
|
||||
//
|
||||
// grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
// for _, v := range grpcCons {
|
||||
// client := rpc.NewOnlineMessageRelayServiceClient(v)
|
||||
// reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
// continue
|
||||
// } else {
|
||||
// if reply.ErrCode == 0 {
|
||||
// wsResult = append(wsResult, reply.SuccessResult...)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// log.NewDebug(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
// //Online data merge of each node
|
||||
// for _, v1 := range params.UserIDList {
|
||||
// flag = false
|
||||
// temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
// for _, v2 := range wsResult {
|
||||
// if v2.UserID == v1 {
|
||||
// flag = true
|
||||
// temp.UserID = v1
|
||||
// temp.Status = constant.OnlineStatus
|
||||
// temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
// }
|
||||
// }
|
||||
// if !flag {
|
||||
// temp.UserID = v1
|
||||
// temp.Status = constant.OfflineStatus
|
||||
// }
|
||||
// respResult = append(respResult, temp)
|
||||
// }
|
||||
// log.NewDebug(params.OperationID, "Finished merged data", respResult)
|
||||
// resp := gin.H{"errCode": 0, "errMsg": "", "data": respResult}
|
||||
//
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
//}
|
||||
//params := api.AddBlacklistReq{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// log.NewError("0", "BindJSON failed ", err.Error())
|
||||
// return
|
||||
// }
|
||||
// req := &rpc.AddBlacklistReq{}
|
||||
// utils.CopyStructFields(req.CommID, params)
|
||||
// var ok bool
|
||||
// ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
// if !ok {
|
||||
// log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(params.OperationID, "AddBlacklist args ", req.String())
|
||||
|
||||
func GetUserInfo(c *gin.Context) {
|
||||
params := api.GetUserInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserInfoReq{}
|
||||
utils.CopyStructFields(&req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(params.OperationID, "GetUserInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.GetUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
resp.UserInfoList = RpcResp.UserInfoList
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
}
|
||||
|
||||
func UpdateUserInfo(c *gin.Context) {
|
||||
log.InfoByKv("api update userinfo init...", "")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsStruct{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbUser.UpdateUserInfoReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
Name: params.Name,
|
||||
Icon: params.Icon,
|
||||
Gender: params.Gender,
|
||||
Mobile: params.Mobile,
|
||||
Birth: params.Birth,
|
||||
Email: params.Email,
|
||||
Ex: params.Ex,
|
||||
Uid: params.Uid,
|
||||
}
|
||||
log.InfoByKv("api update user info is server", req.OperationID, req.Token)
|
||||
RpcResp, err := client.UpdateUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call update user info rpc server success", params.OperationID)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
log.InfoByKv("api update user info return success", params.OperationID, "args=%s", RpcResp.String())
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserRegister args ", req.String())
|
||||
var user imdb.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
err := imdb.UserRegister(user)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err.Error(), user)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserRegister return")
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
||||
|
||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, req.Platform)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CreateToken failed ", err.Error(), req.FromUserID, req.Platform)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserToken return ")
|
||||
return &pbAuth.UserTokenResp{Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
|
||||
type rpcAuth struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log.NewInfo("0", "rpc auth start...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(),
|
||||
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc auth ok")
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"Open_IM/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type rpcAuth struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log.Info("", "", "rpc get_token init...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.Error("", "", "register rpc get_token to etcd failed, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.Info("", "", "rpc get_token fail, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc get_token init success")
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, pb *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.Info("", "", "rpc user_register start, [data: %s]", pb.String())
|
||||
|
||||
if err := im_mysql_model.UserRegister(pb); err != nil {
|
||||
log.Error("", "", "rpc user_register error, [data: %s] [err: %s]", pb.String(), err.Error())
|
||||
return &pbAuth.UserRegisterResp{Success: false}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_register success return")
|
||||
|
||||
return &pbAuth.UserRegisterResp{Success: true}, nil
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, pb *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.Info("", "", "rpc user_token call start..., [pbTokenReq: %s]", pb.String())
|
||||
|
||||
_, err := im_mysql_model.FindUserByUID(pb.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID")
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(pb.UID, pb.Platform)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., utils.CreateToken fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token success return, [uid: %s] [tokens: %s]", pb.UID, tokens)
|
||||
|
||||
return &pbAuth.UserTokenResp{Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
|
||||
m := make(map[string]int, len(req.ConversationId))
|
||||
for _, v := range req.ConversationId {
|
||||
m[v] = int(req.Opt)
|
||||
}
|
||||
err := db.DB.SetMultiConversationMsgOpt(req.UId, m)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.SetReceiveMessageOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.SetReceiveMessageOptResp
|
||||
resp.ErrCode = 0
|
||||
|
||||
for _, v := range req.ConversationId {
|
||||
resp.OptResult = append(resp.OptResult, &pbUser.OptResult{ConversationId: v, Result: 0})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt req, resp ", req, resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
|
||||
m, err := db.DB.GetMultiConversationMsgOpt(req.UId, req.ConversationId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.GetReceiveMessageOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.GetReceiveMessageOptResp
|
||||
resp.ErrCode = 0
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResult = append(resp.ConversationOptResult, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt, req, resp", req, resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
|
||||
m, err := db.DB.GetAllConversationMsgOpt(req.UId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.GetAllConversationMsgOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.GetAllConversationMsgOptResp
|
||||
resp.ErrCode = 0
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResult = append(resp.ConversationOptResult, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt, req, resp", req, resp)
|
||||
return &resp, nil
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.Info("", "", "rpc user init....")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbUser.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc token to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen token failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc token init success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.InfoByKv("rpc get_user_info is server", req.OperationID)
|
||||
|
||||
var userInfoList []*pbUser.UserInfo
|
||||
//Obtain user information according to userID
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo pbUser.UserInfo
|
||||
user, err := im_mysql_model.FindUserByUID(userID)
|
||||
if err != nil {
|
||||
log.ErrorByKv("search userinfo failed", req.OperationID, "userID", userID, "err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&userInfo, user)
|
||||
userInfoList = append(userInfoList, &userInfo)
|
||||
}
|
||||
} else {
|
||||
return &pbUser.GetUserInfoResp{ErrorCode: 999, ErrorMsg: "uidList is nil"}, nil
|
||||
}
|
||||
log.InfoByKv("rpc get userInfo return success", req.OperationID, "token", req.Token)
|
||||
return &pbUser.GetUserInfoResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: userInfoList,
|
||||
}, nil
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package internal_service
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserInfoClient(req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
return RpcResp, err
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
** description("").
|
||||
** copyright('open-im,www.open-im.io').
|
||||
** author("fg,Gordon@tuoyun.net").
|
||||
** time(2021/9/15 10:28).
|
||||
*/
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String())
|
||||
var resp pbUser.DeleteUsersResp
|
||||
var common pbUser.CommonResp
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
for _, uid := range req.DeleteUidList {
|
||||
err = im_mysql_model.UserDelete(uid)
|
||||
if err != nil {
|
||||
common.ErrorCode = 201
|
||||
common.ErrorMsg = "some uid deleted failed"
|
||||
resp.FailedUidList = append(resp.FailedUidList, uid)
|
||||
}
|
||||
}
|
||||
resp.CommonResp = &common
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUsersUid(_ context.Context, req *pbUser.GetAllUsersUidReq) (*pbUser.GetAllUsersUidResp, error) {
|
||||
log.InfoByKv("rpc GetAllUsersUid arrived server", req.OperationID, "args", req.String())
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectAllUID()
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, UidList: uidList}, nil
|
||||
}
|
||||
|
||||
}
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.InfoByKv("rpc AccountCheck arrived server", req.OperationID, "args", req.String())
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectSomeUID(req.UidList)
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get SelectSomeUID failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
var r []*pbUser.AccountCheckResp_SingleUserStatus
|
||||
for _, v := range req.UidList {
|
||||
temp := new(pbUser.AccountCheckResp_SingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp.AccountStatus = constant.Registered
|
||||
} else {
|
||||
temp.AccountStatus = constant.UnRegistered
|
||||
}
|
||||
r = append(r, temp)
|
||||
}
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, Result: r}, nil
|
||||
}
|
||||
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/logic"
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc modify user is server,args=%s", req.String())
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
|
||||
}
|
||||
|
||||
ownerUid := ""
|
||||
//if claims.UID == config.Config.AppManagerUid {
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
ownerUid = req.Uid
|
||||
} else {
|
||||
ownerUid = claims.UID
|
||||
}
|
||||
|
||||
err = im_mysql_model.UpDateUserInfo(ownerUid, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: constant.ErrModifyUserInfo.ErrCode, ErrorMsg: constant.ErrModifyUserInfo.ErrMsg}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
if RpcResp.ErrCode != 0 {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
self, err := im_mysql_model.FindUserByUID(ownerUid)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
var name, faceUrl string
|
||||
if self != nil {
|
||||
name, faceUrl = self.Name, self.Icon
|
||||
}
|
||||
|
||||
chat.SelfInfoUpdatedNotification(req.OperationID, req.Uid)
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: ownerUid,
|
||||
RecvID: v.Uid,
|
||||
SenderNickName: name,
|
||||
SenderFaceURL: faceUrl,
|
||||
Content: ownerUid + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
})
|
||||
|
||||
}
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
@ -0,0 +1,238 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"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/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.NewInfo("0", "", "rpc user start...")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, address ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbUser.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(), s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||
var userInfoList []*sdkws.UserInfo
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo sdkws.UserInfo
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), userID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&userInfo, user)
|
||||
userInfoList = append(userInfoList, &userInfo)
|
||||
}
|
||||
} else {
|
||||
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetUserInfo rpc return ", pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList:userInfoList})
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList:userInfoList}, nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String())
|
||||
m := make(map[string]int, len(req.ConversationIDList))
|
||||
for _, v := range req.ConversationIDList {
|
||||
m[v] = int(req.Opt)
|
||||
}
|
||||
err := db.DB.SetMultiConversationMsgOpt(req.FromUserID, m)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
|
||||
for _, v := range req.ConversationIDList {
|
||||
resp.OptResultList = append(resp.OptResultList, &pbUser.OptResult{ConversationId: v, Result: 0})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt args ", req.String())
|
||||
m, err := db.DB.GetMultiConversationMsgOpt(req.FromUserID, req.ConversationId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req.FromUserID, req.ConversationId)
|
||||
return &pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt args ", req.String())
|
||||
m, err := db.DB.GetAllConversationMsgOpt(req.FromUserId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req.FromUserId)
|
||||
return &pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, FailedUserIDList: req.DeleteUserIDList}, nil
|
||||
}
|
||||
var common pbUser.CommonResp
|
||||
resp := pbUser.DeleteUsersResp{CommonResp: &common}
|
||||
for _, userID := range req.DeleteUserIDList {
|
||||
err := imdb.DeleteUser(userID)
|
||||
if err != nil {
|
||||
common.ErrCode = 201
|
||||
common.ErrMsg = "some uid deleted failed"
|
||||
resp.FailedUserIDList = append(resp.FailedUserIDList, userID)
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, "DeleteUsers rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
|
||||
log.NewInfo(req.OperationID,"GetAllUserID args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectAllUserID()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectAllUserID false ", err.Error())
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
} else {
|
||||
log.NewInfo(req.OperationID, "GetAllUserID rpc return ", pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList})
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.NewInfo(req.OperationID,"AccountCheck args ", req.String())
|
||||
if token_verify.IsMangerUserID(req.OpUserID){
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectSomeUserID(req.CheckUserIDList)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectSomeUserID failed ", err.Error(), req.CheckUserIDList)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
} else {
|
||||
var r []*pbUser.AccountCheckResp_SingleUserStatus
|
||||
for _, v := range req.CheckUserIDList {
|
||||
temp := new(pbUser.AccountCheckResp_SingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp.AccountStatus = constant.Registered
|
||||
} else {
|
||||
temp.AccountStatus = constant.UnRegistered
|
||||
}
|
||||
r = append(r, temp)
|
||||
}
|
||||
resp := pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: 0, ErrMsg: ""}, ResultList: r}
|
||||
log.NewInfo(req.OperationID, "AccountCheck rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.UpdateUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID,"UpdateUserInfo args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.UserInfo.UserID){
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserInfo.UserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
var user imdb.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
err := imdb.UpdateUserInfo(user)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID}
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
for _, v := range RpcResp.FriendInfoList{
|
||||
chat.FriendInfoChangedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
}
|
||||
chat.SelfInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package base_info
|
||||
|
||||
import (
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
type GetUsersOnlineStatusReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=200"`
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
}
|
||||
type OnlineStatus struct {
|
||||
UserID string `json:"userID"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
type GetUsersOnlineStatusResp struct {
|
||||
CommResp
|
||||
OnlineStatusList []*OnlineStatus `json:"data"`
|
||||
}
|
||||
|
||||
type GetUserInfoReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserInfoResp struct {
|
||||
CommResp
|
||||
UserInfoList []*open_im_sdk.UserInfo `json:"data"`
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue