Commit 2e1b7f2f by 李洪

删除验证

parent 41583da8
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: u-proto/common.proto
package pb
import (
fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/golang/protobuf/proto"
_ "github.com/mwitkow/go-proto-validators"
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
func (this *Common) Validate() error {
if this.Appkey == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Appkey", fmt.Errorf(`value '%v' must not be an empty string`, this.Appkey))
}
if this.Nonce == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Nonce", fmt.Errorf(`value '%v' must not be an empty string`, this.Nonce))
}
if this.Curtime == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Curtime", fmt.Errorf(`value '%v' must not be an empty string`, this.Curtime))
}
if this.Checksum == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Checksum", fmt.Errorf(`value '%v' must not be an empty string`, this.Checksum))
}
return nil
}
func (this *Page) Validate() error {
return nil
}
......@@ -5,10 +5,10 @@ package pb
import (
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
_ "github.com/mwitkow/go-proto-validators"
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
......@@ -17,11 +17,6 @@ var _ = fmt.Errorf
var _ = math.Inf
func (this *RoomUserAddOpeRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
if !(this.RoomId > 0) {
return github_com_mwitkow_go_proto_validators.FieldError("RoomId", fmt.Errorf(`value '%v' must be greater than '0'`, this.RoomId))
}
......@@ -31,11 +26,6 @@ func (this *RoomUserAddOpeRequest) Validate() error {
return nil
}
func (this *RoomUserAddRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
if !(this.RoomId > 0) {
return github_com_mwitkow_go_proto_validators.FieldError("RoomId", fmt.Errorf(`value '%v' must be greater than '0'`, this.RoomId))
}
......@@ -45,11 +35,6 @@ func (this *RoomUserAddRequest) Validate() error {
return nil
}
func (this *RoomUserSetRoleRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
if !(this.RoomId > 0) {
return github_com_mwitkow_go_proto_validators.FieldError("RoomId", fmt.Errorf(`value '%v' must be greater than '0'`, this.RoomId))
}
......@@ -71,11 +56,6 @@ func (this *RoomUserReply) Validate() error {
return nil
}
func (this *RoomUserOneRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
if !(this.RoomId > 0) {
return github_com_mwitkow_go_proto_validators.FieldError("RoomId", fmt.Errorf(`value '%v' must be greater than '0'`, this.RoomId))
}
......@@ -88,11 +68,6 @@ func (this *RoomUserOneReply) Validate() error {
return nil
}
func (this *RoomUserListRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
return nil
}
func (this *RoomUserListReply) Validate() error {
......
......@@ -5,10 +5,10 @@ package pb
import (
fmt "fmt"
math "math"
proto "github.com/golang/protobuf/proto"
_ "github.com/mwitkow/go-proto-validators"
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
......@@ -17,10 +17,8 @@ var _ = fmt.Errorf
var _ = math.Inf
func (this *ImUserRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
if this.Appkey == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Appkey", fmt.Errorf(`value '%v' must not be an empty string`, this.Appkey))
}
if this.Accid == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Accid", fmt.Errorf(`value '%v' must not be an empty string`, this.Accid))
......@@ -30,25 +28,9 @@ func (this *ImUserRequest) Validate() error {
func (this *ImUserRegReply) Validate() error {
return nil
}
func (this *ImUserLoginRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
if this.Accid == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Accid", fmt.Errorf(`value '%v' must not be an empty string`, this.Accid))
}
if this.Platform == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Platform", fmt.Errorf(`value '%v' must not be an empty string`, this.Platform))
}
return nil
}
func (this *ImUserSetRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
if this.Appkey == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Appkey", fmt.Errorf(`value '%v' must not be an empty string`, this.Appkey))
}
if this.Accid == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Accid", fmt.Errorf(`value '%v' must not be an empty string`, this.Accid))
......@@ -59,10 +41,8 @@ func (this *ImUserSetReply) Validate() error {
return nil
}
func (this *ImUserOneRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
if this.Appkey == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Appkey", fmt.Errorf(`value '%v' must not be an empty string`, this.Appkey))
}
if this.Accid == "" {
return github_com_mwitkow_go_proto_validators.FieldError("Accid", fmt.Errorf(`value '%v' must not be an empty string`, this.Accid))
......@@ -73,11 +53,6 @@ func (this *ImUserOneReply) Validate() error {
return nil
}
func (this *ImUserListRequest) Validate() error {
if this.Common != nil {
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Common); err != nil {
return github_com_mwitkow_go_proto_validators.FieldError("Common", err)
}
}
return nil
}
func (this *ImUserListReply) Validate() error {
......
......@@ -14,23 +14,6 @@ type ImUserServer struct {
pb.UnimplementedImUserServer
}
type ImUser struct {
Name string
Mobile string
Code string
Platform string
}
type ImUserSet struct {
Accid string
Mute bool
}
type ImUserQ struct {
Accid string
Platform string
}
//注册
func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest) (reply *pb.ImUserRegReply, err error) {
// 请求超时
......@@ -39,7 +22,7 @@ func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest)
return
}
// 是否已经注册过, 如果已经注册返回用户信息
if c_user, _ := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey); c_user.Accid != "" {
if c_user, _ := GetImUserByAccidAppkey(in.Accid, in.Appkey); c_user.Accid != "" {
err = status.Error(10438, "用户已存在")
return
}
......@@ -57,14 +40,14 @@ func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest)
}
//修改用户信息
func (u *ImUserServer) ImuserSave(ctx context.Context, in *pb.ImUserRequest) (reply *pb.ImUserSetReply, err error) {
func (u *ImUserServer) ImUserSave(ctx context.Context, in *pb.ImUserRequest) (reply *pb.ImUserSetReply, err error) {
// 请求超时
if ctx.Err() == context.Canceled {
err = status.New(codes.Canceled, "Client cancelled, abandoning.").Err()
return
}
//查询用户是否存在
c_user, _ := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
c_user, _ := GetImUserByAccidAppkey(in.Accid, in.Appkey)
if c_user.Token == "" {
err = status.Error(404, "用户不存在")
return
......@@ -96,61 +79,16 @@ func (u *ImUserServer) ImuserSave(ctx context.Context, in *pb.ImUserRequest) (re
m["ex"] = in.Ex
}
if res, _ := UpdateImUser(in.GetAccid(), in.Common.Appkey, m); res != 1 {
if res, _ := UpdateImUser(in.Accid, in.Appkey, m); res != 1 {
err = status.Error(500, "修改用户信息失败")
return
}
reply = &pb.ImUserSetReply{}
reply.Code = 200
reply.Msg = "修改成功"
return
}
//用户登录
func (u *ImUserServer) ImUserLogin(ctx context.Context, in *pb.ImUserLoginRequest) (reply *pb.ImUserRegReply, err error) {
// 请求超时
if ctx.Err() == context.Canceled {
err = status.New(codes.Canceled, "Client cancelled, abandoning.").Err()
return
}
//获取用户信息
c_user, _ := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
if c_user.Token == "" {
err = status.Error(404, "用户不存在")
return
}
//用户登录处理
err = LoginHandle(in)
if err != nil {
//err = status.Error(500, "用户登录时间更新失败")
return
}
reply = &pb.ImUserRegReply{}
reply.Token = c_user.Token
reply.Accid = c_user.Accid
reply.Name = c_user.Name
return
}
//用户退出
func (u *ImUserServer) ImUserLoginOut(ctx context.Context, in *pb.ImUserLoginRequest) (reply *pb.ImUserSetReply, err error) {
// 请求超时
if ctx.Err() == context.Canceled {
err = status.New(codes.Canceled, "Client cancelled, abandoning.").Err()
return
}
c_user, _ := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
if c_user.Accid == "" {
err = status.Error(404, "用户不存在")
return
}
err = LoginOutHandle(in)
if err != nil {
return
}
reply = &pb.ImUserSetReply{}
return reply, nil
}
//用户禁言
func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSetRequest) (reply *pb.ImUserSetReply, err error) {
// 请求超时
......@@ -163,7 +101,7 @@ func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSe
mute = 1
}
//检测该用户
c_user, err := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
c_user, err := GetImUserByAccidAppkey(in.Accid, in.Appkey)
if err != nil {
err = status.Error(404, "该用户不存在")
return
......@@ -175,11 +113,13 @@ func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSe
m := make(map[string]interface{})
m["mute_estoppel"] = mute
if res, _ := UpdateImUser(in.GetAccid(), in.Common.Appkey, m); res != 1 {
if res, _ := UpdateImUser(in.Accid, in.Appkey, m); res != 1 {
err = status.Error(500, "用户禁言失败")
return
}
reply = &pb.ImUserSetReply{}
reply.Code = 200
reply.Msg = "设置成功"
return
}
......@@ -195,7 +135,7 @@ func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRe
mute = 1
}
//检测该用户
c_user, err := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
c_user, err := GetImUserByAccidAppkey(in.Accid, in.Appkey)
if err != nil {
err = status.Error(404, "该用户不存在")
return
......@@ -207,12 +147,14 @@ func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRe
m := make(map[string]interface{})
m["mute_audio_video"] = mute
if res, _ := UpdateImUser(in.GetAccid(), in.Common.Appkey, m); res != 1 {
if res, _ := UpdateImUser(in.Accid, in.Appkey, m); res != 1 {
err = status.Error(500, "用户禁音视频失败")
return
}
reply = &pb.ImUserSetReply{}
reply.Code = 200
reply.Msg = "设置成功"
return
}
......@@ -224,7 +166,7 @@ func (u *ImUserServer) ImUserOne(ctx context.Context, in *pb.ImUserOneRequest) (
return
}
reply = &pb.ImUserOneReply{}
c_user, err := GetImUserByAccidAppkey(in.GetAccid(), in.Common.Appkey)
c_user, err := GetImUserByAccidAppkey(in.Accid, in.Appkey)
if err != nil {
return
}
......
......@@ -59,7 +59,7 @@ func CreateImUser(in *pb.ImUserRequest) (db.ImUser, error) {
token := createToken()
var c_user db.ImUser
c_user.Accid = in.GetAccid()
c_user.Appkey = in.Common.Appkey
c_user.Appkey = in.Appkey
c_user.Name = in.GetName()
c_user.Icon = in.GetIcon()
c_user.Token = token
......
package im_user
import (
"im-microservice/pb"
//"fmt"
//"errors"
"bytes"
"encoding/json"
"im-microservice/helper"
//"im-microservice/pb"
//"github.com/astaxie/beego/orm"
"google.golang.org/grpc/status"
)
//用户登录处理
func LoginHandle(in *pb.ImUserLoginRequest) error {
loginMap := make(map[int]map[string]interface{})
loginOne := map[string]interface{}{
"platform": in.Platform,
"Updatetime": helper.GetNowTime(),
}
num := 1
//查询该设备平台是否已经存在数据
var buffer bytes.Buffer
buffer.WriteString(in.Accid)
buffer.WriteString("_")
buffer.WriteString(in.Common.Appkey)
fieldKey := buffer.String()
jsonStr, err := helper.GetRedis(fieldKey)
if err == nil {
//不是第一次登录了
json.Unmarshal([]byte(jsonStr), &loginMap)
for _, m := range loginMap {
if m["platform"] == in.Platform {
err = status.Error(417, "该种设备已经登录了")
return err
}
num += 1
}
}
loginMap[num] = loginOne
loginJson, _ := json.Marshal(loginMap)
err = helper.SetRedis(fieldKey, string(loginJson))
if err != nil {
return err
}
return nil
}
//用户退出处理
func LoginOutHandle(in *pb.ImUserLoginRequest) error {
loginMap := make(map[int]map[string]interface{})
var buffer bytes.Buffer
buffer.WriteString(in.Accid)
buffer.WriteString("_")
buffer.WriteString(in.Common.Appkey)
fieldKey := buffer.String()
jsonStr, err := helper.GetRedis(fieldKey)
if jsonStr == "" {
err = status.Error(404, "没有登录信息")
return err
}
json.Unmarshal([]byte(jsonStr), &loginMap)
var num int
n := 0
for k, m := range loginMap {
if m["platform"] == in.Platform {
num = k
}
n += 1
}
if n == 1 {
err = helper.DelRedis(fieldKey)
return err
}
delete(loginMap, num)
loginJson, _ := json.Marshal(loginMap)
err = helper.SetRedis(fieldKey, string(loginJson))
if err != nil {
return err
}
return nil
}
// //用户登录处理
// func LoginHandle(in *pb.ImUserLoginRequest) (db.ImUserLogin, error) {
// //查询该设备平台是否已经存在数据
// var buffer bytes.Buffer
// buffer.WriteString(in.Accid)
// buffer.WriteString("_")
// buffer.WriteString(in.Common.Appkey)
// log_user, err := helper.GetRedis(buffer.String())
// if err != nil {
// //插入数据
// log_user.LoginStatus = 1
// log_user.Platform = platform
// log_user.Updatetime = helper.GetNowTime()
// log_user.UserId = user_id
// _, err := db.MysqlClient.Insert(&log_user)
// if err != nil {
// return log_user, err
// }
// } else {
// //修改数据
// if err := UpdateLogin(user_id, platform, 1); err != nil {
// return log_user, err
// }
// log_user.LoginStatus = 1
// }
// return log_user, nil
// }
// //用户退出
// func LoginOutHandle(user_id int64, platform string) (db.ImUserLogin, error) {
// //查询登录信息
// log_user, err := GetLogin(user_id, platform)
// if err != nil {
// err = status.Error(500, "用户还没有登录信息")
// return log_user, err
// }
// //修改
// if err := UpdateLogin(user_id, platform, 0); err != nil {
// return log_user, err
// }
// return log_user, nil
// }
// //查询
// func GetLogin(user_id int64, platform string) (db.ImUserLogin, error) {
// var log_user db.ImUserLogin
// err := db.MysqlClient.QueryTable(ul_table_name).Filter(ul_user_id, user_id).Filter(ul_platform, platform).One(&log_user)
// if err != nil {
// return log_user, err
// }
// return log_user, nil
// }
// //修改
// func UpdateLogin(user_id int64, platform string, login_status int64) error {
// orm_params := make(orm.Params)
// orm_params[ul_login_status] = login_status
// orm_params[ul_updatetime] = helper.GetNowTime()
// _, err := db.MysqlClient.QueryTable(ul_table_name).Filter(ul_user_id, user_id).Filter(ul_platform, platform).Update(orm_params)
// if err != nil {
// err = status.Error(500, err.Error())
// return err
// }
// return err
// }
......@@ -7,25 +7,22 @@ import "github.com/mwitkow/go-proto-validators/validator.proto";
//添加操作者(创建者)
message RoomUserAddOpeRequest {
Common Common = 1;
int64 RoomId = 2[(validator.field) = {int_gt: 0}];
string Operator = 3[(validator.field) = {string_not_empty: true}];
int64 RoomId = 1[(validator.field) = {int_gt: 0}];
string Operator = 2[(validator.field) = {string_not_empty: true}];
}
//添加用户
message RoomUserAddRequest{
Common Common = 1;
int64 RoomId = 2[(validator.field) = {int_gt: 0}];
string Accid = 4[(validator.field) = {string_not_empty: true}];
int64 RoomId = 1[(validator.field) = {int_gt: 0}];
string Accid = 2[(validator.field) = {string_not_empty: true}];
}
//设置权限
message RoomUserSetRoleRequest {
Common Common = 1;
int64 RoomId = 2[(validator.field) = {int_gt: 0}];
string Operator = 3[(validator.field) = {string_not_empty: true}];
string Accid = 4[(validator.field) = {string_not_empty: true}];
int64 Role = 5[(validator.field) = {int_gt: 0, int_lt: 5}];
int64 RoomId = 1 [(validator.field) = {int_gt: 0}];
string Operator = 2[(validator.field) = {string_not_empty: true}];
string Accid = 3[(validator.field) = {string_not_empty: true}];
int64 Role = 4[(validator.field) = {int_gt: 0, int_lt: 5}];
}
......@@ -39,9 +36,8 @@ message RoomUserReply {
//获取房间单个用户属性
message RoomUserOneRequest {
Common Common = 1;
int64 RoomId = 2[(validator.field) = {int_gt: 0}];
string Accid = 3[(validator.field) = {string_not_empty: true}];
int64 RoomId = 1[(validator.field) = {int_gt: 0}];
string Accid = 2[(validator.field) = {string_not_empty: true}];
}
//返回房间单个用户属性
message RoomUserOneReply {
......@@ -57,11 +53,10 @@ message RoomUserOneReply {
//获取房间用户列表
message RoomUserListRequest {
Common Common = 1;
int64 Page = 2;
int64 RoomId = 3;
int64 Role = 4;
string Accid = 5;
int64 Page = 1;
int64 RoomId = 2;
int64 Role = 3;
string Accid = 4;
}
//返回房间用户列表
message RoomUserListReply {
......
......@@ -3,12 +3,11 @@ syntax = "proto3";
package pb;
import "u-proto/common.proto";
import "u-proto/google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
//用户注册修改
message ImUserRequest {
Common Common = 1;
string Appkey = 1[(validator.field) = {string_not_empty: true}];
string Accid = 2[(validator.field) = {string_not_empty: true}];
string Name = 3;
string Icon = 4;
......@@ -25,30 +24,27 @@ message ImUserRequest {
message ImUserRegReply{
string Token = 1;
string Accid = 2;
string Name = 3;
string Appkey = 3;
string Name = 4;
}
//用户登录退出
message ImUserLoginRequest {
Common Common = 1;
string Accid = 2[(validator.field) = {string_not_empty: true}];
string Platform = 3[(validator.field) = {string_not_empty: true}];
}
//用户设置禁言,禁音视频
message ImUserSetRequest {
Common Common = 1;
string Appkey = 1[(validator.field) = {string_not_empty: true}];
bool Mute = 2;
string Accid = 3[(validator.field) = {string_not_empty: true}];
}
//修改返回
message ImUserSetReply {}
message ImUserSetReply {
int64 Code = 1;
string Msg = 2;
}
//获取单个用户信息
message ImUserOneRequest {
Common Common = 1;
string Appkey = 1[(validator.field) = {string_not_empty: true}];
string Accid = 2[(validator.field) = {string_not_empty: true}];
}
......@@ -72,7 +68,7 @@ message ImUserOneReply {
//获取用户列表
message ImUserListRequest {
Common Common = 1;
string Appkey = 1;
int64 Page = 2;
string Accid = 3;
string Mobile = 4;
......@@ -92,14 +88,7 @@ message ImUserListReply{
service ImUser {
rpc ImUserRegister (ImUserRequest) returns(ImUserRegReply) {}
rpc ImuserSave(ImUserRequest) returns(ImUserSetReply) {}
rpc ImUserLogin (ImUserLoginRequest) returns(ImUserRegReply) {
option (google.api.http) ={
post:"/api/v1/im_login",
body:"*"
};
}
rpc ImUserLoginOut (ImUserLoginRequest) returns(ImUserSetReply) {}
rpc ImUserSave(ImUserRequest) returns(ImUserSetReply) {}
rpc ImUserForbiddenWords (ImUserSetRequest) returns(ImUserSetReply) {}
rpc ImUserForbiddenAV (ImUserSetRequest) returns(ImUserSetReply) {}
rpc ImUserOne (ImUserOneRequest) returns(ImUserOneReply) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment