Exemplo n.º 1
0
        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");
        }