108 lines
3.5 KiB
C#
108 lines
3.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using Microsoft.Web.WebView2.WinForms;
|
|
using Microsoft.Web.WebView2.Core;
|
|
|
|
namespace WinFormsApp1
|
|
{
|
|
public partial class ChaturbateLoginForm : Form
|
|
{
|
|
private readonly WebView2 _webView;
|
|
private readonly Button _btnDone;
|
|
|
|
// Einzeln gespeicherte Werte
|
|
public string? CfClearance { get; private set; }
|
|
public string? SessionId { get; private set; }
|
|
|
|
// Kombinierter String für den Recorder:
|
|
// "cf_clearance=...; sessionid=..."
|
|
public string? SessionCookie { get; private set; }
|
|
|
|
public ChaturbateLoginForm()
|
|
{
|
|
Text = "Chaturbate Login";
|
|
Width = 1000;
|
|
Height = 800;
|
|
|
|
_webView = new WebView2
|
|
{
|
|
Dock = DockStyle.Fill
|
|
};
|
|
|
|
_btnDone = new Button
|
|
{
|
|
Text = "Login fertig",
|
|
Dock = DockStyle.Bottom,
|
|
Height = 40
|
|
};
|
|
_btnDone.Click += BtnDone_Click;
|
|
|
|
Controls.Add(_webView);
|
|
Controls.Add(_btnDone);
|
|
|
|
Shown += ChaturbateLoginForm_Shown;
|
|
}
|
|
|
|
private async void ChaturbateLoginForm_Shown(object? sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
await _webView.EnsureCoreWebView2Async();
|
|
_webView.CoreWebView2.Navigate("https://chaturbate.com/");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Browser konnte nicht initialisiert werden:\n" + ex.Message,
|
|
"Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private async void BtnDone_Click(object? sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (_webView.CoreWebView2 == null)
|
|
{
|
|
MessageBox.Show("Browser noch nicht bereit.");
|
|
return;
|
|
}
|
|
|
|
CoreWebView2CookieManager cookieManager = _webView.CoreWebView2.CookieManager;
|
|
var cookies = await cookieManager.GetCookiesAsync("https://chaturbate.com/");
|
|
|
|
// beide Cookies holen
|
|
var cfClearance = cookies.FirstOrDefault(c => c.Name == "cf_clearance");
|
|
var sessionId = cookies.FirstOrDefault(c => c.Name == "sessionid");
|
|
|
|
if (cfClearance == null || sessionId == null)
|
|
{
|
|
MessageBox.Show(
|
|
"Die nötigen Cookies wurden nicht gefunden.\n\n" +
|
|
"Stelle sicher, dass du auf Chaturbate eingeloggt bist\n" +
|
|
"und ggf. die Seite einmal neu lädst.",
|
|
"Hinweis",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
// Einzelwerte speichern
|
|
CfClearance = cfClearance.Value;
|
|
SessionId = sessionId.Value;
|
|
|
|
// kombinierten Header bauen, wie du ihn an recorder.exe übergibst
|
|
SessionCookie = $"cf_clearance={CfClearance}; sessionid={SessionId}";
|
|
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("Fehler beim Lesen der Cookies:\n" + ex.Message,
|
|
"Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|