mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
Merge remote-tracking branch 'origin/superGroup' into superGroup
This commit is contained in:
commit
7d63c82ddd
@ -46,12 +46,18 @@ func Login(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "password err"})
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.PasswordErr, "errMsg": "password err"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var userID string
|
||||||
|
if r.UserID != "" {
|
||||||
|
userID = r.UserID
|
||||||
|
} else {
|
||||||
|
userID = r.Account
|
||||||
|
}
|
||||||
url := fmt.Sprintf("http://%s:%d/auth/user_token", utils.ServerIP, config.Config.Api.GinPort[0])
|
url := fmt.Sprintf("http://%s:%d/auth/user_token", utils.ServerIP, config.Config.Api.GinPort[0])
|
||||||
openIMGetUserToken := api.UserTokenReq{}
|
openIMGetUserToken := api.UserTokenReq{}
|
||||||
openIMGetUserToken.OperationID = params.OperationID
|
openIMGetUserToken.OperationID = params.OperationID
|
||||||
openIMGetUserToken.Platform = params.Platform
|
openIMGetUserToken.Platform = params.Platform
|
||||||
openIMGetUserToken.Secret = config.Config.Secret
|
openIMGetUserToken.Secret = config.Config.Secret
|
||||||
openIMGetUserToken.UserID = account
|
openIMGetUserToken.UserID = userID
|
||||||
openIMGetUserTokenResp := api.UserTokenResp{}
|
openIMGetUserTokenResp := api.UserTokenResp{}
|
||||||
bMsg, err := http2.Post(url, openIMGetUserToken, 2)
|
bMsg, err := http2.Post(url, openIMGetUserToken, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,7 +44,9 @@ func ResetPassword(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
user, err := im_mysql_model.GetRegister(account)
|
user, err := im_mysql_model.GetRegister(account)
|
||||||
if err != nil || user.Account == "" {
|
if err != nil || user.Account == "" {
|
||||||
|
if err != nil {
|
||||||
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
|
log.NewError(req.OperationID, utils.GetSelfFuncName(), "get register error", err.Error())
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "user not register!"})
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.NotRegistered, "errMsg": "user not register!"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,12 @@ func SetPassword(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
userID := utils.Md5(account)
|
||||||
url := config.Config.Demo.ImAPIURL + "/auth/user_register"
|
url := config.Config.Demo.ImAPIURL + "/auth/user_register"
|
||||||
openIMRegisterReq := api.UserRegisterReq{}
|
openIMRegisterReq := api.UserRegisterReq{}
|
||||||
openIMRegisterReq.OperationID = params.OperationID
|
openIMRegisterReq.OperationID = params.OperationID
|
||||||
openIMRegisterReq.Platform = params.Platform
|
openIMRegisterReq.Platform = params.Platform
|
||||||
openIMRegisterReq.UserID = account
|
openIMRegisterReq.UserID = userID
|
||||||
openIMRegisterReq.Nickname = params.Name
|
openIMRegisterReq.Nickname = params.Name
|
||||||
openIMRegisterReq.Secret = config.Config.Secret
|
openIMRegisterReq.Secret = config.Config.Secret
|
||||||
openIMRegisterResp := api.UserRegisterResp{}
|
openIMRegisterResp := api.UserRegisterResp{}
|
||||||
@ -76,7 +77,7 @@ func SetPassword(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
log.Info(params.OperationID, "begin store mysql", account, params.Password)
|
||||||
err = im_mysql_model.SetPassword(account, params.Password, params.Ex)
|
err = im_mysql_model.SetPassword(account, params.Password, params.Ex, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
|
log.NewError(params.OperationID, "set phone number password error", account, "err", err.Error())
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": err.Error()})
|
||||||
@ -84,7 +85,7 @@ func SetPassword(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
log.Info(params.OperationID, "end setPassword", account, params.Password)
|
log.Info(params.OperationID, "end setPassword", account, params.Password)
|
||||||
// demo onboarding
|
// demo onboarding
|
||||||
onboardingProcess(params.OperationID, account, params.Name)
|
onboardingProcess(params.OperationID, userID, params.Name)
|
||||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
|
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ type Register struct {
|
|||||||
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
|
||||||
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
|
||||||
Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
Ex string `gorm:"column:ex;size:1024" json:"ex"`
|
||||||
|
UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -53,7 +53,9 @@ func initMysqlDB() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("open db ok ", dsn)
|
fmt.Println("open db ok ", dsn)
|
||||||
db.AutoMigrate(&Friend{},
|
db.AutoMigrate(
|
||||||
|
&Register{},
|
||||||
|
&Friend{},
|
||||||
&FriendRequest{},
|
&FriendRequest{},
|
||||||
&Group{},
|
&Group{},
|
||||||
&GroupMember{},
|
&GroupMember{},
|
||||||
|
@ -15,11 +15,12 @@ func GetRegister(account string) (*db.Register, error) {
|
|||||||
account).Take(&r).Error
|
account).Take(&r).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetPassword(account, password, ex string) error {
|
func SetPassword(account, password, ex, userID string) error {
|
||||||
r := db.Register{
|
r := db.Register{
|
||||||
Account: account,
|
Account: account,
|
||||||
Password: password,
|
Password: password,
|
||||||
Ex: ex,
|
Ex: ex,
|
||||||
|
UserID: userID,
|
||||||
}
|
}
|
||||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
64
pkg/utils/encryption .go
Normal file
64
pkg/utils/encryption .go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/aes"
|
||||||
|
"crypto/cipher"
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Md5(s string, salt ...string) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(s))
|
||||||
|
if len(salt) > 0 {
|
||||||
|
h.Write([]byte(salt[0]))
|
||||||
|
}
|
||||||
|
cipher := h.Sum(nil)
|
||||||
|
return hex.EncodeToString(cipher)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AesEncrypt(data []byte, key []byte) ([]byte, error) {
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
blockSize := block.BlockSize()
|
||||||
|
encryptBytes := pkcs7Padding(data, blockSize)
|
||||||
|
crypted := make([]byte, len(encryptBytes))
|
||||||
|
blockMode := cipher.NewCBCEncrypter(block, key[:blockSize])
|
||||||
|
blockMode.CryptBlocks(crypted, encryptBytes)
|
||||||
|
return crypted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AesDecrypt(data []byte, key []byte) ([]byte, error) {
|
||||||
|
block, err := aes.NewCipher(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
blockSize := block.BlockSize()
|
||||||
|
blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
|
||||||
|
crypted := make([]byte, len(data))
|
||||||
|
blockMode.CryptBlocks(crypted, data)
|
||||||
|
crypted, err = pkcs7UnPadding(crypted)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return crypted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func pkcs7Padding(data []byte, blockSize int) []byte {
|
||||||
|
padding := blockSize - len(data)%blockSize
|
||||||
|
padText := bytes.Repeat([]byte{byte(padding)}, padding)
|
||||||
|
return append(data, padText...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func pkcs7UnPadding(data []byte) ([]byte, error) {
|
||||||
|
length := len(data)
|
||||||
|
if length == 0 {
|
||||||
|
return nil, errors.New("encrypt error")
|
||||||
|
}
|
||||||
|
unPadding := int(data[length-1])
|
||||||
|
return data[:(length - unPadding)], nil
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Md5(s string) string {
|
|
||||||
h := md5.New()
|
|
||||||
h.Write([]byte(s))
|
|
||||||
cipher := h.Sum(nil)
|
|
||||||
return hex.EncodeToString(cipher)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user