protected void EnterButton_Click(object sender, EventArgs e) { String user = TextBox1.Text; String password = TextBox2.Text; if (String.IsNullOrWhiteSpace(user) || String.IsNullOrWhiteSpace(password)) { ErrorLabel.Text = "Please enter your username and password"; ErrorLabel.Visible = true; ErrorLabelUpdatePanel.Update(); return; } List <Record> userList = DBConnectionHelper.ReadUserRecords(); Record userRecord = null; bool found = false; foreach (Record record in userList) { if (record.Entries[DBConnectionHelper._columnName].ToLower() == user.ToLower()) { found = true; userRecord = record; break; } } if (!found) { ErrorLabel.Text = "Username not found. Please create a new user"; ErrorLabel.Visible = true; ErrorLabelUpdatePanel.Update(); return; } // ReadRecords(); if (userRecord.Entries[DBConnectionHelper._columPasword] != FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5")) { ErrorLabel.Text = "Username and password do not match"; ErrorLabel.Visible = true; ErrorLabelUpdatePanel.Update(); return; } //Guid guid = Guid.NewGuid(); Guid guid = new Guid(userRecord.Entries[DBConnectionHelper._columnGuid]); Session["Username"] = userRecord.Entries[DBConnectionHelper._columnName]; Session["Guid"] = guid; List <Chatter> chatters = ((List <Chatter>)Application.Get("Chatters")); Chatter chatter = new Chatter(guid, userRecord.Entries[DBConnectionHelper._columnName]); chatter.intId = Convert.ToInt32(userRecord.Entries["ID"]); chatter.email = userRecord.Entries[DBConnectionHelper._columnEmail]; chatter.buddyList = DBConnectionHelper.ReadBuddiesFromUser(chatter.intId); foreach (int i in chatter.buddyList) { foreach (Record record in userList) { if (Convert.ToInt32(record.Entries["ID"]) == i) { //Guid g = new Guid(record.Entries[DBConnectionHelper._columnGuid]); foreach (Chatter c in chatters) { //if (c.Id.Equals(g)) { if (c.intId == Convert.ToInt32(record.Entries["ID"])) { chatter.myBuddies.Add(c); goto CONT; } } } } CONT: continue; } List <Chatter> doubleChatters = new List <Chatter>(); foreach (Chatter loggedInChatter in chatters) { if (loggedInChatter.intId.Equals(chatter.intId)) { doubleChatters.Add(loggedInChatter); } } foreach (Chatter c in doubleChatters) { chatters.Remove(c); c.LeaveAll(); } chatters.Add(chatter); try { //TODO: throws exception after logging in and leaving for 2 times... ReadOnlyCollection <Chat> tmp = Chat.ActiveChats(); chatter.Join(tmp[0]); } catch (ArgumentOutOfRangeException x) { } Application.Add("Chatters", chatters); Response.Redirect("Chat.aspx"); }
protected void EnterButton_Click(object sender, EventArgs e) { if (!ValidateData()) { ErrorLabelUpdatePanel.Update(); return; } String username = UsernameBox.Text; String email = EmailBox.Text; String pw1 = PasswordBox1.Text; List <Record> list = DBConnectionHelper.ReadUserRecords(); foreach (Record record in list) { if (record.Entries[DBConnectionHelper._columnName].ToLower() == username.ToLower()) { ErrorLabel.Text = "Username not available"; ErrorLabel.Visible = true; ErrorLabelUpdatePanel.Update(); return; } } String pwHash = FormsAuthentication.HashPasswordForStoringInConfigFile(pw1, "md5"); Guid guid = Guid.NewGuid(); String sql = DBConnectionHelper.MakeSQLInsertQuery(DBConnectionHelper._tableUser, new String[] { DBConnectionHelper._columnName, DBConnectionHelper._columPasword, DBConnectionHelper._columnEmail, DBConnectionHelper._columnGuid }, new String[] { username, pwHash, email, guid.ToString() }); DBConnectionHelper.ExecuteNonQuery(sql); Thread.Sleep(1000); list = DBConnectionHelper.ReadUserRecords(); Record userRecord = null; foreach (Record record in list) { if (record.Entries[DBConnectionHelper._columnName] == username) { userRecord = record; break; } } //Guid guid = Guid.NewGuid(); Session["Username"] = userRecord.Entries[DBConnectionHelper._columnName]; Session["Guid"] = guid; List <Chatter> chatters = ((List <Chatter>)Application.Get("Chatters")); Chatter chatter = new Chatter(guid, userRecord.Entries[DBConnectionHelper._columnName]); chatter.intId = Convert.ToInt32(userRecord.Entries["ID"]); chatter.email = userRecord.Entries[DBConnectionHelper._columnEmail]; chatter.buddyList = DBConnectionHelper.ReadBuddiesFromUser(chatter.intId); foreach (int i in chatter.buddyList) { foreach (Record record in list) { if (Convert.ToInt32(record.Entries["ID"]) == i) { //Guid g = new Guid(record.Entries[DBConnectionHelper._columnGuid]); foreach (Chatter c in chatters) { //if (c.Id.Equals(g)) { if (c.intId == Convert.ToInt32(record.Entries["ID"])) { chatter.myBuddies.Add(c); goto CONT; } } } } CONT: continue; } chatters.Add(chatter); chatter.Join(Chat.ActiveChats()[0]); Application.Add("Chatters", chatters); Response.Redirect("Chat.aspx"); }