|
|
|
|
@ -1064,45 +1064,3 @@ func (s *userServer) SortQuery(ctx context.Context, req *pbuser.SortQueryReq) (*
|
|
|
|
|
}
|
|
|
|
|
return &pbuser.SortQueryResp{Users: convert.UsersDB2Pb(users)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UserLogin 记录当前用户的登录时间(userID 取自上下文 opUserID)。
|
|
|
|
|
func (s *userServer) UserLogin(ctx context.Context, _ *pbuser.UserLoginReq) (*pbuser.UserLoginResp, error) {
|
|
|
|
|
userID := mcontext.GetOpUserID(ctx)
|
|
|
|
|
if userID == "" {
|
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("opUserID is required")
|
|
|
|
|
}
|
|
|
|
|
if _, err := s.db.FindWithError(ctx, []string{userID}); err != nil {
|
|
|
|
|
log.ZError(ctx, "UserLogin: user not found", err, "userID", userID)
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
now := time.Now()
|
|
|
|
|
if err := s.db.UpdateByMap(ctx, userID, map[string]any{
|
|
|
|
|
"cur_login_time": now,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
log.ZError(ctx, "UserLogin: UpdateByMap failed", err, "userID", userID)
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
log.ZDebug(ctx, "UserLogin: recorded login time", "userID", userID, "loginTime", now)
|
|
|
|
|
return &pbuser.UserLoginResp{}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UserLogout 记录当前登录用户的登出时间(userID 取自上下文 opUserID)。
|
|
|
|
|
func (s *userServer) UserLogout(ctx context.Context, _ *pbuser.UserLogoutReq) (*pbuser.UserLogoutResp, error) {
|
|
|
|
|
userID := mcontext.GetOpUserID(ctx)
|
|
|
|
|
if userID == "" {
|
|
|
|
|
return nil, errs.ErrArgs.WrapMsg("opUserID is required")
|
|
|
|
|
}
|
|
|
|
|
if _, err := s.db.FindWithError(ctx, []string{userID}); err != nil {
|
|
|
|
|
log.ZError(ctx, "UserLogout: user not found", err, "userID", userID)
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
now := time.Now()
|
|
|
|
|
if err := s.db.UpdateByMap(ctx, userID, map[string]any{
|
|
|
|
|
"last_logout_time": now,
|
|
|
|
|
}); err != nil {
|
|
|
|
|
log.ZError(ctx, "UserLogout: UpdateByMap failed", err, "userID", userID)
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
log.ZDebug(ctx, "UserLogout: recorded logout time", "userID", userID, "logoutTime", now)
|
|
|
|
|
return &pbuser.UserLogoutResp{}, nil
|
|
|
|
|
}
|
|
|
|
|
|