/// <summary> /// Constructor for this class. /// Initialises and displays the form. /// Checks if valid user credentials are stored for automatic login. If so, closes this form and opens an instance of Listener. /// Else, shows the login panel. /// </summary> public Dashboard() { InitializeComponent(); this.Visible = false; if (DbConnect.CheckLogin(Properties.Settings.Default.LastUsername, Properties.Settings.Default.LastPassword)) // if (1 == 2) // For testing purposes { this.Hide(); DbConnect.SetClient(Properties.Settings.Default.LastUsername); Listener li = new Listener(); li.ShowDialog(); } else { this.Visible = true; pnl_Login.Show(); } }
/// <summary> /// Constructor for this class. /// Initialises and displays the form. /// Checks if valid user credentials are stored for automatic login. If so, closes this form and opens an instance of Listener. /// Else, shows the login panel. /// </summary> public Dashboard() { InitializeComponent(); this.Visible = false; if (Properties.Settings.Default.LastUsername != "*****@*****.**" && DbConnect.CheckLogin(Properties.Settings.Default.LastUsername, Properties.Settings.Default.LastPassword)) { Account acc = DbConnect.GetAccount(Properties.Settings.Default.LastUsername); Notification n = new Notification("Welcome, " + acc.Name + "!", false); this.Hide(); DbConnect.SetClient(Properties.Settings.Default.LastUsername); Listener li = new Listener(); li.ShowDialog(); } else { this.Visible = true; pnl_Login.Show(); } }
/// <summary> /// Attempts to log in using the input credentials. If successful, hides this form and creates an instance of Listener. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Login_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(emailBox.Text) || String.IsNullOrEmpty(passBox.Text) || emailBox.Text == "*****@*****.**") { MessageBox.Show("You must fill in all fields!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (DbConnect.Login(emailBox.Text, passBox.Text)) { DbConnect.SetClient(emailBox.Text); WindowState = FormWindowState.Minimized; Properties.Settings.Default.LastUsername = emailBox.Text; Properties.Settings.Default.LastPassword = DbConnect.GetPassHash(emailBox.Text); Properties.Settings.Default.Save(); Notification n = new Notification("Welcome to Donatello, ", false); Listener li = new Listener(); li.Show(); this.Hide(); } else { MessageBox.Show("Incorrect username or password!"); } }
/// <summary> /// Verifies the user's input and if valid closes this form and starts an instance of Listener. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Start_Click(object sender, EventArgs e) { // Sort out dates string newDate = new_dobBox.Value.Year + "-" + new_dobBox.Value.Month + "-" + new_dobBox.Value.Day; // Create account object Account newAccount = new Account(newUsername, new_nameBox.Text, newPassword, newDate); // Get it into the database DbConnect.CreateAccount(newAccount); // Send a confirmation email message MailMessage mail = new MailMessage(); SmtpClient smtp = new SmtpClient("mail.kajp.im"); smtp.Port = 25; smtp.Credentials = new System.Net.NetworkCredential("donatello+kajp.im", "eijonu"); smtp.EnableSsl = false; mail.From = new MailAddress("*****@*****.**"); mail.To.Add(newUsername); mail.Subject = "Welcome to Donatello!"; mail.Body = "Thanks for joining Donatello"; try { //smtp.Send(mail); } catch (SmtpException) { // Oh well, not the end of the world if the email doesn't send. } Properties.Settings.Default.LastUsername = newUsername; Properties.Settings.Default.Save(); DbConnect.SetClient(newUsername); Listener li = new Listener(); li.ShowDialog(); this.Hide(); }