mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-07-07 21:03:20 +08:00
删除登录、登出接口
This commit is contained in:
parent
b34d7262e3
commit
62e965ad28
@ -18,6 +18,7 @@ import (
|
|||||||
// It follows the same direct-DB pattern as UserGlobalBlackApi.
|
// It follows the same direct-DB pattern as UserGlobalBlackApi.
|
||||||
type DeleteUserApi struct {
|
type DeleteUserApi struct {
|
||||||
userDB database.User
|
userDB database.User
|
||||||
|
phoneSNDB database.PhoneSN
|
||||||
authClient *rpcli.AuthClient
|
authClient *rpcli.AuthClient
|
||||||
groupClient group.GroupClient
|
groupClient group.GroupClient
|
||||||
friendClient relation.FriendClient
|
friendClient relation.FriendClient
|
||||||
@ -26,6 +27,7 @@ type DeleteUserApi struct {
|
|||||||
|
|
||||||
func NewDeleteUserApi(
|
func NewDeleteUserApi(
|
||||||
userDB database.User,
|
userDB database.User,
|
||||||
|
phoneSNDB database.PhoneSN,
|
||||||
authClient *rpcli.AuthClient,
|
authClient *rpcli.AuthClient,
|
||||||
groupClient group.GroupClient,
|
groupClient group.GroupClient,
|
||||||
friendClient relation.FriendClient,
|
friendClient relation.FriendClient,
|
||||||
@ -33,6 +35,7 @@ func NewDeleteUserApi(
|
|||||||
) *DeleteUserApi {
|
) *DeleteUserApi {
|
||||||
return &DeleteUserApi{
|
return &DeleteUserApi{
|
||||||
userDB: userDB,
|
userDB: userDB,
|
||||||
|
phoneSNDB: phoneSNDB,
|
||||||
authClient: authClient,
|
authClient: authClient,
|
||||||
groupClient: groupClient,
|
groupClient: groupClient,
|
||||||
friendClient: friendClient,
|
friendClient: friendClient,
|
||||||
@ -131,7 +134,14 @@ func (d *DeleteUserApi) DeleteUser(c *gin.Context) {
|
|||||||
pageNumber++
|
pageNumber++
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Hard-delete user document from MongoDB.
|
// 5. Delete phone_sn_info record bound to this user's phone number.
|
||||||
|
if phone := users[0].Phone; phone != "" {
|
||||||
|
if err := d.phoneSNDB.DeleteByPhone(c, phone); err != nil {
|
||||||
|
log.ZWarn(c, "DeleteUser: DeleteByPhone failed", err, "userID", req.UserID, "phone", phone)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Hard-delete user document from MongoDB.
|
||||||
// Redis cache will become stale and expire via TTL; the user can no longer
|
// Redis cache will become stale and expire via TTL; the user can no longer
|
||||||
// authenticate because their tokens were already invalidated in step 2.
|
// authenticate because their tokens were already invalidated in step 2.
|
||||||
if err := d.userDB.Delete(c, []string{req.UserID}); err != nil {
|
if err := d.userDB.Delete(c, []string{req.UserID}); err != nil {
|
||||||
|
|||||||
@ -137,7 +137,7 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, co
|
|||||||
m := NewMessageApi(msg.NewMsgClient(msgConn), rpcli.NewUserClient(userConn), config.Share.IMAdminUserID)
|
m := NewMessageApi(msg.NewMsgClient(msgConn), rpcli.NewUserClient(userConn), config.Share.IMAdminUserID)
|
||||||
cp := NewCaptchaApi(pbcaptcha.NewCaptchaClient(captchaConn))
|
cp := NewCaptchaApi(pbcaptcha.NewCaptchaClient(captchaConn))
|
||||||
bl := NewUserGlobalBlackApi(blacklistCtrl, userDB, config.Share.IMAdminUserID, rpcli.NewAuthClient(authConn))
|
bl := NewUserGlobalBlackApi(blacklistCtrl, userDB, config.Share.IMAdminUserID, rpcli.NewAuthClient(authConn))
|
||||||
du := NewDeleteUserApi(userDB, rpcli.NewAuthClient(authConn), group.NewGroupClient(groupConn), relation.NewFriendClient(friendConn), config.Share.IMAdminUserID)
|
du := NewDeleteUserApi(userDB, phoneSNDB, rpcli.NewAuthClient(authConn), group.NewGroupClient(groupConn), relation.NewFriendClient(friendConn), config.Share.IMAdminUserID)
|
||||||
phoneSN := NewPhoneSNApi(phoneSNDB)
|
phoneSN := NewPhoneSNApi(phoneSNDB)
|
||||||
userRouterGroup := r.Group("/user")
|
userRouterGroup := r.Group("/user")
|
||||||
{
|
{
|
||||||
|
|||||||
@ -48,6 +48,14 @@ func (p *phoneSNMgo) GetByPhone(ctx context.Context, phone string) (*model.Phone
|
|||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *phoneSNMgo) DeleteByPhone(ctx context.Context, phone string) error {
|
||||||
|
if phone == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
_, err := p.coll.DeleteOne(ctx, bson.M{"phone": phone})
|
||||||
|
return errs.Wrap(err)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *phoneSNMgo) Upsert(ctx context.Context, phone string, userID int64, isSnd bool) error {
|
func (p *phoneSNMgo) Upsert(ctx context.Context, phone string, userID int64, isSnd bool) error {
|
||||||
if phone == "" {
|
if phone == "" {
|
||||||
return errs.ErrArgs.WrapMsg("phone is empty")
|
return errs.ErrArgs.WrapMsg("phone is empty")
|
||||||
|
|||||||
@ -17,4 +17,6 @@ type PhoneSN interface {
|
|||||||
GetByPhone(ctx context.Context, phone string) (*model.PhoneSNInfo, error)
|
GetByPhone(ctx context.Context, phone string) (*model.PhoneSNInfo, error)
|
||||||
// Upsert 写入或更新 is_snd 与 user_id
|
// Upsert 写入或更新 is_snd 与 user_id
|
||||||
Upsert(ctx context.Context, phone string, userID int64, isSnd bool) error
|
Upsert(ctx context.Context, phone string, userID int64, isSnd bool) error
|
||||||
|
// DeleteByPhone 按手机号删除记录;记录不存在时不报错
|
||||||
|
DeleteByPhone(ctx context.Context, phone string) error
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user