mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-08 11:41:03 +00:00
Add user.LogoutAll() method
This commit is contained in:
parent
b7cb0db6c5
commit
92f2b43f56
@ -13,4 +13,5 @@ Implemented from [Client-Server API](https://matrix.org/docs/spec/client_server/
|
||||
- [x] [5.4.1 GET /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-login)
|
||||
- [x] [5.4.2 POST /_matrix/client/r0/login](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login)
|
||||
- [x] [5.4.3 POST /_matrix/client/r0/logout](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout)
|
||||
- [x] [5.4.4 POST /_matrix/client/r0/logout/all](https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout-all)
|
||||
- [x] [5.7.1 GET /_matrix/client/r0/account/whoami](https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-account-whoami)
|
@ -33,4 +33,5 @@ type User interface {
|
||||
LeaveRoom(room Room) *models.ApiError
|
||||
SetTopic(room Room, topic string) *models.ApiError
|
||||
SendMessage(room Room, text string) *models.ApiError
|
||||
LogoutAll()
|
||||
}
|
||||
|
@ -154,3 +154,7 @@ func (user *User) SendMessage(room internal.Room, text string) *models.ApiError
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user *User) LogoutAll() {
|
||||
user.Tokens = make(map[string]Token)
|
||||
}
|
||||
|
@ -97,6 +97,31 @@ func LogoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||
sendJsonResponse(w, http.StatusOK, struct{}{})
|
||||
}
|
||||
|
||||
// https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-logout-all
|
||||
func LogoutAllHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
errorResponse(w, models.M_UNKNOWN, http.StatusBadRequest, "wrong method: "+r.Method)
|
||||
return
|
||||
}
|
||||
|
||||
token := getTokenFromResponse(r)
|
||||
|
||||
if token == "" {
|
||||
errorResponse(w, models.M_MISSING_TOKEN, http.StatusBadRequest, "")
|
||||
return
|
||||
}
|
||||
|
||||
user := currServer.Backend.GetUserByToken(token)
|
||||
if user == nil {
|
||||
errorResponse(w, models.M_UNKNOWN_TOKEN, http.StatusBadRequest, "")
|
||||
return
|
||||
}
|
||||
|
||||
user.LogoutAll()
|
||||
|
||||
sendJsonResponse(w, http.StatusOK, struct{}{})
|
||||
}
|
||||
|
||||
// https://models.org/docs/spec/client_server/latest#post-models-client-r0-register
|
||||
func RegisterHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
|
@ -21,6 +21,7 @@ func New() *Server {
|
||||
router.HandleFunc("/_matrix/client/versions", VersionHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/login", LoginHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/logout", LogoutHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/logout/all", LogoutAllHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/register", RegisterHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/account/whoami", WhoAmIHandler)
|
||||
router.HandleFunc("/_matrix/client/r0/sync", SyncHandler)
|
||||
|
Loading…
Reference in New Issue
Block a user