// TODO: handle captcha public static async Task <string?> Login( RuTrackerClientEnvironment env, string login, string password, CancellationToken ct = default ) { var req = ApiUtil.CreatePostReq( baseUrl: env.BaseUrl, url: "/forum/login.php", session: null, ("login_username", login), ("login_password", password), ("login", "вход") ); var resp = await env.HttpClient.SendAsync(req, ct).ConfigureAwait(false); var cookies = new CookieContainer(); var uri = new Uri(env.BaseUrl, "/forum/"); var cookieHeaders = resp.Headers.TryGetValues("Set-Cookie", out var res) ? res : new string[0]; foreach (var x in cookieHeaders) { cookies.SetCookies(uri, x); } var sessionCookie = cookies.GetCookies(uri)["bb_session"]; return(sessionCookie?.Value); }
public static async Task <RuTrackerClient> Login( string login, string password, RuTrackerClientEnvironment?env = default, CancellationToken ct = default ) { env ??= RuTrackerClientEnvironment.CreateDefault(); var session = await RuTrackerAuthorizer.Login(env, login, password, ct); return(session == null ? throw new RuTrackerClientAuthException("Invalid login/password.") : new RuTrackerClient(env, session)); }
public RuTrackerClient(RuTrackerClientEnvironment env, string session) { _env = env; _session = session; }