#NEWLINE# @ login_required #NEWLINE# @ csrf_exempt #NEWLINE# def session_stop( request , session_id ) : #NEWLINE# #INDENT# if ( request . method != 'POST' ) : #NEWLINE# #INDENT# return HttpResponseBadRequest ( 'Method must be POST' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# Session ( auth_token = request . user . password ) . stop ( session_id ) #NEWLINE# #UNINDENT# except UnauthorizedException : #NEWLINE# #INDENT# logger . warning ( 'User unauthorized. Signing out...' ) #NEWLINE# signout ( request ) #NEWLINE# return HttpResponseBadRequest ( 'Unauthorized' ) #NEWLINE# #UNINDENT# except NotFoundException : #NEWLINE# #INDENT# logger . warning ( 'The requested Session "%s" does not exist' , session_id ) #NEWLINE# return HttpResponseBadRequest ( 'Resource not found' ) #NEWLINE# #UNINDENT# except ServerErrorException : #NEWLINE# #INDENT# logger . error ( 'Unexpected exception in the API' , exc_info = True ) #NEWLINE# return HttpResponseServerError ( ) #NEWLINE# #UNINDENT# except Exception as inst : #NEWLINE# #INDENT# logger . error ( 'Unexpected exception' , exc_info = True ) #NEWLINE# message = ( inst . message if inst . message else 'Unexpected error' ) #NEWLINE# return HttpResponseBadRequest ( message ) #NEWLINE# #UNINDENT# return HttpResponse ( 'stopped' )