Ejemplo n.º 1
0
    def get(self):
        if session[ProtocolItem.LOGIN_BODY][ProtocolItem.CLIENTTYPE]==ProtocolItem.VALUE_HUMAN:
            return {ProtocolItem.ID: session[ProtocolItem.SESSION_ACCOUNT].id}
        else:
            return {}


class Logout(Resource):
    method_decorators = [auth.login_required]
    def get(self):
        session.clear()
        return {}


class Keepalive(Resource):
    method_decorators = [auth.login_required]
    def get(self):
        return {}


class Regist(Resource):
    def post(self):
        account = logic.Regist(json.loads(request.data))
        return {ProtocolItem.ID:account.id} if account else {}


api.add_resource(Keepalive, '/api/v1.0/keepalive')
api.add_resource(Logout, '/api/v1.0/logout')
api.add_resource(Login, '/api/v1.0/login')
api.add_resource(Regist, '/api/v1.0/regist')
Ejemplo n.º 2
0
class Gateway(Resource):
    method_decorators = [auth.login_required]

    def post(self):
        print "POST a Gateway:", request.data, "--"
        body = json.loads(request.data)
        _id = mongo.UpsertGateway(body[ProtocolItem.ADDGATEWAY][ProtocolItem.GATEWAY])
        resp = {"_id": str(_id)}
        return resp

    def delete(self, id):
        print "DELETE a Gateway<id:%d>:%s--" % (id, request.data)
        body = json.loads(request.data)
        return {"deleted_count": mongo.DeleteGateway(body[ProtocolItem.DELETEGATEWAY][ProtocolItem.GATEWAY])}

    def put(self, id):
        print "PUT a Gateway<id:%d>:%s--" % (id, request.data)
        body = json.loads(request.data)
        _id = mongo.UpsertGateway(body[ProtocolItem.UPDATEGATEWAY][ProtocolItem.GATEWAY])
        resp = {"_id": str(_id)}
        return resp

    def get(self, id):
        print "GET a Gateway<id:%s>:%s--" % (id, request.data)
        ret = mongo.GetGateway(id)
        print ret
        return ret


api.add_resource(Gateway, "/api/gateway", "/api/gateway/<string:id>")