59e26b28 by Jonille Arreglo

31466_limited_usage_chatbot+

1 parent 80f3ea39
Showing 1 changed file with 36 additions and 33 deletions
......@@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) {
let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" });
if (!auth.success) {
IS_FREE_USER = true;
if (auth.is_restrict) {
res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
res.end();
return false;
} else if (typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
res.json({ status: "invalid", restrict: true });
res.end();
return false;
IS_FREE_USER = true;
if (auth.is_restrict) {
res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
res.end();
return false;
} else if (auth.subscription_type &&
typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
res.json({ status: "invalid", restrict: true });
res.end();
return false;
}
} else {
let data = await getUsage({
aiwp_logged_in, app: 'chatbot+'
});
if (!(data.success === 1 && data.status === 'valid')) {
res.json({ status: "invalid", data });
res.status(200);
return false;
}
}
let data = await getUsage({
aiwp_logged_in, app: 'chatbot+'
});
if (!(data.success === 1 && data.status === 'valid')) {
res.json({ status: "invalid", data });
res.status(200);
return false;
}
} else {
IS_FREE_USER = true;
let data = await getLimitedUsage({
"aiwp_app_id": aiwp_app_id
});
if (data.usage !== null) {
TRIED_USAGE = parseInt(data.usage);
}
} else {
IS_FREE_USER = true;
}
if (IS_FREE_USER && TRIED_USAGE >= limit) {
res.json({ status: "invalid", limited: true });
res.end();
return false;
if(IS_FREE_USER) {
let data = await getLimitedUsage({
"aiwp_app_id": aiwp_app_id
});
if (data.usage !== null) {
TRIED_USAGE = parseInt(data.usage);
}
if (TRIED_USAGE >= limit) {
res.json({ status: "invalid", limited: true });
res.end();
return false;
}
TRIED_USAGE++;
}
if (IS_FREE_USER) TRIED_USAGE++;
return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE };
};
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!