public GetCredentialsPresenter(Game game, GetCredentialsEventArgs args) { OK = false; _args = args; View.Game = game; View.OnOK += View_OnOK; }
private bool GetUpdateCredentials(GetCredentialsEventArgs args) { GetCredentialsPresenter presenter = null; View.Invoke(() => { presenter = new GetCredentialsPresenter(Game.Current, args); presenter.ShowView(View); }); return(presenter.OK); }
public bool GetCredentials(GetCredentialsEventArgs args) { try { //check if this game has some stored details if (SettingsManager.Instance.Settings == null) { //if not, create some SettingsManager.Instance.Settings = new GameSettings { GameUid = _game.Uid, }; } args.UserName = SettingsManager.Instance.Settings.UserName; args.Password = SettingsManager.Instance.Settings.Password; //if we have no credentials or we have incorrect stored credentials if (string.IsNullOrEmpty(args.UserName) || _requiresManualIntervention) { if (_newCredentials(args)) { SettingsManager.Instance.Settings.UserName = args.UserName; SettingsManager.Instance.Settings.Password = args.Password; SettingsManager.Instance.Save(); return(true); } else { SettingsManager.Instance.Settings.UserName = string.Empty; SettingsManager.Instance.Settings.Password = string.Empty; SettingsManager.Instance.Save(); return(false); } } else { return(true); } } finally { //if this callback is called again, it must mean that the //credentials supplied were wrong so must be entered manually _requiresManualIntervention = true; } }
public Stream GetResponseStream(string uri, long progress, Func <GetCredentialsEventArgs, bool> getCredentials, out long contentLength) { var response = _responses[uri]; if (response == null) { throw new WebException("404 File not found"); } if (_credentials.ContainsKey(uri)) { bool hasValidCredentials = false; if (getCredentials != null) { var args = new GetCredentialsEventArgs(); while (getCredentials(args)) { if (_credentials[uri].Key == args.UserName && _credentials[uri].Value == args.Password) { hasValidCredentials = true; break; } } } if (!hasValidCredentials) { throw new WebException("401 Unauthorized"); } } contentLength = response.Data.Length; var stream = new MockStream(response.Data); if (response.OnRead != null) { stream.OnRead += response.OnRead; } if (response.OnWrite != null) { stream.OnWrite += response.OnWrite; } stream.Open(); stream.Seek(progress, SeekOrigin.Begin); return(stream); }
static void server_GetCredentials(object sender, GetCredentialsEventArgs<MyContext> eventArgs) { if (!accessKeysToUsers.ContainsKey(eventArgs.AccessKey)) { eventArgs.UserFound = false; eventArgs.ErrorMessage = "*Could not find user record"; return; } if (!accessKeysToEncryptionKeys.ContainsKey(eventArgs.AccessKey)) { eventArgs.UserFound = false; eventArgs.ErrorMessage = "*could not find encryption key"; return; } eventArgs.Context.User = accessKeysToUsers[eventArgs.AccessKey]; eventArgs.EncryptionKey = accessKeysToEncryptionKeys[eventArgs.AccessKey]; eventArgs.UserFound = true; }
private void server_GetCredentials(object sender, GetCredentialsEventArgs<WebHookContext> eventArgs) { if (String.IsNullOrEmpty(eventArgs.AccessKey)) { eventArgs.ErrorMessage = "Access Key not set."; return; } var context = eventArgs.Context; if (context == null) { throw new Exception("Context not set."); } context.Database = new RoomieDatabaseContext(); context.Computer = context.Database.Computers.Get(eventArgs.AccessKey); if (context.Computer == null) { eventArgs.ErrorMessage = "Computer not found."; eventArgs.UserFound = false; return; } if (context.User == null) { eventArgs.ErrorMessage = "User not found"; eventArgs.UserFound = false; return; } eventArgs.EncryptionKey = System.Text.Encoding.UTF8.GetBytes(context.Computer.EncryptionKey); eventArgs.UserFound = true; }