2016-06-02 20:33:39 +00:00
|
|
|
import json
|
2016-10-02 20:48:14 +00:00
|
|
|
|
|
|
|
from common.web import requestsManager
|
|
|
|
from constants import exceptions
|
2016-06-02 20:33:39 +00:00
|
|
|
from objects import glob
|
|
|
|
|
2016-10-02 20:48:14 +00:00
|
|
|
|
|
|
|
class handler(requestsManager.asyncRequestHandler):
|
2016-06-02 20:33:39 +00:00
|
|
|
def asyncGet(self):
|
|
|
|
statusCode = 400
|
|
|
|
data = {"message": "unknown error"}
|
|
|
|
try:
|
|
|
|
# Check arguments
|
2016-08-24 03:10:29 +00:00
|
|
|
if "u" not in self.request.arguments and "id" not in self.request.arguments:
|
2016-08-21 18:32:17 +00:00
|
|
|
raise exceptions.invalidArgumentsException()
|
2016-06-02 20:33:39 +00:00
|
|
|
|
|
|
|
# Get online staus
|
2016-08-23 18:35:47 +00:00
|
|
|
username = None
|
|
|
|
userID = None
|
|
|
|
if "u" in self.request.arguments:
|
|
|
|
username = self.get_argument("u")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
userID = int(self.get_argument("id"))
|
|
|
|
except:
|
|
|
|
raise exceptions.invalidArgumentsException()
|
|
|
|
|
2016-09-02 15:45:10 +00:00
|
|
|
if username is None and userID is None:
|
2016-06-02 20:33:39 +00:00
|
|
|
data["result"] = False
|
|
|
|
else:
|
2016-09-02 15:45:10 +00:00
|
|
|
if username is not None:
|
|
|
|
data["result"] = True if glob.tokens.getTokenFromUsername(username) is not None else False
|
2016-08-23 18:35:47 +00:00
|
|
|
else:
|
2016-09-02 15:45:10 +00:00
|
|
|
data["result"] = True if glob.tokens.getTokenFromUserID(userID) is not None else False
|
2016-06-02 20:33:39 +00:00
|
|
|
|
|
|
|
# Status code and message
|
|
|
|
statusCode = 200
|
|
|
|
data["message"] = "ok"
|
|
|
|
except exceptions.invalidArgumentsException:
|
|
|
|
statusCode = 400
|
|
|
|
data["message"] = "missing required arguments"
|
|
|
|
finally:
|
|
|
|
# Add status code to data
|
|
|
|
data["status"] = statusCode
|
|
|
|
|
|
|
|
# Send response
|
2016-06-16 12:57:54 +00:00
|
|
|
#self.clear()
|
|
|
|
self.write(json.dumps(data))
|
2016-06-02 20:33:39 +00:00
|
|
|
self.set_status(statusCode)
|
2016-06-16 12:57:54 +00:00
|
|
|
#self.finish(json.dumps(data))
|