/// <summary> /// Get user google token and replace it with temporally /// </summary> private void ChangeGoogleToken() { if (!WasGLogin) { return; } string tokenDir = GUtil.TokenDirectory; GUtil.RemoveGoogleToken(OldUser); try { string[] files = Directory.GetFiles(tempDir); var tokenNames = files.Where(f => f.Contains(ChangingUser.Username)); if (tokenNames.ToList().Count != 0) { string tokenNameFullPath = files.Where(f => f.Contains(ChangingUser.Username)).First(); string tokenName = tokenNameFullPath.Substring(tempDir.Length + 1); File.Copy(tokenNameFullPath, Path.Combine(tokenDir, tokenName)); } } catch (IOException e) { MessageBox.Show(string.Format("Token does not add, because '{0}', please try login to Google again", e.Message), "Error", MessageBoxButtons.OK); Form.GoogleButton.BackColor = System.Drawing.Color.OrangeRed; throw new InvalidOperationException(); } }
/// <summary> /// Delete user and google token from database /// </summary> public void DeleteUser() { DialogResult result = MessageBox.Show( string.Format("Do you want to really delete user {0}?", user.ToString()), "Delete User", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { lock (DataDatabase.userDatabase) { TCCredentialsManager.Delete(user.Username); DataDatabase.userDatabase.Remove(user); GUtil.RemoveGoogleToken(user); DataDatabase.RefreshListBox(); DataDatabase.SaveChanges(); } } }