internal FrmMain(ClientCredential credential, DesktopClientSettings settings, ExtensionManager extensionManager, StyleManager styleManager) { this.credential = credential; this.settings = settings; this.extensionManager = extensionManager; this.styleManager = styleManager; this.InitializeComponent(); this.InitializeHtmlEditor(); this.InitializeExtensions(); this.Text = string.Format("CloudNotes - {0}@{1}", credential.UserName, credential.ServerUri); // Fix the main form size var currentScreen = Screen.FromControl(this); this.Width = Convert.ToInt32(currentScreen.Bounds.Width * 0.75F); this.Height = Convert.ToInt32(currentScreen.Bounds.Height * 0.75F); this.Location = new Point(currentScreen.Bounds.X + (currentScreen.Bounds.Width - this.Width)/2, currentScreen.Bounds.Y + (currentScreen.Bounds.Height - this.Height)/2); this.splitContainer.SplitterDistance = Convert.ToInt32(this.Width*0.25F); this.notifyIcon.Text = string.Format("CloudNotes - {0}", credential.UserName); this.notesNode = this.tvNotes.Nodes.Add("NotesRoot", Resources.NotesNodeTitle, 0, 0); this.trashNode = this.tvNotes.Nodes.Add("TrashRoot", Resources.TrashNodeTitle, 1, 1); Application.Idle += (s, e) => { this.slblStatus.Text = Resources.Ready; }; }
/// <summary> /// Initializes a new instance of the <see cref="ServiceProxy"/> class. /// </summary> /// <param name="clientCredential">The client credential.</param> public ServiceProxy(ClientCredential clientCredential) : base(new HttpClientHandler { Credentials = new NetworkCredential(clientCredential.UserName, clientCredential.Password) }, true) { this.BaseAddress = new Uri( clientCredential.ServerUri.EndsWith("/") ? clientCredential.ServerUri : clientCredential.ServerUri + "/"); this.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
internal FrmMain(ClientCredential credential, DesktopClientSettings settings, ExtensionManager extensionManager) { this.credential = credential; this.settings = settings; this.extensionManager = extensionManager; this.InitializeComponent(); this.InitializeHtmlEditor(); this.InitializeExtensions(); this.Text = string.Format("CloudNotes - {0}@{1}", credential.UserName, credential.ServerUri); this.notifyIcon.Text = string.Format("CloudNotes - {0}", credential.UserName); this.notesNode = this.tvNotes.Nodes.Add("NotesRoot", Resources.NotesNodeTitle, 0, 0); this.trashNode = this.tvNotes.Nodes.Add("TrashRoot", Resources.TrashNodeTitle, 1, 1); Application.Idle += (s, e) => { this.slblStatus.Text = Resources.Ready; }; }
public LocalStorageAccessProxy(ClientCredential credential) : base(credential) { }
public FrmChangePassword(ClientCredential credential) { InitializeComponent(); this.clientCredential = credential; }
private void btnOK_Click(object sender, EventArgs e) { var hasError = false; this.errorProvider.Clear(); if (string.IsNullOrWhiteSpace(cbUserName.Text)) { hasError = true; errorProvider.SetError(cbUserName, Resources.UserNameRequired); } if (string.IsNullOrWhiteSpace(txtPassword.Text)) { hasError = true; errorProvider.SetError(txtPassword, Resources.PasswordRequired); } if (string.IsNullOrWhiteSpace(cbServer.Text)) { hasError = true; errorProvider.SetError(cbServer, Resources.ServerRequired); } if (hasError) { // prevent the dialog from closing this.DialogResult = DialogResult.None; return; } Credential = new ClientCredential { Password = txtPassword.Text, ServerUri = cbServer.Text.Trim(), UserName = cbUserName.Text.Trim() }; // reset the IsSelected property for users profile.UserProfiles.ForEach(up => up.IsSelected = false); var userProfile = profile.UserProfiles.FirstOrDefault(p => p.UserName == Credential.UserName); var encryptedPassword = crypto.Encrypt(Credential.Password); if (userProfile == null) { userProfile = new UserProfile { AutoLogin = chkAutomaticLogin.Checked, IsSelected = true, Password = encryptedPassword, RememberPassword = chkRememberPassword.Checked, UserName = Credential.UserName }; profile.UserProfiles.Add(userProfile); } else { userProfile.AutoLogin = chkAutomaticLogin.Checked; userProfile.IsSelected = true; userProfile.Password = encryptedPassword; userProfile.RememberPassword = chkRememberPassword.Checked; userProfile.UserName = Credential.UserName; } // reset the IsSelected property for servers profile.ServerProfiles.ForEach(sp => sp.IsSelected = false); var serverProfile = profile.ServerProfiles.FirstOrDefault(p => p.Uri == Credential.ServerUri); if (serverProfile == null) { serverProfile = new ServerProfile(Credential.ServerUri) {IsSelected = true}; profile.ServerProfiles.Add(serverProfile); } else { serverProfile.IsSelected = true; serverProfile.Uri = cbServer.Text; } try { cbUserName.Enabled = false; txtPassword.Enabled = false; cbServer.Enabled = false; btnOK.Enabled = false; this.Cursor = Cursors.WaitCursor; using (var proxy = new ServiceProxy(Credential)) { var result = proxy.PostAsJsonAsync( "api/users/authenticate", new { Credential.UserName, EncodedPassword = Convert.ToBase64String( Encoding.ASCII.GetBytes(Crypto.ComputeHash(Credential.Password, Credential.UserName))) }).Result; switch (result.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.Forbidden: MessageBox.Show( Resources.IncorrectUserNamePassword, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; default: dynamic message = JsonConvert.DeserializeObject(result.Content.ReadAsStringAsync().Result); MessageBox.Show( message.ExceptionMessage.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } Profile.Save(fileName, profile); } catch (Exception ex) { FrmExceptionDialog.ShowException(ex); this.DialogResult = DialogResult.None; } finally { cbUserName.Enabled = true; txtPassword.Enabled = true; cbServer.Enabled = true; btnOK.Enabled = true; this.Cursor = Cursors.Default; } }
public static ClientCredential Login(Action cancelCallback, DesktopClientSettings settings, bool alwaysShowDialog = false) { var crypto = Crypto.CreateDefaultCrypto(); Profile profile; var profileFile = Directories.GetFullName(Constants.ProfileFileName); var profileDirectory = Path.GetDirectoryName(profileFile); if (string.IsNullOrEmpty(profileDirectory)) throw new InvalidOperationException("The directory name is invalid (empty)."); if (!Directory.Exists(profileDirectory)) { Directory.CreateDirectory(profileDirectory); profile = new Profile(); } else { if (File.Exists(profileFile)) { try { profile = Profile.Load(profileFile); } catch { profile = new Profile(); } } else { profile = new Profile(); } } ClientCredential credential = null; var selectedUserProfile = profile.UserProfiles.FirstOrDefault(p => p.IsSelected); var selectedServerProfile = profile.ServerProfiles.FirstOrDefault(p => p.IsSelected); if (alwaysShowDialog || selectedUserProfile == null || !selectedUserProfile.AutoLogin) { var loginForm = new FrmLogin(profile, settings, profileFile); var dialogResult = loginForm.ShowDialog(); if (dialogResult == DialogResult.OK) { credential = loginForm.Credential; } else { cancelCallback(); } } else { credential = new ClientCredential { Password = crypto.Decrypt(selectedUserProfile.Password), ServerUri = selectedServerProfile == null ? string.Empty : selectedServerProfile.Uri, UserName = selectedUserProfile.UserName }; } return credential; }