示例#1
0
        private void signOnBtn_Click(object sender, EventArgs e)
        {
            tmpLocation = selectLocation.Text;

            Properties.Settings.Default.connType = tmpLocation;
            Properties.Settings.Default.Save();

            if (screenName.Text == "New User" || screenName.Text == "Existing Member")
            {
                signup_form suf = new signup_form();
                suf.Owner     = this;
                suf.MdiParent = MdiParent;
                suf.Show();
            }
            else if (screenName.Text == "Guest")
            {
                tmpUsername = "******";
                Close();
            }
            else
            {
                if (RestAPI.loginAccount(screenName.Text, passBox.Text))
                {
                    Close();
                }
                else
                {
                    MessageBox.Show("Account either doesn't exist, or incorrect password.");
                }
            }
        }
示例#2
0
        public static List <string> getBuddyList(string user = "", string pass = "")
        {
            int              userID         = Convert.ToInt32(RestAPI.getAccInfo("id", user, pass));
            List <string>    buddies        = new List <string>();
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                SQLiteCommand command = new SQLiteCommand(m_dbConnection);
                //Debug.WriteLine("getting email info with id:" + userID);
                command.CommandText = "SELECT count(*) FROM buddy_list WHERE userid = '" + userID + "'";
                int count = Convert.ToInt32(command.ExecuteScalar());
                if (count > 0)
                {
                    command.CommandText = "SELECT * FROM buddy_list WHERE userid = '" + userID + "'";

                    SQLiteDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        buddies.Add(reader["buddy_name"].ToString());
                    }
                }
            }
            catch (SQLiteException ex)
            {
                Debug.WriteLine("SQLite err " + ex.ErrorCode);
            }

            m_dbConnection.Close();
            return(buddies);
        }
示例#3
0
        public static int addFavorite(string url, string URLname)
        {
            int code = 0;

            int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            string sql = "INSERT INTO favorites (userid, url, name) VALUES ('" + userID + "', '" + url + "', @URLname)";

            try
            {
                SQLiteCommand     command    = new SQLiteCommand(sql, m_dbConnection);
                SQLiteParameter[] parameters = { new SQLiteParameter("URLname", URLname) };
                command.Parameters.AddRange(parameters);
                command.ExecuteNonQuery();
            }
            catch (SQLiteException ex)
            {
                code = ex.ErrorCode;
            }

            m_dbConnection.Close();
            return(code);
        }
示例#4
0
        public static int deleteHistory(string url)
        {
            int code   = 0;
            int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                SQLiteCommand command = new SQLiteCommand(m_dbConnection);
                //Debug.WriteLine("getting email info with id:" + userID);
                command.CommandText = "SELECT count(*) FROM history WHERE userid = '" + userID + "' AND url = '" + url + "'";
                int count = Convert.ToInt32(command.ExecuteScalar());
                if (count > 0)
                {
                    command.CommandText = "DELETE FROM history WHERE userid = '" + userID + "' AND url = '" + url + "'";
                    SQLiteDataReader reader = command.ExecuteReader();
                }
            }
            catch (SQLiteException ex)
            {
                code = ex.ErrorCode;
            }

            m_dbConnection.Close();
            return(code);
        }
示例#5
0
        /// <summary>
        /// Key = URL, Value = Name
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, string> getFavoritesList()
        {
            int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));
            Dictionary <string, string> favorites      = new Dictionary <string, string>();
            SQLiteConnection            m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                SQLiteCommand command = new SQLiteCommand(m_dbConnection);
                command.CommandText = "SELECT count(*) FROM favorites WHERE userid = '" + userID + "'";
                int count = Convert.ToInt32(command.ExecuteScalar());
                if (count > 0)
                {
                    command.CommandText = "SELECT * FROM favorites WHERE userid = '" + userID + "'";

                    SQLiteDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        favorites.Add(reader["url"].ToString(), reader["name"].ToString());
                    }
                }
            }
            catch (SQLiteException ex)
            {
                Debug.WriteLine("SQLite err " + ex.ErrorCode);
            }

            m_dbConnection.Close();
            return(favorites);
        }
示例#6
0
 private void sendBtn_Click(object sender, EventArgs e)
 {
     if (RestAPI.addBuddy(nameTextBox.Text))
     {
         MessageBox.Show("Buddy Added!");
     }
     else
     {
         MessageBox.Show("Error: Buddy not added.");
     }
     Close();
 }
示例#7
0
        private void nextBtn_Click(object sender, EventArgs e)
        {
            if (newAOL.Checked)
            {
                panel2.SendToBack();
                panel3.BringToFront();
            }
            else // recover acc from DB API
            {
                string user = recoverUser.Text;
                string pass = recoverPass.Text;
                if (RestAPI.loginAccount(user, pass))
                {
                    string        fn         = RestAPI.getAccInfo("fullname", user, pass);
                    int           code       = sqlite_accounts.createAcc(user, fn);
                    List <string> tmpBuddies = sqlite_accounts.getBuddyList(user, pass);

                    if (code == 0)
                    {
                        foreach (var t in RestAPI.getBuddyList(user, pass))
                        {
                            if (!tmpBuddies.Contains(t)) // if we deleted an account to re-create it, but we had our buddy list still there, prevent a crash
                            {
                                sqlite_accounts.addBuddy(t.ToString());
                            }
                        }
                        MessageBox.Show("Account has been added. Welcome back!", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Close();
                    }
                    else
                    {
                        if (code == 19)
                        {
                            MessageBox.Show("Account already exists.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show("SQLite error " + code.ToString() + " on account creation.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Account not found.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Get history to add to address bar drop down list
        /// </summary>
        /// <returns></returns>
        public static List <string> getHistory()
        {
            if (RestAPI.getAccInfo("id") == "")
            {
                return new List <string> {
                           null
                }
            }
            ;                                     // error, account not found. Prevent crash.

            List <string>    history        = new List <string>();
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));

                SQLiteCommand command = new SQLiteCommand(m_dbConnection);
                //Debug.WriteLine("getting email info with id:" + userID);
                command.CommandText = "SELECT count(*) FROM history WHERE userid = '" + userID + "'";
                int count = Convert.ToInt32(command.ExecuteScalar());
                if (count > 0)
                {
                    command.CommandText = "SELECT * FROM history WHERE userid = '" + userID + "'";

                    SQLiteDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        history.Add(reader["url"].ToString());
                    }
                }
            }
            catch (SQLiteException ex)
            {
                Debug.WriteLine("SQLite err " + ex.ErrorCode);
            }
            catch
            {
                Debug.WriteLine("unknown error in getHistory()");
            }

            m_dbConnection.Close();
            return(history);
        }
示例#9
0
        private void registerBtn_Click(object sender, EventArgs e)
        {
            if (username.Text == "Guest")
            {
                MessageBox.Show("You cannot use the username Guest.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (RestAPI.createAccount(username.Text, password.Text, fullname.Text))
            {
                MessageBox.Show("Account has been created. Welcome!", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
            }
            else
            {
                MessageBox.Show("Account creation has failed for an unknown reason." + Environment.NewLine + "Please email [email protected]", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#10
0
        /// <summary>
        /// Check if history URL is already present, 0 = failed
        /// </summary>
        /// <param name="url">URL</param>
        /// <returns></returns>
        public static int findHisory(string url)
        {
            int foundHistory = 0;
            int userID       = Convert.ToInt32(RestAPI.getAccInfo("id"));
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            string           sql     = "SELECT * FROM history WHERE userid = '" + userID + "' AND url = '" + url + "'";
            SQLiteCommand    command = new SQLiteCommand(sql, m_dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                foundHistory++;
            }

            m_dbConnection.Close();
            return(foundHistory);
        }
示例#11
0
        public static bool addBuddy(string user)
        {
            bool             good           = false;
            int              userID         = Convert.ToInt32(RestAPI.getAccInfo("id"));
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                SQLiteCommand cmd = new SQLiteCommand(m_dbConnection);
                cmd.CommandText = "SELECT count(*) FROM buddy_list WHERE userid = '" + userID + "' AND buddy_name = '" + user + "'";
                int count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count > 0)
                {
                    return(false); // user already exists
                }
            }
            catch (SQLiteException ex)
            {
                Debug.WriteLine("SQLite ERR: " + ex.ErrorCode);
            }

            string sql = "INSERT INTO buddy_list (userid, buddy_name) VALUES ('" + userID + "', '" + user + "')";

            try
            {
                SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                command.ExecuteNonQuery();
                chat.buddyStatus.Add(user, false); // put them immediately into our buddy list
                good = true;
            }
            catch (SQLiteException ex)
            {
                Debug.WriteLine("SQLite ERR: " + ex.ErrorCode);
            }

            m_dbConnection.Close();
            return(good);
        }
示例#12
0
        /*public static string[] getEmailInfo()
         * {
         *  int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));
         *  //Debug.WriteLine("tmpUsername:"******" tmpPassword:"******" userID:" + userID);
         *  string[] info = new string[7];
         *  SQLiteConnection m_dbConnection = openDB();
         *  m_dbConnection.Open();
         *
         *  try
         *  {
         *      SQLiteCommand command = new SQLiteCommand(m_dbConnection);
         *      //Debug.WriteLine("getting email info with id:" + userID);
         *      command.CommandText = "SELECT count(*) FROM email_accounts WHERE user_id = '" + userID + "'";
         *      int count = Convert.ToInt32(command.ExecuteScalar());
         *      if (count > 0)
         *      {
         *          command.CommandText = "SELECT * FROM email_accounts WHERE user_id = '" + userID + "'";
         *
         *          SQLiteDataReader reader = command.ExecuteReader();
         *          while (reader.Read())
         *          {
         *              info[0] = reader["address"].ToString();
         *              info[1] = reader["password"].ToString();
         *              info[2] = reader["imap"].ToString();
         *              info[3] = reader["imap_port"].ToString();
         *              info[4] = reader["smtp"].ToString();
         *              info[5] = reader["smtp_port"].ToString();
         *              info[6] = reader["ssl"].ToString();
         *          }
         *      }
         *      else
         *      {
         *          Debug.WriteLine("No email acc created yet.");
         *          info = new string[] { "", "", "", "993", "", "465", "1" };
         *      }
         *  }
         *  catch (SQLiteException ex)
         *  {
         *      Debug.WriteLine("SQLite err " + ex.ErrorCode);
         *  }
         *
         *  m_dbConnection.Close();
         *  return info;
         * }*/

        public static int emailAcc(string address, string pass, string imap, int imapPort, string smtp, int smtpPort, int ssl)
        {
            int code   = 0;
            int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));

            Debug.WriteLine("userID:" + userID);
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();

            try
            {
                SQLiteCommand command = new SQLiteCommand(m_dbConnection);

                command.CommandText = "SELECT count(*) FROM email_accounts WHERE user_id = '" + userID + "'";
                int count = Convert.ToInt32(command.ExecuteScalar());
                if (count == 0)
                {
                    Debug.WriteLine("Email acc doesnt exists, inserting...");
                    command.CommandText = "INSERT INTO email_accounts (user_id, address, password, imap, imap_port, smtp, smtp_port, ssl) VALUES ('" + userID + "', '" + address + "', @encPass, '" + imap + "', '" + imapPort + "', '" + smtp + "', '" + smtpPort + "', '" + ssl + "')";
                }
                else
                {
                    Debug.WriteLine("Email acc exists, updating...");
                    command.CommandText = "UPDATE email_accounts SET address = '" + address + "', password = @encPass, imap = '" + imap + "', imap_port = '" + imapPort + "', smtp = '" + smtp + "', smtp_port = '" + smtpPort + "', ssl = '" + ssl + "' WHERE user_id = '" + userID + "'";
                }
                //command.Parameters.AddWithValue("encPass", encryptedPass); // encrypt this or something in the future
                command.Parameters.AddWithValue("encPass", pass);
                command.ExecuteNonQuery();
            }
            catch (SQLiteException ex)
            {
                code = ex.ErrorCode;
            }

            m_dbConnection.Close();
            return(code);
        }
示例#13
0
        /// <summary>
        /// Add history URL to address bar
        /// </summary>
        /// <param name="url">Address bar URL</param>
        /// <returns></returns>
        public static int addHistory(string url)
        {
            int code = 0;

            url = url.ToLower();
            url = url.Replace("http://", "");
            url = url.Replace("https://", "");

            if (url.EndsWith("/"))
            {
                url = url.Remove(url.Length - 1);
            }

            if (findHisory(url) > 0)
            {
                return(999);
            }

            int userID = Convert.ToInt32(RestAPI.getAccInfo("id"));
            SQLiteConnection m_dbConnection = openDB();

            m_dbConnection.Open();
            long   timeStamp = DateTime.Now.ToFileTime();
            string sql       = "INSERT INTO history (userid, url, date) VALUES ('" + userID + "', '" + url + "', '" + timeStamp + "')";

            try
            {
                SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
                command.ExecuteNonQuery();
            }
            catch (SQLiteException ex)
            {
                code = ex.ErrorCode;
            }

            m_dbConnection.Close();
            return(code);
        }
示例#14
0
 private void updateFNBtn_Click(object sender, EventArgs e)
 {
     RestAPI.updateFullName(fullnameBox.Text);
 }