mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 11:22:10 +08:00 
			
		
		
		
	Merge remote-tracking branch 'upstream/tuoyun' into tuoyun
This commit is contained in:
		
						commit
						f22a07fb29
					
				@ -1 +1 @@
 | 
			
		||||
Subproject commit e43ec7d427a84702eea7a6aaa358a7a0a809019d
 | 
			
		||||
Subproject commit 23f31958dae08260c5f9631f4937389a8e2d6751
 | 
			
		||||
@ -21,6 +21,7 @@ func main() {
 | 
			
		||||
		authRouterGroup.POST("/verify", register.Verify)
 | 
			
		||||
		authRouterGroup.POST("/password", register.SetPassword)
 | 
			
		||||
		authRouterGroup.POST("/login", register.Login)
 | 
			
		||||
		authRouterGroup.POST("/reset_password", register.ResetPassword)
 | 
			
		||||
	}
 | 
			
		||||
	log.NewPrivateLog("demo")
 | 
			
		||||
	ginPort := flag.Int("port", 42233, "get ginServerPort from cmd,default 42233 as port")
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										69
									
								
								cmd/test/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								cmd/test/main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,69 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"go.mongodb.org/mongo-driver/bson"
 | 
			
		||||
	"go.mongodb.org/mongo-driver/mongo"
 | 
			
		||||
	"go.mongodb.org/mongo-driver/mongo/options"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type MongoMsg struct {
 | 
			
		||||
	UID string
 | 
			
		||||
	Msg []string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func main()  {
 | 
			
		||||
	//"mongodb://%s:%s@%s/%s/?maxPoolSize=%d"
 | 
			
		||||
	uri := "mongodb://user:pass@sample.host:27017/?maxPoolSize=20&w=majority"
 | 
			
		||||
	DBAddress := "127.0.0.1:37017"
 | 
			
		||||
	DBDatabase := "new-test-db"
 | 
			
		||||
	Collection := "new-test-collection"
 | 
			
		||||
	DBMaxPoolSize := 100
 | 
			
		||||
	uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
 | 
			
		||||
		DBAddress,DBDatabase,
 | 
			
		||||
		DBMaxPoolSize)
 | 
			
		||||
 | 
			
		||||
	mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	filter := bson.M{"uid":"my_uid"}
 | 
			
		||||
	ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
 | 
			
		||||
	for i:=0; i < 2; i++{
 | 
			
		||||
 | 
			
		||||
		if err = mongoClient.Database(DBDatabase).Collection(Collection).FindOneAndUpdate(ctx, filter,
 | 
			
		||||
			bson.M{"$push": bson.M{"msg": utils.Int32ToString(int32(i))}}).Err(); err != nil{
 | 
			
		||||
			fmt.Println("FindOneAndUpdate failed ", i, )
 | 
			
		||||
			var mmsg MongoMsg
 | 
			
		||||
			mmsg.UID = "my_uid"
 | 
			
		||||
			mmsg.Msg = append(mmsg.Msg, utils.Int32ToString(int32(i)))
 | 
			
		||||
			_, err := mongoClient.Database(DBDatabase).Collection(Collection).InsertOne(ctx, &mmsg)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Println("insertone failed ", err.Error(), i)
 | 
			
		||||
			} else{
 | 
			
		||||
				fmt.Println("insertone ok ", i)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
		}else {
 | 
			
		||||
			fmt.Println("FindOneAndUpdate ok ", i)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var mmsg MongoMsg
 | 
			
		||||
 | 
			
		||||
	if  err = mongoClient.Database(DBDatabase).Collection(Collection).FindOne(ctx, filter).Decode(&mmsg); err != nil {
 | 
			
		||||
		fmt.Println("findone failed ", err.Error())
 | 
			
		||||
	}else{
 | 
			
		||||
		fmt.Println("findone ok ", mmsg.UID)
 | 
			
		||||
		for i, v:=range mmsg.Msg{
 | 
			
		||||
			fmt.Println("find value: ", i, v)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
# The class cannot be named by Pascal or camel case.
 | 
			
		||||
# If it is not used, the corresponding structure will not be set,
 | 
			
		||||
# and it will not be read naturally.
 | 
			
		||||
serverversion: 1.0.3
 | 
			
		||||
serverversion: 2.0.0
 | 
			
		||||
#---------------Infrastructure configuration---------------------#
 | 
			
		||||
etcd:
 | 
			
		||||
  etcdSchema: openIM
 | 
			
		||||
@ -11,7 +11,7 @@ mysql:
 | 
			
		||||
  dbMysqlAddress: [ 127.0.0.1:13306 ]
 | 
			
		||||
  dbMysqlUserName: root
 | 
			
		||||
  dbMysqlPassword: openIM
 | 
			
		||||
  dbMysqlDatabaseName: openIM
 | 
			
		||||
  dbMysqlDatabaseName: openIM_v2
 | 
			
		||||
  dbTableName: eMsg
 | 
			
		||||
  dbMsgTableNum: 1
 | 
			
		||||
  dbMaxOpenConns: 20
 | 
			
		||||
@ -87,7 +87,12 @@ credential:
 | 
			
		||||
    bucket: echat-1302656840
 | 
			
		||||
    secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC
 | 
			
		||||
    secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe
 | 
			
		||||
 | 
			
		||||
  minio:
 | 
			
		||||
    bucket: openim
 | 
			
		||||
    location: us-east-1
 | 
			
		||||
    endpoint: http://127.0.0.1:9000
 | 
			
		||||
    accessKeyID: minioadmin
 | 
			
		||||
    secretAccessKey: minioadmin
 | 
			
		||||
 | 
			
		||||
rpcport:
 | 
			
		||||
  openImUserPort: [ 10100 ]
 | 
			
		||||
@ -454,17 +459,17 @@ demoswitch: true
 | 
			
		||||
demo:
 | 
			
		||||
  openImDemoPort: [ 42233 ]
 | 
			
		||||
  alismsverify:
 | 
			
		||||
    accessKeyId: LTAI5tJPkn4HuuePdiLdGqe71
 | 
			
		||||
    accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV1
 | 
			
		||||
    signName: OpenIM Corporation
 | 
			
		||||
    verificationCodeTemplateCode: SMS_2268101641
 | 
			
		||||
    accessKeyId: LTAI5tJPkn4HuuePdiLdGqe7
 | 
			
		||||
    accessKeySecret: 4n9OJ7ZCVN1U6KeHDAtOyNeVZcjOuV
 | 
			
		||||
    signName: 托云信息技术
 | 
			
		||||
    verificationCodeTemplateCode: SMS_226810164
 | 
			
		||||
  superCode: 666666
 | 
			
		||||
  #  second
 | 
			
		||||
  codeTTL: 60
 | 
			
		||||
  codeTTL: 300
 | 
			
		||||
  mail:
 | 
			
		||||
    title: "openIM"
 | 
			
		||||
    senderMail: "1765567899@qq.com"
 | 
			
		||||
    senderAuthorizationCode: "1gxyausfoevlzbfag"
 | 
			
		||||
    senderMail: "765567899@qq.com"
 | 
			
		||||
    senderAuthorizationCode: "gxyausfoevlzbfag"
 | 
			
		||||
    smtpAddr: "smtp.qq.com"
 | 
			
		||||
    smtpPort: 25
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -73,6 +73,8 @@ api:
 | 
			
		||||
  openImApiPort: [ 10000 ]
 | 
			
		||||
sdk:
 | 
			
		||||
  openImSdkWsPort: [ 30000 ]
 | 
			
		||||
cmsapi:
 | 
			
		||||
  openImCmsApiPort: [ 8000 ]
 | 
			
		||||
 | 
			
		||||
credential:
 | 
			
		||||
  tencent:
 | 
			
		||||
@ -91,7 +93,9 @@ rpcport:
 | 
			
		||||
  openImGroupPort: [ 10500  ]
 | 
			
		||||
  openImAuthPort: [ 10600 ]
 | 
			
		||||
  openImPushPort: [ 10700 ]
 | 
			
		||||
 | 
			
		||||
  openImStatisticsPort: [ 10800 ]
 | 
			
		||||
  openImMessageCmsPort: [ 10900 ]
 | 
			
		||||
  openImAdminCmsPort: [ 11000 ]
 | 
			
		||||
 | 
			
		||||
rpcregistername:
 | 
			
		||||
  openImUserName: User
 | 
			
		||||
 | 
			
		||||
@ -89,7 +89,7 @@ services:
 | 
			
		||||
    command: /usr/local/bin/etcd --name etcd0 --data-dir /etcd-data --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-advertise-peer-urls http://0.0.0.0:2380 --initial-cluster etcd0=http://0.0.0.0:2380 --initial-cluster-token tkn --initial-cluster-state new
 | 
			
		||||
 | 
			
		||||
  open_im_server:
 | 
			
		||||
    image: openim/open_im_server
 | 
			
		||||
    image: openim/open_im_server:v2.0.0
 | 
			
		||||
    container_name: open_im_server
 | 
			
		||||
    volumes:
 | 
			
		||||
      - ./logs:/Open-IM-Server/logs
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							@ -45,6 +45,7 @@ require (
 | 
			
		||||
	github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca
 | 
			
		||||
	github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
 | 
			
		||||
	go.etcd.io/etcd v0.0.0-20200402134248-51bdeb39e698
 | 
			
		||||
	go.mongodb.org/mongo-driver v1.8.3
 | 
			
		||||
	golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
 | 
			
		||||
	golang.org/x/net v0.0.0-20210917221730-978cfadd31cf
 | 
			
		||||
	google.golang.org/grpc v1.40.0
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								go.sum
									
									
									
									
									
								
							@ -156,6 +156,7 @@ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn
 | 
			
		||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
			
		||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
 | 
			
		||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 | 
			
		||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
 | 
			
		||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 | 
			
		||||
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
			
		||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
 | 
			
		||||
@ -200,6 +201,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
 | 
			
		||||
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
 | 
			
		||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
 | 
			
		||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 | 
			
		||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 | 
			
		||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 | 
			
		||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
 | 
			
		||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 | 
			
		||||
@ -312,7 +314,10 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
 | 
			
		||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
 | 
			
		||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 | 
			
		||||
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
 | 
			
		||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
 | 
			
		||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
 | 
			
		||||
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
 | 
			
		||||
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
 | 
			
		||||
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
 | 
			
		||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 | 
			
		||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
 | 
			
		||||
@ -358,6 +363,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j
 | 
			
		||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 | 
			
		||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
 | 
			
		||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
 | 
			
		||||
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
 | 
			
		||||
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
 | 
			
		||||
github.com/minio/minio-go/v7 v7.0.22 h1:iXhsiRyYh1ozm/+jN2qGgEIahYjEkvcpuu6NcdpSxcA=
 | 
			
		||||
github.com/minio/minio-go/v7 v7.0.22/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2DAn1ou4+Do=
 | 
			
		||||
@ -377,6 +383,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
 | 
			
		||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 | 
			
		||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
 | 
			
		||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
 | 
			
		||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
 | 
			
		||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
 | 
			
		||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
 | 
			
		||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
 | 
			
		||||
@ -421,6 +428,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
 | 
			
		||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 | 
			
		||||
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
 | 
			
		||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
 | 
			
		||||
github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc=
 | 
			
		||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
 | 
			
		||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 | 
			
		||||
github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE=
 | 
			
		||||
@ -463,6 +471,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
 | 
			
		||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 | 
			
		||||
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca h1:G/aIr3WiUesWHL2YGYgEqjM5tCAJ43Ml+0C18wDkWWs=
 | 
			
		||||
github.com/tencentyun/qcloud-cos-sts-sdk v0.0.0-20210325043845-84a0811633ca/go.mod h1:b18KQa4IxHbxeseW1GcZox53d7J0z39VNONTxvvlkXw=
 | 
			
		||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
 | 
			
		||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 | 
			
		||||
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
 | 
			
		||||
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
 | 
			
		||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 | 
			
		||||
@ -473,8 +483,16 @@ github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVM
 | 
			
		||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
 | 
			
		||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
 | 
			
		||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
 | 
			
		||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
 | 
			
		||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
 | 
			
		||||
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
 | 
			
		||||
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
 | 
			
		||||
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
 | 
			
		||||
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
 | 
			
		||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
 | 
			
		||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
 | 
			
		||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
 | 
			
		||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
 | 
			
		||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 | 
			
		||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 | 
			
		||||
github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 | 
			
		||||
@ -488,6 +506,8 @@ go.etcd.io/etcd v0.0.0-20200402134248-51bdeb39e698/go.mod h1:YoUyTScD3Vcv2RBm3eG
 | 
			
		||||
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
 | 
			
		||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
 | 
			
		||||
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
 | 
			
		||||
go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R4=
 | 
			
		||||
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
 | 
			
		||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
 | 
			
		||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
 | 
			
		||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
 | 
			
		||||
@ -624,6 +644,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
 | 
			
		||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
 | 
			
		||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
			
		||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
			
		||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
			
		||||
@ -712,6 +733,7 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3
 | 
			
		||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 | 
			
		||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										47
									
								
								internal/api/third/minio_init.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								internal/api/third/minio_init.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,47 @@
 | 
			
		||||
package apiThird
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"Open_IM/pkg/common/config"
 | 
			
		||||
	"Open_IM/pkg/common/log"
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/minio/minio-go/v7"
 | 
			
		||||
	"github.com/minio/minio-go/v7/pkg/credentials"
 | 
			
		||||
	url2 "net/url"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	minioUrl, err := url2.Parse(config.Config.Credential.Minio.Endpoint)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("", utils.GetSelfFuncName(), "parse failed, please check config/config.yaml", err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	minioClient, err := minio.New(minioUrl.Host, &minio.Options{
 | 
			
		||||
		Creds:  credentials.NewStaticV4(config.Config.Credential.Minio.AccessKeyID, config.Config.Credential.Minio.SecretAccessKey, ""),
 | 
			
		||||
		Secure: false,
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("", utils.GetSelfFuncName(), "init minio client failed", err.Error())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	opt := minio.MakeBucketOptions{
 | 
			
		||||
		Region:        config.Config.Credential.Minio.Location,
 | 
			
		||||
		ObjectLocking: false,
 | 
			
		||||
	}
 | 
			
		||||
	err = minioClient.MakeBucket(context.Background(), config.Config.Credential.Minio.Bucket, opt)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		exists, err := minioClient.BucketExists(context.Background(), config.Config.Credential.Minio.Bucket)
 | 
			
		||||
		if err == nil && exists {
 | 
			
		||||
			log.NewInfo("", utils.GetSelfFuncName(), "We already own %s\n", config.Config.Credential.Minio.Bucket)
 | 
			
		||||
		} else {
 | 
			
		||||
			log.NewError("", utils.GetSelfFuncName(), "create bucket failed and bucket not exists", err.Error())
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	//err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
 | 
			
		||||
	//if err != nil {
 | 
			
		||||
	//	log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in 	", err.Error())
 | 
			
		||||
	//	return
 | 
			
		||||
	//}
 | 
			
		||||
	log.NewInfo("", utils.GetSelfFuncName(), "minio create and set policy success")
 | 
			
		||||
}
 | 
			
		||||
@ -2,13 +2,16 @@ package apiThird
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	apiStruct "Open_IM/pkg/base_info"
 | 
			
		||||
	"Open_IM/pkg/common/config"
 | 
			
		||||
	"Open_IM/pkg/common/constant"
 | 
			
		||||
	http "Open_IM/pkg/common/http"
 | 
			
		||||
	"Open_IM/pkg/common/log"
 | 
			
		||||
	"Open_IM/pkg/common/token_verify"
 | 
			
		||||
	_ "Open_IM/pkg/common/token_verify"
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	_ "github.com/minio/minio-go/v7/pkg/credentials"
 | 
			
		||||
	_ "github.com/minio/minio-go/v7"
 | 
			
		||||
	cr "github.com/minio/minio-go/v7/pkg/credentials"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func MinioStorageCredential(c *gin.Context) {
 | 
			
		||||
@ -16,15 +19,42 @@ func MinioStorageCredential(c *gin.Context) {
 | 
			
		||||
		req  apiStruct.MinioStorageCredentialReq
 | 
			
		||||
		resp apiStruct.MiniostorageCredentialResp
 | 
			
		||||
	)
 | 
			
		||||
	ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
 | 
			
		||||
	if !ok {
 | 
			
		||||
		log.NewError("", "GetUserIDFromToken false ", c.Request.Header.Get("token"))
 | 
			
		||||
		http.RespHttp200(c, constant.ErrAccess, nil)
 | 
			
		||||
	if err := c.BindJSON(&req); err != nil {
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	//var stsOpts cr.STSAssumeRoleOptions
 | 
			
		||||
	//stsOpts.AccessKey = minioUsername
 | 
			
		||||
	//stsOpts.SecretKey = minioPassword
 | 
			
		||||
	log.NewInfo("0", req, resp)
 | 
			
		||||
	http.RespHttp200(c, constant.OK, nil)
 | 
			
		||||
	//ok, _ := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
 | 
			
		||||
	//if !ok {
 | 
			
		||||
	//	log.NewError("", utils.GetSelfFuncName(), "GetUserIDFromToken false ", c.Request.Header.Get("token"))
 | 
			
		||||
	//	c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
 | 
			
		||||
	//	return
 | 
			
		||||
	//}
 | 
			
		||||
	var stsOpts cr.STSAssumeRoleOptions
 | 
			
		||||
	stsOpts.AccessKey = config.Config.Credential.Minio.AccessKeyID
 | 
			
		||||
	stsOpts.SecretKey = config.Config.Credential.Minio.SecretAccessKey
 | 
			
		||||
	stsOpts.DurationSeconds = constant.MinioDurationTimes
 | 
			
		||||
	li, err := cr.NewSTSAssumeRole(config.Config.Credential.Minio.Endpoint, stsOpts)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("", utils.GetSelfFuncName(), "NewSTSAssumeRole failed", err.Error(), stsOpts, config.Config.Credential.Minio.Endpoint)
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	v, err := li.Get()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), "li.Get error", err.Error())
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	resp.SessionToken = v.SessionToken
 | 
			
		||||
	resp.SecretAccessKey = v.SecretAccessKey
 | 
			
		||||
	resp.AccessKeyID = v.AccessKeyID
 | 
			
		||||
	resp.BucketName = config.Config.Credential.Minio.Bucket
 | 
			
		||||
	resp.StsEndpointURL = config.Config.Credential.Minio.Endpoint
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -32,8 +32,8 @@ func GetMessagesStatistics(c *gin.Context) {
 | 
			
		||||
	client := pb.NewUserClient(etcdConn)
 | 
			
		||||
	respPb, err := client.GetMessageStatistics(context.Background(), &reqPb)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrServer, resp)
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetMessageStatistics failed", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, err, resp)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	// utils.CopyStructFields(&resp, respPb)
 | 
			
		||||
@ -77,8 +77,8 @@ func GetUserStatistics(c *gin.Context) {
 | 
			
		||||
	client := pb.NewUserClient(etcdConn)
 | 
			
		||||
	respPb, err := client.GetUserStatistics(context.Background(), &reqPb)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrServer, nil)
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), "GetUserStatistics failed", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, err, nil)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	// utils.CopyStructFields(&resp, respPb)
 | 
			
		||||
@ -132,7 +132,8 @@ func GetGroupStatistics(c *gin.Context) {
 | 
			
		||||
	client := pb.NewUserClient(etcdConn)
 | 
			
		||||
	respPb, err := client.GetGroupStatistics(context.Background(), &reqPb)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrServer, nil)
 | 
			
		||||
		log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, err, nil)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	// utils.CopyStructFields(&resp, respPb)
 | 
			
		||||
@ -179,7 +180,8 @@ func GetActiveUser(c *gin.Context) {
 | 
			
		||||
	client := pb.NewUserClient(etcdConn)
 | 
			
		||||
	respPb, err := client.GetActiveUser(context.Background(), &reqPb)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrServer, nil)
 | 
			
		||||
		log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "GetActiveUser failed ", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, err, nil)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	utils.CopyStructFields(&resp.ActiveUserList, respPb.Users)
 | 
			
		||||
@ -194,7 +196,7 @@ func GetActiveGroup(c *gin.Context) {
 | 
			
		||||
	)
 | 
			
		||||
	reqPb.StatisticsReq = &pb.StatisticsReq{}
 | 
			
		||||
	if err := c.ShouldBindQuery(&req); err != nil {
 | 
			
		||||
		log.NewError("0", "BindJSON failed ", err.Error())
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), "BindJSON failed ", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrArgs, nil)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@ -203,8 +205,8 @@ func GetActiveGroup(c *gin.Context) {
 | 
			
		||||
	client := pb.NewUserClient(etcdConn)
 | 
			
		||||
	respPb, err := client.GetActiveGroup(context.Background(), &reqPb)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("0", "BindJSON failed ", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, constant.ErrServer, nil)
 | 
			
		||||
		log.NewError("0", utils.GetSelfFuncName(), "GetActiveGroup failed ", err.Error())
 | 
			
		||||
		openIMHttp.RespHttp200(c, err, nil)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	for _, group := range respPb.Groups {
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,7 @@ func Login(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	if r.Password != params.Password {
 | 
			
		||||
		log.NewError(params.OperationID, "password err", params.Password, account, r.Password, r.Account)
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "Mobile phone number is not registered"})
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "password err"})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	url := fmt.Sprintf("http://%s:10000/auth/user_token", viper.GetString("endpoints.api"))
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										56
									
								
								internal/demo/register/reset_password.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								internal/demo/register/reset_password.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,56 @@
 | 
			
		||||
package register
 | 
			
		||||
 | 
			
		||||
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"
 | 
			
		||||
	"Open_IM/pkg/common/log"
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"net/http"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type resetPasswordRequest struct {
 | 
			
		||||
	VerificationCode string `json:"verificationCode"`
 | 
			
		||||
	Email            string `json:"email"`
 | 
			
		||||
	PhoneNumber      string `json:"phoneNumber"`
 | 
			
		||||
	NewPassword string `json:"newPassword"`
 | 
			
		||||
	OperationID string `json:"operationID"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ResetPassword(c *gin.Context) {
 | 
			
		||||
	var (
 | 
			
		||||
		req resetPasswordRequest
 | 
			
		||||
	)
 | 
			
		||||
	if err := c.BindJSON(&req); err != nil {
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var account string
 | 
			
		||||
	if req.Email != "" {
 | 
			
		||||
		account = req.Email
 | 
			
		||||
	} else {
 | 
			
		||||
		account = req.PhoneNumber
 | 
			
		||||
	}
 | 
			
		||||
	if req.VerificationCode != config.Config.Demo.SuperCode {
 | 
			
		||||
		accountKey := account + "_" + constant.VerificationCodeForResetSuffix
 | 
			
		||||
		v, err := db.DB.GetAccountCode(accountKey)
 | 
			
		||||
		if err != nil || v != req.VerificationCode {
 | 
			
		||||
			log.NewError(req.OperationID, "password Verification code error", account, req.VerificationCode, v)
 | 
			
		||||
			c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code error!"})
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	user, err := im_mysql_model.GetRegister(account)
 | 
			
		||||
	if err != nil || user.Account == "" {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "user not register!"})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if err := im_mysql_model.ResetPassword(account, req.NewPassword); err != nil {
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.ResetPasswordFailed, "errMsg": "reset password failed: "+err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "reset password success"})
 | 
			
		||||
}
 | 
			
		||||
@ -21,6 +21,7 @@ type paramsVerificationCode struct {
 | 
			
		||||
	Email       string `json:"email"`
 | 
			
		||||
	PhoneNumber string `json:"phoneNumber"`
 | 
			
		||||
	OperationID string `json:"operationID" binding:"required"`
 | 
			
		||||
	UsedFor     int `json:"usedFor"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SendVerificationCode(c *gin.Context) {
 | 
			
		||||
@ -36,25 +37,35 @@ func SendVerificationCode(c *gin.Context) {
 | 
			
		||||
	} else {
 | 
			
		||||
		account = params.PhoneNumber
 | 
			
		||||
	}
 | 
			
		||||
	_, err := im_mysql_model.GetRegister(account)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		log.NewError(params.OperationID, "The phone number has been registered", params)
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": ""})
 | 
			
		||||
		return
 | 
			
		||||
	var accountKey string
 | 
			
		||||
	if params.UsedFor == 0 {
 | 
			
		||||
		params.UsedFor = constant.VerificationCodeForRegister
 | 
			
		||||
	}
 | 
			
		||||
	ok, err := db.DB.JudgeAccountEXISTS(account)
 | 
			
		||||
	if ok || err != nil {
 | 
			
		||||
		log.NewError(params.OperationID, "The phone number has been registered", params)
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.RepeatSendCode, "errMsg": ""})
 | 
			
		||||
		return
 | 
			
		||||
	switch params.UsedFor {
 | 
			
		||||
	case constant.VerificationCodeForRegister:
 | 
			
		||||
		_, err := im_mysql_model.GetRegister(account)
 | 
			
		||||
		if err == nil {
 | 
			
		||||
			log.NewError(params.OperationID, "The phone number has been registered", params)
 | 
			
		||||
			c.JSON(http.StatusOK, gin.H{"errCode": constant.HasRegistered, "errMsg": "The phone number has been registered"})
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		ok, err := db.DB.JudgeAccountEXISTS(account)
 | 
			
		||||
		if ok || err != nil {
 | 
			
		||||
			log.NewError(params.OperationID, "The phone number has been registered", params)
 | 
			
		||||
			c.JSON(http.StatusOK, gin.H{"errCode": constant.RepeatSendCode, "errMsg": "The phone number has been registered"})
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		accountKey = account + "_" + constant.VerificationCodeForRegisterSuffix
 | 
			
		||||
 | 
			
		||||
	case constant.VerificationCodeForReset:
 | 
			
		||||
		accountKey = account + "_" + constant.VerificationCodeForResetSuffix
 | 
			
		||||
	}
 | 
			
		||||
	log.InfoByKv("begin sendSms", account)
 | 
			
		||||
	rand.Seed(time.Now().UnixNano())
 | 
			
		||||
	code := 100000 + rand.Intn(900000)
 | 
			
		||||
	log.NewInfo(params.OperationID, "begin store redis", account)
 | 
			
		||||
	err = db.DB.SetAccountCode(account, code, config.Config.Demo.CodeTTL)
 | 
			
		||||
	log.NewInfo(params.OperationID, params.UsedFor,"begin store redis", accountKey, code)
 | 
			
		||||
	err := db.DB.SetAccountCode(accountKey, code, config.Config.Demo.CodeTTL)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(params.OperationID, "set redis error", account, "err", err.Error())
 | 
			
		||||
		log.NewError(params.OperationID, "set redis error", accountKey, "err", err.Error())
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.SmsSendCodeErr, "errMsg": "Enter the superCode directly in the verification code box, SuperCode can be configured in config.xml"})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -8,11 +8,11 @@ import (
 | 
			
		||||
	"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
 | 
			
		||||
	http2 "Open_IM/pkg/common/http"
 | 
			
		||||
	"Open_IM/pkg/common/log"
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/garyburd/redigo/redis"
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
)
 | 
			
		||||
@ -30,6 +30,7 @@ type ParamsSetPassword struct {
 | 
			
		||||
func SetPassword(c *gin.Context) {
 | 
			
		||||
	params := ParamsSetPassword{}
 | 
			
		||||
	if err := c.BindJSON(¶ms); err != nil {
 | 
			
		||||
		log.NewError(params.OperationID, utils.GetSelfFuncName(), "bind json failed", err.Error())
 | 
			
		||||
		c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@ -40,7 +41,8 @@ func SetPassword(c *gin.Context) {
 | 
			
		||||
		account = params.PhoneNumber
 | 
			
		||||
	}
 | 
			
		||||
	if params.VerificationCode != config.Config.Demo.SuperCode {
 | 
			
		||||
		v, err := redis.String(db.DB.Exec("GET", account))
 | 
			
		||||
		accountKey := account + "_" + constant.VerificationCodeForRegisterSuffix
 | 
			
		||||
		v, err := db.DB.GetAccountCode(accountKey)
 | 
			
		||||
		if err != nil || v != params.VerificationCode {
 | 
			
		||||
			log.NewError(params.OperationID, "password Verification code error", account, params.VerificationCode)
 | 
			
		||||
			data := make(map[string]interface{})
 | 
			
		||||
@ -65,8 +67,11 @@ func SetPassword(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	err = json.Unmarshal(bMsg, &openIMRegisterResp)
 | 
			
		||||
	if err != nil || openIMRegisterResp.ErrCode != 0 {
 | 
			
		||||
		log.NewError(params.OperationID, "request openIM register error", account, "err", "")
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": ""})
 | 
			
		||||
		log.NewError(params.OperationID, "request openIM register error", account, "err", "resp: ", openIMRegisterResp.ErrCode)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		}
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	log.Info(params.OperationID, "begin store mysql", account, params.Password)
 | 
			
		||||
 | 
			
		||||
@ -15,6 +15,7 @@ type paramsCertification struct {
 | 
			
		||||
	PhoneNumber      string `json:"phoneNumber"`
 | 
			
		||||
	VerificationCode string `json:"verificationCode"`
 | 
			
		||||
	OperationID      string `json:"operationID" binding:"required"`
 | 
			
		||||
	UsedFor          int    `json:"usedFor"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Verify(c *gin.Context) {
 | 
			
		||||
@ -43,11 +44,21 @@ func Verify(c *gin.Context) {
 | 
			
		||||
	}
 | 
			
		||||
	log.NewInfo("0", " params.VerificationCode != config.Config.Demo.SuperCode", params.VerificationCode, config.Config.Demo)
 | 
			
		||||
	log.NewInfo(params.OperationID, "begin get form redis", account)
 | 
			
		||||
	if params.UsedFor == 0 {
 | 
			
		||||
		params.UsedFor = constant.VerificationCodeForRegister
 | 
			
		||||
	}
 | 
			
		||||
	var accountKey string
 | 
			
		||||
	switch params.UsedFor {
 | 
			
		||||
	case constant.VerificationCodeForRegister:
 | 
			
		||||
		accountKey = account + "_" + constant.VerificationCodeForRegisterSuffix
 | 
			
		||||
	case constant.VerificationCodeForReset:
 | 
			
		||||
		accountKey = account + "_" + constant.VerificationCodeForResetSuffix
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	code, err := db.DB.GetAccountCode(account)
 | 
			
		||||
	log.NewInfo(params.OperationID, "redis phone number and verificating Code", account, code)
 | 
			
		||||
	code, err := db.DB.GetAccountCode(accountKey)
 | 
			
		||||
	log.NewInfo(params.OperationID, "redis phone number and verificating Code", accountKey, code, params)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(params.OperationID, "Verification code expired", account, "err", err.Error())
 | 
			
		||||
		log.NewError(params.OperationID, "Verification code expired", accountKey, "err", err.Error())
 | 
			
		||||
		data := make(map[string]interface{})
 | 
			
		||||
		data["account"] = account
 | 
			
		||||
		c.JSON(http.StatusOK, gin.H{"errCode": constant.CodeInvalidOrExpired, "errMsg": "Verification code expired!", "data": data})
 | 
			
		||||
 | 
			
		||||
@ -19,4 +19,5 @@ func saveUserChat(uid string, msg *pbMsg.MsgDataToMQ) error {
 | 
			
		||||
	pbSaveData.MsgData = msg.MsgData
 | 
			
		||||
	log.NewInfo(msg.OperationID, "IncrUserSeq cost time", utils.GetCurrentTimestampByMill()-time)
 | 
			
		||||
	return db.DB.SaveUserChat(uid, pbSaveData.MsgData.SendTime, &pbSaveData)
 | 
			
		||||
//	return db.DB.SaveUserChatMongo2(uid, pbSaveData.MsgData.SendTime, &pbSaveData)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ func (mc *HistoryConsumerHandler) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) {
 | 
			
		||||
	log.InfoByKv("msg come mongo!!!", "", "msg", string(msg))
 | 
			
		||||
	log.NewInfo("msg come mongo!!!", "", "msg", string(msg))
 | 
			
		||||
	time := utils.GetCurrentTimestampByNano()
 | 
			
		||||
	msgFromMQ := pbMsg.MsgDataToMQ{}
 | 
			
		||||
	err := proto.Unmarshal(msg, &msgFromMQ)
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ func (pc *PersistentConsumerHandler) Init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey string) {
 | 
			
		||||
	log.InfoByKv("msg come here mysql!!!", "", "msg", string(msg))
 | 
			
		||||
	log.NewInfo("msg come here mysql!!!", "", "msg", string(msg))
 | 
			
		||||
	msgFromMQ := pbMsg.MsgDataToMQ{}
 | 
			
		||||
	err := proto.Unmarshal(msg, &msgFromMQ)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 | 
			
		||||
@ -71,32 +71,34 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
 | 
			
		||||
					bCustomContent, _ := json.Marshal(customContent)
 | 
			
		||||
					jsonCustomContent := string(bCustomContent)
 | 
			
		||||
					var content string
 | 
			
		||||
					switch pushMsg.MsgData.ContentType {
 | 
			
		||||
					case constant.Text:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.Text]
 | 
			
		||||
					case constant.Picture:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.Picture]
 | 
			
		||||
					case constant.Voice:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.Voice]
 | 
			
		||||
					case constant.Video:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.Video]
 | 
			
		||||
					case constant.File:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.File]
 | 
			
		||||
					case constant.AtText:
 | 
			
		||||
						a := AtContent{}
 | 
			
		||||
						_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
 | 
			
		||||
						if utils.IsContain(v.RecvID, a.AtUserList) {
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
 | 
			
		||||
						} else {
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.GroupMsg]
 | 
			
		||||
						}
 | 
			
		||||
					default:
 | 
			
		||||
						content = constant.ContentType2PushContent[constant.Common]
 | 
			
		||||
					}
 | 
			
		||||
					if pushMsg.MsgData.OfflinePushInfo != nil {
 | 
			
		||||
						content = pushMsg.MsgData.OfflinePushInfo.Title
 | 
			
		||||
 | 
			
		||||
					} else {
 | 
			
		||||
						switch pushMsg.MsgData.ContentType {
 | 
			
		||||
						case constant.Text:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.Text]
 | 
			
		||||
						case constant.Picture:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.Picture]
 | 
			
		||||
						case constant.Voice:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.Voice]
 | 
			
		||||
						case constant.Video:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.Video]
 | 
			
		||||
						case constant.File:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.File]
 | 
			
		||||
						case constant.AtText:
 | 
			
		||||
							a := AtContent{}
 | 
			
		||||
							_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
 | 
			
		||||
							if utils.IsContain(v.RecvID, a.AtUserList) {
 | 
			
		||||
								content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
 | 
			
		||||
							} else {
 | 
			
		||||
								content = constant.ContentType2PushContent[constant.GroupMsg]
 | 
			
		||||
							}
 | 
			
		||||
						default:
 | 
			
		||||
							content = constant.ContentType2PushContent[constant.Common]
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					pushResult, err := push.JGAccountListPush(UIDList, content, jsonCustomContent, constant.PlatformIDToName(t))
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error(), constant.PlatformIDToName(t))
 | 
			
		||||
 | 
			
		||||
@ -780,10 +780,26 @@ func (s *groupServer) DeleteGroup(_ context.Context, req *pbGroup.DeleteGroupReq
 | 
			
		||||
func (s *groupServer) OperateUserRole(_ context.Context, req *pbGroup.OperateUserRoleReq) (*pbGroup.OperateUserRoleResp, error) {
 | 
			
		||||
	log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "args:", req.String())
 | 
			
		||||
	resp := &pbGroup.OperateUserRoleResp{}
 | 
			
		||||
	if err := imdb.OperateGroupRole(req.UserId, req.GroupId, req.RoleLevel); err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "OperateGroupRole error", err.Error())
 | 
			
		||||
	oldOwnerUserID, err := imdb.GetGroupMaster(req.GroupId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMaster failed", err.Error())
 | 
			
		||||
		return resp, http.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
 | 
			
		||||
	client := pbGroup.NewGroupClient(etcdConn)
 | 
			
		||||
	var reqPb pbGroup.TransferGroupOwnerReq
 | 
			
		||||
	reqPb.OperationID = req.OperationID
 | 
			
		||||
	reqPb.NewOwnerUserID = req.UserId
 | 
			
		||||
	reqPb.GroupID = req.GroupId
 | 
			
		||||
	reqPb.OpUserID = "cms admin"
 | 
			
		||||
	reqPb.OldOwnerUserID = oldOwnerUserID.UserID
 | 
			
		||||
	reply, err := client.TransferGroupOwner(context.Background(), &reqPb)
 | 
			
		||||
	if reply.CommonResp.ErrCode != 0 || err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "TransferGroupOwner rpc failed")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -840,6 +856,8 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo
 | 
			
		||||
		OpUserID:         req.OpUserId,
 | 
			
		||||
	}
 | 
			
		||||
	chat.MemberKickedNotification(reqKick, resp.Success)
 | 
			
		||||
	log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "success: ", resp.Success)
 | 
			
		||||
	log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "failed: ", resp.Failed)
 | 
			
		||||
	return resp, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,7 @@ func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.Pull
 | 
			
		||||
	log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
 | 
			
		||||
	resp := new(open_im_sdk.PullMessageBySeqListResp)
 | 
			
		||||
	msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
 | 
			
		||||
//	msgList, err := commonDB.DB.GetMsgBySeqListMongo2(in.UserID, in.SeqList, in.OperationID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.ErrorByKv("PullMessageBySeqList data error", in.OperationID, in.String())
 | 
			
		||||
		resp.ErrCode = 201
 | 
			
		||||
 | 
			
		||||
@ -44,11 +44,20 @@ type MsgCallBackResp struct {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func userRelationshipVerification(data *pbChat.SendMsgReq) {
 | 
			
		||||
 | 
			
		||||
	//etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
 | 
			
		||||
	//client := pbChat.NewChatClient(etcdConn)
 | 
			
		||||
	//reply, err := client.SendMsg(context.Background(), &req)
 | 
			
		||||
	//if err != nil {
 | 
			
		||||
	//	log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
 | 
			
		||||
	//} else if reply.ErrCode != 0 {
 | 
			
		||||
	//	log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String())
 | 
			
		||||
	//}
 | 
			
		||||
}
 | 
			
		||||
func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
 | 
			
		||||
	msg.ServerMsgID = GetMsgID(msg.SendID)
 | 
			
		||||
	if msg.SendTime == 0 {
 | 
			
		||||
		msg.SendTime = utils.GetCurrentTimestampByMill()
 | 
			
		||||
	}
 | 
			
		||||
	msg.SendTime = utils.GetCurrentTimestampByMill()
 | 
			
		||||
	switch msg.ContentType {
 | 
			
		||||
	case constant.Text:
 | 
			
		||||
		fallthrough
 | 
			
		||||
@ -96,6 +105,7 @@ func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
 | 
			
		||||
func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.SendMsgResp, error) {
 | 
			
		||||
	replay := pbChat.SendMsgResp{}
 | 
			
		||||
	log.NewDebug(pb.OperationID, "rpc sendMsg come here", pb.String())
 | 
			
		||||
	userRelationshipVerification(pb)
 | 
			
		||||
	//if !utils.VerifyToken(pb.Token, pb.SendID) {
 | 
			
		||||
	//	return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
 | 
			
		||||
	rpc.encapsulateMsgData(pb.MsgData)
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ package statistics
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"Open_IM/pkg/common/config"
 | 
			
		||||
	"Open_IM/pkg/common/constant"
 | 
			
		||||
	"context"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
@ -21,6 +22,7 @@ import (
 | 
			
		||||
	"net"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	errors "Open_IM/pkg/common/http"
 | 
			
		||||
 | 
			
		||||
	"google.golang.org/grpc"
 | 
			
		||||
)
 | 
			
		||||
@ -77,13 +79,13 @@ func (s *statisticsServer) GetActiveGroup(_ context.Context, req *pbStatistics.G
 | 
			
		||||
	resp := &pbStatistics.GetActiveGroupResp{}
 | 
			
		||||
	fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrArgs)
 | 
			
		||||
	}
 | 
			
		||||
	activeGroups, err := imdb.GetActiveGroups(fromTime, toTime, 12)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveGroups failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	for _, activeGroup := range activeGroups {
 | 
			
		||||
		resp.Groups = append(resp.Groups,
 | 
			
		||||
@ -101,13 +103,13 @@ func (s *statisticsServer) GetActiveUser(_ context.Context, req *pbStatistics.Ge
 | 
			
		||||
	resp := &pbStatistics.GetActiveUserResp{}
 | 
			
		||||
	fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	activeUsers, err := imdb.GetActiveUsers(fromTime, toTime, 12)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUsers failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	for _, activeUser := range activeUsers {
 | 
			
		||||
		resp.Users = append(resp.Users,
 | 
			
		||||
@ -199,18 +201,18 @@ func (s *statisticsServer) GetGroupStatistics(_ context.Context, req *pbStatisti
 | 
			
		||||
	resp := &pbStatistics.GetGroupStatisticsResp{}
 | 
			
		||||
	fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupStatistics failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrArgs)
 | 
			
		||||
	}
 | 
			
		||||
	increaseGroupNum, err := imdb.GetIncreaseGroupNum(fromTime, toTime.Add(time.Hour*24))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseGroupNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	totalGroupNum, err := imdb.GetTotalGroupNum()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	resp.IncreaseGroupNum = increaseGroupNum
 | 
			
		||||
	resp.TotalGroupNum = totalGroupNum
 | 
			
		||||
@ -250,17 +252,18 @@ func (s *statisticsServer) GetMessageStatistics(_ context.Context, req *pbStatis
 | 
			
		||||
	resp := &pbStatistics.GetMessageStatisticsResp{}
 | 
			
		||||
	fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrArgs)
 | 
			
		||||
	}
 | 
			
		||||
	privateMessageNum, err := imdb.GetPrivateMessageNum(fromTime, toTime.Add(time.Hour*24))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetPrivateMessageNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	groupMessageNum, err := imdb.GetGroupMessageNum(fromTime, toTime.Add(time.Hour*24))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error())
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMessageNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	resp.PrivateMessageNum = privateMessageNum
 | 
			
		||||
	resp.GroupMessageNum = groupMessageNum
 | 
			
		||||
@ -300,23 +303,23 @@ func (s *statisticsServer) GetUserStatistics(_ context.Context, req *pbStatistic
 | 
			
		||||
	resp := &pbStatistics.GetUserStatisticsResp{}
 | 
			
		||||
	fromTime, toTime, err := ParseTimeFromTo(req.StatisticsReq.From, req.StatisticsReq.To)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo", err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "ParseTimeFromTo failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrArgs)
 | 
			
		||||
	}
 | 
			
		||||
	activeUserNum, err := imdb.GetActiveUserNum(fromTime, toTime.Add(time.Hour*24))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUserNum", err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetActiveUserNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	increaseUserNum, err := imdb.GetIncreaseUserNum(fromTime, toTime.Add(time.Hour*24))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum error", err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetIncreaseUserNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	totalUserNum, err := imdb.GetTotalUserNum()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNum error", err.Error())
 | 
			
		||||
		return resp, err
 | 
			
		||||
		log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetTotalUserNum failed", err.Error())
 | 
			
		||||
		return resp, errors.WrapError(constant.ErrDB)
 | 
			
		||||
	}
 | 
			
		||||
	resp.ActiveUserNum = activeUserNum
 | 
			
		||||
	resp.TotalUserNum = totalUserNum
 | 
			
		||||
 | 
			
		||||
@ -31,3 +31,18 @@ type SetReceiveMessageOptResp struct {
 | 
			
		||||
	CommResp
 | 
			
		||||
	ConversationOptResultList []*OptResult `json:"data"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//type Conversation struct {
 | 
			
		||||
//	OwnerUserID      string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
 | 
			
		||||
//	ConversationID   string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
 | 
			
		||||
//	ConversationType int32  `gorm:"column:conversation_type" json:"conversationType"`
 | 
			
		||||
//	UserID           string `gorm:"column:user_id;type:char(64)" json:"userID"`
 | 
			
		||||
//	GroupID          string `gorm:"column:group_id;type:char(128)" json:"groupID"`
 | 
			
		||||
//	RecvMsgOpt       int32  `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
 | 
			
		||||
//	UnreadCount      int32  `gorm:"column:unread_count" json:"unreadCount"`
 | 
			
		||||
//	DraftTextTime    int64  `gorm:"column:draft_text_time" json:"draftTextTime"`
 | 
			
		||||
//	IsPinned         bool   `gorm:"column:is_pinned" json:"isPinned"`
 | 
			
		||||
//	AttachedInfo     string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
 | 
			
		||||
//	Ex               string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,13 @@
 | 
			
		||||
package base_info
 | 
			
		||||
 | 
			
		||||
type MinioStorageCredentialReq struct {
 | 
			
		||||
	Action string `form:"Action";binding:"required"`
 | 
			
		||||
	DurationSeconds int `form:"DurationSeconds"`
 | 
			
		||||
	Version string `form:"Version"`
 | 
			
		||||
	Policy string
 | 
			
		||||
	OperationID string `json:"operationID"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MiniostorageCredentialResp struct {
 | 
			
		||||
 | 
			
		||||
	SecretAccessKey string `json:"secretAccessKey"`
 | 
			
		||||
	AccessKeyID string `json:"accessKeyID"`
 | 
			
		||||
	SessionToken string `json:"sessionToken"`
 | 
			
		||||
	BucketName string `json:"bucketName"`
 | 
			
		||||
	StsEndpointURL string `json:"stsEndpointURL"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,20 @@ type ApiUserInfo struct {
 | 
			
		||||
	Ex          string `json:"ex" binding:"omitempty,max=1024"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//type Conversation struct {
 | 
			
		||||
//	OwnerUserID      string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
 | 
			
		||||
//	ConversationID   string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
 | 
			
		||||
//	ConversationType int32  `gorm:"column:conversation_type" json:"conversationType"`
 | 
			
		||||
//	UserID           string `gorm:"column:user_id;type:char(64)" json:"userID"`
 | 
			
		||||
//	GroupID          string `gorm:"column:group_id;type:char(128)" json:"groupID"`
 | 
			
		||||
//	RecvMsgOpt       int32  `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
 | 
			
		||||
//	UnreadCount      int32  `gorm:"column:unread_count" json:"unreadCount"`
 | 
			
		||||
//	DraftTextTime    int64  `gorm:"column:draft_text_time" json:"draftTextTime"`
 | 
			
		||||
//	IsPinned         bool   `gorm:"column:is_pinned" json:"isPinned"`
 | 
			
		||||
//	AttachedInfo     string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
 | 
			
		||||
//	Ex               string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
type GroupAddMemberInfo struct {
 | 
			
		||||
	UserID    string `json:"userID" binding:"required"`
 | 
			
		||||
	RoleLevel int32  `json:"roleLevel" binding:"required"`
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,9 @@ type config struct {
 | 
			
		||||
	Api           struct {
 | 
			
		||||
		GinPort []int `yaml:"openImApiPort"`
 | 
			
		||||
	}
 | 
			
		||||
	CmsApi        struct{
 | 
			
		||||
		GinPort []int `yaml:"openImCmsApiPort"`
 | 
			
		||||
	}
 | 
			
		||||
	Sdk struct {
 | 
			
		||||
		WsPort []int `yaml:"openImSdkWsPort"`
 | 
			
		||||
	}
 | 
			
		||||
@ -35,6 +38,13 @@ type config struct {
 | 
			
		||||
			SecretID  string `yaml:"secretID"`
 | 
			
		||||
			SecretKey string `yaml:"secretKey"`
 | 
			
		||||
		}
 | 
			
		||||
		Minio struct {
 | 
			
		||||
			Bucket          string `yaml:"bucket"`
 | 
			
		||||
			Location        string `yaml:"location"`
 | 
			
		||||
			Endpoint        string `yaml:"endpoint"`
 | 
			
		||||
			AccessKeyID     string `yaml:"accessKeyID"`
 | 
			
		||||
			SecretAccessKey string `yaml:"secretAccessKey"`
 | 
			
		||||
		} `yaml:"minio"`
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	Mysql struct {
 | 
			
		||||
 | 
			
		||||
@ -54,10 +54,16 @@ const (
 | 
			
		||||
	FriendRemarkSetNotification           = 1206 //set_friend_remark?
 | 
			
		||||
	BlackAddedNotification                = 1207 //add_black
 | 
			
		||||
	BlackDeletedNotification              = 1208 //remove_black
 | 
			
		||||
	ConversationOptChangeNotification     = 1300 // change conversation opt
 | 
			
		||||
 | 
			
		||||
	UserNotificationBegin       = 1301
 | 
			
		||||
	UserInfoUpdatedNotification = 1303 //SetSelfInfoTip             = 204
 | 
			
		||||
	ConversationNotification    = 1307
 | 
			
		||||
	ConversationNotNotification = 1308
 | 
			
		||||
	ConversationDefault         = 0
 | 
			
		||||
	UserNotificationEnd         = 1399
 | 
			
		||||
 | 
			
		||||
	ConversationOptChangeNotification    = 1300 // change conversation opt
 | 
			
		||||
	GroupNotificationBegin = 1500
 | 
			
		||||
 | 
			
		||||
	GroupCreatedNotification             = 1501
 | 
			
		||||
	GroupInfoSetNotification             = 1502
 | 
			
		||||
@ -121,6 +127,15 @@ const (
 | 
			
		||||
 | 
			
		||||
	//UserJoinGroupSource
 | 
			
		||||
	JoinByAdmin = 1
 | 
			
		||||
 | 
			
		||||
	//Minio
 | 
			
		||||
	MinioDurationTimes = 3600
 | 
			
		||||
 | 
			
		||||
	// verificationCode used for
 | 
			
		||||
	VerificationCodeForRegister       = 1
 | 
			
		||||
	VerificationCodeForReset          = 2
 | 
			
		||||
	VerificationCodeForRegisterSuffix = "_forRegister"
 | 
			
		||||
	VerificationCodeForResetSuffix    = "_forReset"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var ContentType2PushContent = map[int64]string{
 | 
			
		||||
@ -173,3 +188,5 @@ func GroupIsBanPrivateChat(status int32) bool {
 | 
			
		||||
	}
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const BigVersion = "v3"
 | 
			
		||||
 | 
			
		||||
@ -80,6 +80,7 @@ const (
 | 
			
		||||
	SmsSendCodeErr       = 10008
 | 
			
		||||
	CodeInvalidOrExpired = 10009
 | 
			
		||||
	RegisterFailed       = 10010
 | 
			
		||||
	ResetPasswordFailed  = 10011
 | 
			
		||||
	DatabaseError        = 10002
 | 
			
		||||
	ServerError          = 10004
 | 
			
		||||
	HttpError            = 10005
 | 
			
		||||
 | 
			
		||||
@ -3,9 +3,16 @@ package db
 | 
			
		||||
import (
 | 
			
		||||
	"Open_IM/pkg/common/config"
 | 
			
		||||
	"Open_IM/pkg/common/log"
 | 
			
		||||
//	"context"
 | 
			
		||||
//	"fmt"
 | 
			
		||||
	"github.com/garyburd/redigo/redis"
 | 
			
		||||
	"gopkg.in/mgo.v2"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	//"go.mongodb.org/mongo-driver/bson"
 | 
			
		||||
	"go.mongodb.org/mongo-driver/mongo"
 | 
			
		||||
//	"go.mongodb.org/mongo-driver/mongo/options"
 | 
			
		||||
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var DB DataBases
 | 
			
		||||
@ -14,6 +21,7 @@ type DataBases struct {
 | 
			
		||||
	MysqlDB    mysqlDB
 | 
			
		||||
	mgoSession *mgo.Session
 | 
			
		||||
	redisPool  *redis.Pool
 | 
			
		||||
	mongoClient *mongo.Client
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func key(dbAddress, dbName string) string {
 | 
			
		||||
@ -22,10 +30,31 @@ func key(dbAddress, dbName string) string {
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	var mgoSession *mgo.Session
 | 
			
		||||
	var mongoClient *mongo.Client
 | 
			
		||||
	var err1 error
 | 
			
		||||
	//mysql init
 | 
			
		||||
	initMysqlDB()
 | 
			
		||||
	// mongo init
 | 
			
		||||
	// "mongodb://sysop:moon@localhost/records"
 | 
			
		||||
	// uri := "mongodb://user:pass@sample.host:27017/?maxPoolSize=20&w=majority"
 | 
			
		||||
	//uri := fmt.Sprintf("mongodb://%s:%s@%s/%s/?maxPoolSize=%d",
 | 
			
		||||
	//	config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword,
 | 
			
		||||
	//	config.Config.Mongo.DBAddress[0],config.Config.Mongo.DBDatabase,
 | 
			
		||||
	//	config.Config.Mongo.DBMaxPoolSize)
 | 
			
		||||
	//
 | 
			
		||||
	//mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
 | 
			
		||||
	//if err != nil{
 | 
			
		||||
	//	log.NewError(" mongo.Connect  failed, try ", err.Error(), uri)
 | 
			
		||||
	//	time.Sleep(time.Duration(30) * time.Second)
 | 
			
		||||
	//	mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
 | 
			
		||||
	//	if err1 != nil {
 | 
			
		||||
	//		log.NewError(" mongo.Connect  failed, panic", err.Error(), uri)
 | 
			
		||||
	//		panic(err1.Error())
 | 
			
		||||
	//	}
 | 
			
		||||
	//}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	mgoDailInfo := &mgo.DialInfo{
 | 
			
		||||
		Addrs:     config.Config.Mongo.DBAddress,
 | 
			
		||||
		Direct:    config.Config.Mongo.DBDirect,
 | 
			
		||||
@ -37,16 +66,16 @@ func init() {
 | 
			
		||||
		PoolLimit: config.Config.Mongo.DBMaxPoolSize,
 | 
			
		||||
	}
 | 
			
		||||
	mgoSession, err := mgo.DialWithInfo(mgoDailInfo)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.NewError("mgo init err", err.Error(), mgoDailInfo)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		time.Sleep(time.Duration(30) * time.Second)
 | 
			
		||||
 | 
			
		||||
		mgoSession, err1 = mgo.DialWithInfo(mgoDailInfo)
 | 
			
		||||
		if err1 != nil {
 | 
			
		||||
			log.NewError(" mongo.Connect  failed, panic", err.Error())
 | 
			
		||||
			panic(err1.Error())
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	DB.mongoClient = mongoClient
 | 
			
		||||
	DB.mgoSession = mgoSession
 | 
			
		||||
	DB.mgoSession.SetMode(mgo.Monotonic, true)
 | 
			
		||||
	c := DB.mgoSession.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
@ -55,6 +84,7 @@ func init() {
 | 
			
		||||
		panic(err.Error())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// redis pool init
 | 
			
		||||
	DB.redisPool = &redis.Pool{
 | 
			
		||||
		MaxIdle:     config.Config.Redis.DBMaxIdle,
 | 
			
		||||
 | 
			
		||||
@ -187,7 +187,7 @@ type ChatLog struct {
 | 
			
		||||
	SessionType      int32     `gorm:"column:session_type" json:"sessionType"`
 | 
			
		||||
	MsgFrom          int32     `gorm:"column:msg_from" json:"msgFrom"`
 | 
			
		||||
	ContentType      int32     `gorm:"column:content_type" json:"contentType"`
 | 
			
		||||
	Content          string    `gorm:"column:content;type:varchar(1000)" json:"content"`
 | 
			
		||||
	Content          string    `gorm:"column:content;type:varchar(3000)" json:"content"`
 | 
			
		||||
	Status           int32     `gorm:"column:status" json:"status"`
 | 
			
		||||
	SendTime         time.Time `gorm:"column:send_time" json:"sendTime"`
 | 
			
		||||
	CreateTime       time.Time `gorm:"column:create_time" json:"createTime"`
 | 
			
		||||
 | 
			
		||||
@ -6,10 +6,12 @@ import (
 | 
			
		||||
	pbMsg "Open_IM/pkg/proto/chat"
 | 
			
		||||
	open_im_sdk "Open_IM/pkg/proto/sdk_ws"
 | 
			
		||||
	"Open_IM/pkg/utils"
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/garyburd/redigo/redis"
 | 
			
		||||
	//"github.com/garyburd/redigo/redis"
 | 
			
		||||
	"github.com/golang/protobuf/proto"
 | 
			
		||||
	"gopkg.in/mgo.v2/bson"
 | 
			
		||||
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
@ -34,33 +36,35 @@ type GroupMember_x struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) GetMinSeqFromMongo(uid string) (MinSeq uint32, err error) {
 | 
			
		||||
	var i, NB uint32
 | 
			
		||||
	var seqUid string
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return MinSeq, errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
	MaxSeq, err := d.GetUserMaxSeq(uid)
 | 
			
		||||
	if err != nil && err != redis.ErrNil {
 | 
			
		||||
		return MinSeq, err
 | 
			
		||||
	}
 | 
			
		||||
	NB = uint32(MaxSeq / singleGocMsgNum)
 | 
			
		||||
	for i = 0; i <= NB; i++ {
 | 
			
		||||
		seqUid = indexGen(uid, i)
 | 
			
		||||
		n, err := c.Find(bson.M{"uid": seqUid}).Count()
 | 
			
		||||
		if err == nil && n != 0 {
 | 
			
		||||
			if i == 0 {
 | 
			
		||||
				MinSeq = 1
 | 
			
		||||
			} else {
 | 
			
		||||
				MinSeq = uint32(i * singleGocMsgNum)
 | 
			
		||||
			}
 | 
			
		||||
			break
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return MinSeq, nil
 | 
			
		||||
	return 1, nil
 | 
			
		||||
	//var i, NB uint32
 | 
			
		||||
	//var seqUid string
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return MinSeq, errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
	//MaxSeq, err := d.GetUserMaxSeq(uid)
 | 
			
		||||
	//if err != nil && err != redis.ErrNil {
 | 
			
		||||
	//	return MinSeq, err
 | 
			
		||||
	//}
 | 
			
		||||
	//NB = uint32(MaxSeq / singleGocMsgNum)
 | 
			
		||||
	//for i = 0; i <= NB; i++ {
 | 
			
		||||
	//	seqUid = indexGen(uid, i)
 | 
			
		||||
	//	n, err := c.Find(bson.M{"uid": seqUid}).Count()
 | 
			
		||||
	//	if err == nil && n != 0 {
 | 
			
		||||
	//		if i == 0 {
 | 
			
		||||
	//			MinSeq = 1
 | 
			
		||||
	//		} else {
 | 
			
		||||
	//			MinSeq = uint32(i * singleGocMsgNum)
 | 
			
		||||
	//		}
 | 
			
		||||
	//		break
 | 
			
		||||
	//	}
 | 
			
		||||
	//}
 | 
			
		||||
	//return MinSeq, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
 | 
			
		||||
	var hasSeqList []uint32
 | 
			
		||||
	singleCount := 0
 | 
			
		||||
@ -115,6 +119,61 @@ func (d *DataBases) GetMsgBySeqList(uid string, seqList []uint32, operationID st
 | 
			
		||||
	}
 | 
			
		||||
	return seqMsg, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) GetMsgBySeqListMongo2(uid string, seqList []uint32, operationID string) (seqMsg []*open_im_sdk.MsgData, err error) {
 | 
			
		||||
	var hasSeqList []uint32
 | 
			
		||||
	singleCount := 0
 | 
			
		||||
	ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
 | 
			
		||||
	c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
 | 
			
		||||
 | 
			
		||||
	m := func(uid string, seqList []uint32) map[string][]uint32 {
 | 
			
		||||
		t := make(map[string][]uint32)
 | 
			
		||||
		for i := 0; i < len(seqList); i++ {
 | 
			
		||||
			seqUid := getSeqUid(uid, seqList[i])
 | 
			
		||||
			if value, ok := t[seqUid]; !ok {
 | 
			
		||||
				var temp []uint32
 | 
			
		||||
				t[seqUid] = append(temp, seqList[i])
 | 
			
		||||
			} else {
 | 
			
		||||
				t[seqUid] = append(value, seqList[i])
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return t
 | 
			
		||||
	}(uid, seqList)
 | 
			
		||||
	sChat := UserChat{}
 | 
			
		||||
	for seqUid, value := range m {
 | 
			
		||||
		if err = c.FindOne(ctx, bson.M{"uid": seqUid}).Decode(&sChat); err != nil {
 | 
			
		||||
			log.NewError(operationID, "not find seqUid", seqUid, value, uid, seqList, err.Error())
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		singleCount = 0
 | 
			
		||||
		for i := 0; i < len(sChat.Msg); i++ {
 | 
			
		||||
			msg := new(open_im_sdk.MsgData)
 | 
			
		||||
			if err = proto.Unmarshal(sChat.Msg[i].Msg, msg); err != nil {
 | 
			
		||||
				log.NewError(operationID, "Unmarshal err", seqUid, value, uid, seqList, err.Error())
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			if isContainInt32(msg.Seq, value) {
 | 
			
		||||
				seqMsg = append(seqMsg, msg)
 | 
			
		||||
				hasSeqList = append(hasSeqList, msg.Seq)
 | 
			
		||||
				singleCount++
 | 
			
		||||
				if singleCount == len(value) {
 | 
			
		||||
					break
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if len(hasSeqList) != len(seqList) {
 | 
			
		||||
		var diff []uint32
 | 
			
		||||
		diff = utils.Difference(hasSeqList, seqList)
 | 
			
		||||
		exceptionMSg := genExceptionMessageBySeqList(diff)
 | 
			
		||||
		seqMsg = append(seqMsg, exceptionMSg...)
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	return seqMsg, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk.MsgData) {
 | 
			
		||||
	for _, v := range seqList {
 | 
			
		||||
		msg := new(open_im_sdk.MsgData)
 | 
			
		||||
@ -124,6 +183,37 @@ func genExceptionMessageBySeqList(seqList []uint32) (exceptionMsg []*open_im_sdk
 | 
			
		||||
	return exceptionMsg
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) SaveUserChatMongo2(uid string, sendTime int64, m *pbMsg.MsgDataToDB) error {
 | 
			
		||||
	ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
 | 
			
		||||
	c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
 | 
			
		||||
	newTime := getCurrentTimestampByMill()
 | 
			
		||||
	operationID := ""
 | 
			
		||||
	seqUid := getSeqUid(uid, m.MsgData.Seq)
 | 
			
		||||
	filter := bson.M{"uid": seqUid}
 | 
			
		||||
	var err error
 | 
			
		||||
	sMsg := MsgInfo{}
 | 
			
		||||
	sMsg.SendTime = sendTime
 | 
			
		||||
	if sMsg.Msg, err = proto.Marshal(m.MsgData); err != nil {
 | 
			
		||||
		return  utils.Wrap(err,"")
 | 
			
		||||
	}
 | 
			
		||||
	err = c.FindOneAndUpdate(ctx, filter, bson.M{"$push": bson.M{"msg": sMsg}}).Err()
 | 
			
		||||
	log.NewDebug(operationID, "get mgoSession cost time", getCurrentTimestampByMill()-newTime)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		sChat := UserChat{}
 | 
			
		||||
		sChat.UID = seqUid
 | 
			
		||||
		sChat.Msg = append(sChat.Msg, sMsg)
 | 
			
		||||
		if _, err = c.InsertOne(ctx, &sChat) ; err != nil{
 | 
			
		||||
			log.NewDebug(operationID, "InsertOne failed", filter)
 | 
			
		||||
			return utils.Wrap(err, "")
 | 
			
		||||
		}
 | 
			
		||||
	}else{
 | 
			
		||||
		log.NewDebug(operationID, "FindOneAndUpdate ok", filter)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.NewDebug(operationID, "find mgo uid cost time", getCurrentTimestampByMill()-newTime)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) SaveUserChat(uid string, sendTime int64, m *pbMsg.MsgDataToDB) error {
 | 
			
		||||
	var seqUid string
 | 
			
		||||
	newTime := getCurrentTimestampByMill()
 | 
			
		||||
@ -163,115 +253,137 @@ func (d *DataBases) SaveUserChat(uid string, sendTime int64, m *pbMsg.MsgDataToD
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) DelUserChat(uid string) error {
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
func (d *DataBases) DelUserChat(uid string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
	//
 | 
			
		||||
	//delTime := time.Now().Unix() - int64(config.Config.Mongo.DBRetainChatRecords)*24*3600
 | 
			
		||||
	//if err := c.Update(bson.M{"uid": uid}, bson.M{"$pull": bson.M{"msg": bson.M{"sendtime": bson.M{"$lte": delTime}}}}); err != nil {
 | 
			
		||||
	//	return err
 | 
			
		||||
	//}
 | 
			
		||||
	//
 | 
			
		||||
	//return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) DelUserChatMongo2(uid string) error {
 | 
			
		||||
	ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
 | 
			
		||||
	c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
 | 
			
		||||
	filter := bson.M{"uid": uid}
 | 
			
		||||
 | 
			
		||||
	delTime := time.Now().Unix() - int64(config.Config.Mongo.DBRetainChatRecords)*24*3600
 | 
			
		||||
	if err := c.Update(bson.M{"uid": uid}, bson.M{"$pull": bson.M{"msg": bson.M{"sendtime": bson.M{"$lte": delTime}}}}); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	if _, err := c.UpdateOne(ctx, filter, bson.M{"$pull": bson.M{"msg": bson.M{"sendtime": bson.M{"$lte": delTime}}}}); err != nil {
 | 
			
		||||
		return utils.Wrap(err, "")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) MgoUserCount() (int, error) {
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return 0, errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
 | 
			
		||||
	return c.Find(nil).Count()
 | 
			
		||||
	return 0, nil
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return 0, errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
	//
 | 
			
		||||
	//return c.Find(nil).Count()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) MgoSkipUID(count int) (string, error) {
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return "", errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
 | 
			
		||||
	sChat := UserChat{}
 | 
			
		||||
	c.Find(nil).Skip(count).Limit(1).One(&sChat)
 | 
			
		||||
	return sChat.UID, nil
 | 
			
		||||
	return "", nil
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return "", errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
 | 
			
		||||
	//
 | 
			
		||||
	//sChat := UserChat{}
 | 
			
		||||
	//c.Find(nil).Skip(count).Limit(1).One(&sChat)
 | 
			
		||||
	//return sChat.UID, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) GetGroupMember(groupID string) []string {
 | 
			
		||||
	groupInfo := GroupMember_x{}
 | 
			
		||||
	groupInfo.GroupID = groupID
 | 
			
		||||
	groupInfo.UIDList = make([]string, 0)
 | 
			
		||||
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return groupInfo.UIDList
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
 | 
			
		||||
	if err := c.Find(bson.M{"groupid": groupInfo.GroupID}).One(&groupInfo); err != nil {
 | 
			
		||||
		return groupInfo.UIDList
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return groupInfo.UIDList
 | 
			
		||||
	return nil
 | 
			
		||||
	//groupInfo := GroupMember_x{}
 | 
			
		||||
	//groupInfo.GroupID = groupID
 | 
			
		||||
	//groupInfo.UIDList = make([]string, 0)
 | 
			
		||||
	//
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return groupInfo.UIDList
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
	//
 | 
			
		||||
	//if err := c.Find(bson.M{"groupid": groupInfo.GroupID}).One(&groupInfo); err != nil {
 | 
			
		||||
	//	return groupInfo.UIDList
 | 
			
		||||
	//}
 | 
			
		||||
	//
 | 
			
		||||
	//return groupInfo.UIDList
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) AddGroupMember(groupID, uid string) error {
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
 | 
			
		||||
	n, err := c.Find(bson.M{"groupid": groupID}).Count()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if n == 0 {
 | 
			
		||||
		groupInfo := GroupMember_x{}
 | 
			
		||||
		groupInfo.GroupID = groupID
 | 
			
		||||
		groupInfo.UIDList = append(groupInfo.UIDList, uid)
 | 
			
		||||
		err = c.Insert(&groupInfo)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		err = c.Update(bson.M{"groupid": groupID}, bson.M{"$addToSet": bson.M{"uidlist": uid}})
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
	//
 | 
			
		||||
	//n, err := c.Find(bson.M{"groupid": groupID}).Count()
 | 
			
		||||
	//if err != nil {
 | 
			
		||||
	//	return err
 | 
			
		||||
	//}
 | 
			
		||||
	//
 | 
			
		||||
	//if n == 0 {
 | 
			
		||||
	//	groupInfo := GroupMember_x{}
 | 
			
		||||
	//	groupInfo.GroupID = groupID
 | 
			
		||||
	//	groupInfo.UIDList = append(groupInfo.UIDList, uid)
 | 
			
		||||
	//	err = c.Insert(&groupInfo)
 | 
			
		||||
	//	if err != nil {
 | 
			
		||||
	//		return err
 | 
			
		||||
	//	}
 | 
			
		||||
	//} else {
 | 
			
		||||
	//	err = c.Update(bson.M{"groupid": groupID}, bson.M{"$addToSet": bson.M{"uidlist": uid}})
 | 
			
		||||
	//	if err != nil {
 | 
			
		||||
	//		return err
 | 
			
		||||
	//	}
 | 
			
		||||
	//}
 | 
			
		||||
	//
 | 
			
		||||
	//return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataBases) DelGroupMember(groupID, uid string) error {
 | 
			
		||||
	session := d.mgoSession.Clone()
 | 
			
		||||
	if session == nil {
 | 
			
		||||
		return errors.New("session == nil")
 | 
			
		||||
	}
 | 
			
		||||
	defer session.Close()
 | 
			
		||||
 | 
			
		||||
	c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
 | 
			
		||||
	if err := c.Update(bson.M{"groupid": groupID}, bson.M{"$pull": bson.M{"uidlist": uid}}); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
	//session := d.mgoSession.Clone()
 | 
			
		||||
	//if session == nil {
 | 
			
		||||
	//	return errors.New("session == nil")
 | 
			
		||||
	//}
 | 
			
		||||
	//defer session.Close()
 | 
			
		||||
	//
 | 
			
		||||
	//c := session.DB(config.Config.Mongo.DBDatabase).C(cGroup)
 | 
			
		||||
	//
 | 
			
		||||
	//if err := c.Update(bson.M{"groupid": groupID}, bson.M{"$pull": bson.M{"uidlist": uid}}); err != nil {
 | 
			
		||||
	//	return err
 | 
			
		||||
	//}
 | 
			
		||||
	//
 | 
			
		||||
	//return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getCurrentTimestampByMill() int64 {
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,7 @@ func GetRegister(account string) (*db.Register, error) {
 | 
			
		||||
	return &r, dbConn.Table("registers").Where("account = ?",
 | 
			
		||||
		account).Take(&r).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func SetPassword(account, password, ex string) error {
 | 
			
		||||
	r := db.Register{
 | 
			
		||||
		Account:  account,
 | 
			
		||||
@ -25,5 +26,16 @@ func SetPassword(account, password, ex string) error {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return dbConn.Table("registers").Create(&r).Error
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ResetPassword(account, password string) error {
 | 
			
		||||
	r := db.Register{
 | 
			
		||||
		Password:password,
 | 
			
		||||
	}
 | 
			
		||||
	dbConn, err := db.DB.MysqlDB.DefaultGormDB()
 | 
			
		||||
	dbConn.LogMode(true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return dbConn.Table("registers").Where("account = ?", account).Update(&r).Error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -116,10 +116,10 @@ func DeleteGroup(groupId string) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func OperateGroupRole(userId, groupId string, roleLevel int32) error {
 | 
			
		||||
func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, error) {
 | 
			
		||||
	dbConn, err := db.DB.MysqlDB.DefaultGormDB()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
		return "", "", err
 | 
			
		||||
	}
 | 
			
		||||
	dbConn.LogMode(true)
 | 
			
		||||
	groupMember := db.GroupMember{
 | 
			
		||||
@ -133,7 +133,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
 | 
			
		||||
	}
 | 
			
		||||
	switch roleLevel {
 | 
			
		||||
	case constant.GroupOwner:
 | 
			
		||||
		return dbConn.Transaction(func(tx *gorm.DB) error {
 | 
			
		||||
		err = dbConn.Transaction(func(tx *gorm.DB) error {
 | 
			
		||||
			result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{
 | 
			
		||||
				RoleLevel: constant.GroupOrdinaryUsers,
 | 
			
		||||
			})
 | 
			
		||||
@ -153,14 +153,15 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
 | 
			
		||||
			}
 | 
			
		||||
			return nil
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
	case constant.GroupOrdinaryUsers:
 | 
			
		||||
		return dbConn.Transaction(func(tx *gorm.DB) error {
 | 
			
		||||
		err = dbConn.Transaction(func(tx *gorm.DB) error {
 | 
			
		||||
			result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster)
 | 
			
		||||
			if result.Error != nil {
 | 
			
		||||
				return result.Error
 | 
			
		||||
			}
 | 
			
		||||
			if result.RowsAffected == 0 {
 | 
			
		||||
				return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
 | 
			
		||||
				return  errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
 | 
			
		||||
			}
 | 
			
		||||
			if groupMaster.UserID == userId {
 | 
			
		||||
				return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId))
 | 
			
		||||
@ -170,13 +171,13 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) error {
 | 
			
		||||
					return result.Error
 | 
			
		||||
				}
 | 
			
		||||
				if result.RowsAffected == 0 {
 | 
			
		||||
					return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
 | 
			
		||||
					return  errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId))
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return nil
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
	return "", "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetGroupsCountNum(group db.Group) (int32, error) {
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	registerAccountTempCode       = "REGISTER_ACCOUNT_TEMP_CODE"
 | 
			
		||||
	AccountTempCode               = "ACCOUNT_TEMP_CODE"
 | 
			
		||||
	resetPwdTempCode              = "RESET_PWD_TEMP_CODE"
 | 
			
		||||
	userIncrSeq                   = "REDIS_USER_INCR_SEQ:" // user incr seq
 | 
			
		||||
	appleDeviceToken              = "DEVICE_TOKEN"
 | 
			
		||||
	userMinSeq                    = "REDIS_USER_MIN_SEQ:"
 | 
			
		||||
@ -35,16 +36,16 @@ func (d *DataBases) Exec(cmd string, key interface{}, args ...interface{}) (inte
 | 
			
		||||
	return con.Do(cmd, params...)
 | 
			
		||||
}
 | 
			
		||||
func (d *DataBases) JudgeAccountEXISTS(account string) (bool, error) {
 | 
			
		||||
	key := registerAccountTempCode + account
 | 
			
		||||
	key := AccountTempCode + account
 | 
			
		||||
	return redis.Bool(d.Exec("EXISTS", key))
 | 
			
		||||
}
 | 
			
		||||
func (d *DataBases) SetAccountCode(account string, code, ttl int) (err error) {
 | 
			
		||||
	key := registerAccountTempCode + account
 | 
			
		||||
	_, err = d.Exec("Set", key, code, ttl)
 | 
			
		||||
	key := AccountTempCode + account
 | 
			
		||||
	_, err = d.Exec("SET", key, code, "ex", ttl)
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
func (d *DataBases) GetAccountCode(account string) (string, error) {
 | 
			
		||||
	key := userIncrSeq + account
 | 
			
		||||
	key := AccountTempCode + account
 | 
			
		||||
	return redis.String(d.Exec("GET", key))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@ list_to_string $list2
 | 
			
		||||
ws_ports=($ports_array)
 | 
			
		||||
list_to_string $list3
 | 
			
		||||
sdk_ws_ports=($ports_array)
 | 
			
		||||
 | 
			
		||||
list_to_string $list4
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user