<s> from twisted . internet import defer <EOL> from synapse . api . errors import AuthError , Codes <EOL> from . base import ClientV1RestServlet , client_path_patterns <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> class LogoutRestServlet ( ClientV1RestServlet ) : <EOL> PATTERNS = client_path_patterns ( "<STR_LIT>" ) <EOL> def __init__ ( self , hs ) : <EOL> super ( LogoutRestServlet , self ) . __init__ ( hs ) <EOL> self . store = hs . get_datastore ( ) <EOL> def on_OPTIONS ( self , request ) : <EOL> return ( <NUM_LIT:200> , { } ) <EOL> @ defer . inlineCallbacks <EOL> def on_POST ( self , request ) : <EOL> try : <EOL> access_token = request . args [ "<STR_LIT>" ] [ <NUM_LIT:0> ] <EOL> except KeyError : <EOL> raise AuthError ( <EOL> self . TOKEN_NOT_FOUND_HTTP_STATUS , "<STR_LIT>" , <EOL> errcode = Codes . MISSING_TOKEN <EOL> ) <EOL> yield self . store . delete_access_token ( access_token ) <EOL> defer . returnValue ( ( <NUM_LIT:200> , { } ) ) <EOL> class LogoutAllRestServlet ( ClientV1RestServlet ) : <EOL> PATTERNS = client_path_patterns ( "<STR_LIT>" ) <EOL> def __init__ ( self , hs ) : <EOL> super ( LogoutAllRestServlet , self ) . __init__ ( hs ) <EOL> self . store = hs . get_datastore ( ) <EOL> self . auth = hs . get_auth ( ) <EOL> def on_OPTIONS ( self , request ) : <EOL> return ( <NUM_LIT:200> , { } ) <EOL> @ defer . inlineCallbacks <EOL> def on_POST ( self , request ) : <EOL> requester = yield self . auth . get_user_by_req ( request ) <EOL> user_id = requester . user . to_string ( ) <EOL> yield self . store . user_delete_access_tokens ( user_id ) <EOL> defer . returnValue ( ( <NUM_LIT:200> , { } ) ) <EOL> def register_servlets ( hs , http_server ) : <EOL> LogoutRestServlet ( hs ) . register ( http_server ) <EOL> LogoutAllRestServlet ( hs ) . register ( http_server ) </s>
