/// <summary> /// If Login successfully send user data to MainForm /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Timers.ElapsedEventArgs"/> instance containing the event data.</param> private void Timer1Elapsed(object sender, System.Timers.ElapsedEventArgs e) { this.timer1.Enabled = false; ((MainForm)Owner).cameThroughCorrectLogin = true; if (CacheController.Instance().UserSettings.ForumsAccount.Any(item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = this.GuestLogin.Checked }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.Close(); }
/// <summary> /// Auto login if User Credentials exists in Config file. /// if no Data show Login Form /// </summary> private void AutoLogin() { bool accountExists = false; var currentForumAccount = new ForumAccount(); foreach (var forumAccount in CacheController.Instance().UserSettings.ForumsAccount.Where( forumAccount => forumAccount.ForumURL.Equals(CacheController.Instance().UserSettings.CurrentForumUrl)).Where( forumAccount => !string.IsNullOrEmpty(forumAccount.UserName) && !string.IsNullOrEmpty(forumAccount.UserPassWord))) { currentForumAccount = forumAccount; accountExists = true; } if (accountExists) { if (currentForumAccount.GuestAccount) { this.cameThroughCorrectLogin = true; } else { LoginManager lgnMgr = new LoginManager(currentForumAccount.UserName, currentForumAccount.UserPassWord); if (lgnMgr.DoLogin(CacheController.Instance().UserSettings.CurrentForumUrl)) { this.cameThroughCorrectLogin = true; } else { Login frmLgn = new Login(); frmLgn.ShowDialog(this); DialogResult result = TopMostMessageBox.Show( this._ResourceManager.GetString("mbExit"), this._ResourceManager.GetString("mbExitTtl"), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Application.Exit(); } } } } else { Login frmLgn = new Login(); frmLgn.ShowDialog(this); Application.Exit(); } }
/// <summary> /// Tries to Login to the Forums /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void LoginBtnClick(object sender, EventArgs e) { if (this.ForumUrl.Text.StartsWith("http://")) { if (!this.ForumUrl.Text.EndsWith("/")) { this.ForumUrl.Text += "/"; } CacheController.Instance().UserSettings.CurrentForumUrl = this.ForumUrl.Text; } string welcomeString = this.rm.GetString("lblWelcome"), lblFailed = this.rm.GetString("lblFailed"); if (this.GuestLogin.Checked) { this.UserNameField.Text = "Guest"; this.PasswordField.Text = "Guest"; this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { // Encrypt Password this.PasswordField.Text = Utility.EncodePassword(this.PasswordField.Text).Replace("-", string.Empty).ToLower(); var loginManager = new LoginManager(this.UserNameField.Text, this.PasswordField.Text); if (loginManager.DoLogin(CacheController.Instance().UserSettings.CurrentForumUrl)) { this.label3.Text = string.Format("{0}{1}", welcomeString, this.UserNameField.Text); this.label3.ForeColor = Color.Green; this.LoginButton.Enabled = false; if ( CacheController.Instance().UserSettings.ForumsAccount.Any( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl)) { CacheController.Instance().UserSettings.ForumsAccount.RemoveAll( item => item.ForumURL == CacheController.Instance().UserSettings.CurrentForumUrl); } var forumsAccount = new ForumAccount { ForumURL = CacheController.Instance().UserSettings.CurrentForumUrl, UserName = this.UserNameField.Text, UserPassWord = this.PasswordField.Text, GuestAccount = false }; CacheController.Instance().UserSettings.ForumsAccount.Add(forumsAccount); CacheController.Instance().UserSettings.CurrentUserName = this.UserNameField.Text; this.timer1.Enabled = true; } else { this.label3.Text = lblFailed; this.label3.ForeColor = Color.Red; } } }