Pixel-Composer/objects/o_dialog_patreon/Create_0.gml

74 lines
2 KiB
Text
Raw Normal View History

2024-11-14 03:41:05 +01:00
/// @description init
event_inherited();
#region data
dialog_w = ui(480);
2024-11-20 09:05:51 +01:00
dialog_h = ui(240);
2024-11-14 03:41:05 +01:00
title_height = ui(28);
destroy_on_click_out = false;
campaign_id = "2263128";
req_patreon = "";
req_user = "";
2024-11-16 07:01:14 +01:00
req_member = {};
access_token = "";
2024-11-14 03:41:05 +01:00
2024-11-20 09:05:51 +01:00
page = 0;
status = 0;
2024-11-14 03:41:05 +01:00
2024-11-20 09:05:51 +01:00
tb_code = new textBox(TEXTBOX_INPUT.text, function(t) /*=>*/ { submit_code(t); });
if(IS_PATREON) {
txt = "Patreon verified, thank you for supporting Pixel Composer!";
server = 0;
} else {
2024-11-20 09:05:51 +01:00
if(!os_is_network_connected()) {
status = -1;
txt = "No internet connection, please try again.";
} else {
txt = "Sign-in to Patreon on browser";
var attmp = 0;
do {
port = irandom_range(7000, 20000);
server = network_create_server_raw(network_socket_ws, port, 32);
} until(server >= 0 || attmp++ >= 100);
if(server >= 0) {
var _url = "www.patreon.com/oauth2/authorize";
_url += "?response_type=code";
_url += "&client_id=oZ1PNvUY61uH0FiA7ZPMBy77Xau3Ok9tfvsT_Y8DQwyKeMNjaVC35r1qsK09QJhY";
_url += "&redirect_uri=https://pixel-composer.com/verify";
_url += "&scope=identity campaigns.members";
_url += "&state=" + string(port);
url_open(_url);
} else {
status = -1;
txt = "Cannot connect to Patreon, please try again.";
}
}
}
function submit_code(code) {
code = string_trim(code);
2024-11-16 07:01:14 +01:00
2024-11-20 09:05:51 +01:00
var _header = ds_map_create();
_header[? "User-Agent"] = "pixelcomposer";
_header[? "Content-Type"] = "application/x-www-form-urlencoded";
var _content = $"code={code}";
_content += $"&grant_type=authorization_code";
_content += $"&client_id=oZ1PNvUY61uH0FiA7ZPMBy77Xau3Ok9tfvsT_Y8DQwyKeMNjaVC35r1qsK09QJhY";
_content += $"&client_secret=winWb1rAgSGUn9JBXxCjWqIb7EYkfYWO9j4nK_Stmg4W_wtKbdE30ckqvcwcCn2o";
_content += $"&redirect_uri=https://pixel-composer.com/verify";
2024-11-20 09:05:51 +01:00
req_patreon = http_request("https://www.patreon.com/api/oauth2/token", "POST", _header, _content);
ds_map_destroy(_header);
page = 1;
2024-11-14 09:19:03 +01:00
}
2024-11-14 03:41:05 +01:00
#endregion