private static void OnLoginSuccessful(AwfulLoginClient sender, string username, List<Cookie> cookie) { if (LoginSuccessful != null) { var user = new UserMetadata() { Username = username, Cookies = cookie }; LoginSuccessful(sender, new LoginEventArgs(user)); } }
private static void OnLoginSuccessful(AwfulLoginClient sender, string username, List <Cookie> cookie) { if (LoginSuccessful != null) { var user = new UserMetadata() { Username = username, Cookies = cookie }; LoginSuccessful(sender, new LoginEventArgs(user)); } }
private void Authenticate() { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "START Authenticate"); // first, check iso storage for cookies. // TODO: the above. // else, login using the supplied username and password. var login = new AwfulLoginClient(); int tries = 0; while (!AwfulWebRequest.CanAuthenticate && tries < 3) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "Authentication failed, attempting to try again..."); var loginArgs = OnLoginRequired(this); if (loginArgs == null) { throw new Exception("You need to attach an event listener for login required!"); } loginArgs.Signal.WaitOne(); if (loginArgs.Ignore) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "Ignoring authentication request. Moving on..."); return; } else if (!loginArgs.Cancel) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "User has input credentials; retrying..."); Username = loginArgs.Username; Password = loginArgs.Password; AwfulWebRequest.SetCookieJar(login.Authenticate(Username, Password)); tries++; } // automatically fail on cancel else { throw new Exception("User cancelled authentication."); } } // after too many tries throw the white flag. if (tries > 3) { throw new Exception("User failed to authenticate."); } AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "END Authenticate()"); }
public static bool Login(this UserMetadata user, string password) { var login = new AwfulLoginClient(); var cookies = login.Authenticate(user.Username, password); bool success = false; if (cookies != null) { success = true; user.Cookies = cookies; AwfulWebRequest.SetCredentials(user); } return(success); }
private void Authenticate() { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "START Authenticate"); // first, check iso storage for cookies. // TODO: the above. // else, login using the supplied username and password. var login = new AwfulLoginClient(); int tries = 0; while (!AwfulWebRequest.CanAuthenticate && tries < 3) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "Authentication failed, attempting to try again..."); var loginArgs = OnLoginRequired(this); if (loginArgs == null) throw new Exception("You need to attach an event listener for login required!"); loginArgs.Signal.WaitOne(); if (loginArgs.Ignore) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "Ignoring authentication request. Moving on..."); return; } else if (!loginArgs.Cancel) { AwfulDebugger.AddLog(this, AwfulDebugger.Level.Info, "User has input credentials; retrying..."); Username = loginArgs.Username; Password = loginArgs.Password; AwfulWebRequest.SetCookieJar(login.Authenticate(Username, Password)); tries++; } // automatically fail on cancel else throw new Exception("User cancelled authentication."); } // after too many tries throw the white flag. if (tries > 3) throw new Exception("User failed to authenticate."); AwfulDebugger.AddLog(this, AwfulDebugger.Level.Debug, "END Authenticate()"); }