Esempio n. 1
0
        protected void lnkForgotPassword_Click(object sender, EventArgs e)
        {
            string username = txtLogUsername.Text;

            if (username == "")
            {
                smlLogUsernameHelp.InnerText = "Enter your username to retrieve password";
                return;
            }
            else
            {
                smlLogUsernameHelp.InnerText = "";
            }

            UserService.UserService proxy = new UserService.UserService();
            bool verify = proxy.ValidateUsername(username);

            if (verify)
            {
                smlLogUsernameHelp.InnerText = "Username is not registered";
                return;
            }

            UserService.User serviceUser = proxy.GetUser(username);
            User             recoverUser = new User(serviceUser.Username, serviceUser.FirstName, serviceUser.LastName,
                                                    serviceUser.Password, serviceUser.ProfileImage, serviceUser.HomeAddress, serviceUser.BillingAddress,
                                                    serviceUser.EmailAddress, serviceUser.Phone, serviceUser.SecretQuestions, serviceUser.SecretAnswers, serviceUser.Verified);

            int arrayIndex;
            int secretQuestion = recoverUser.GetRandomQuestion(out arrayIndex);

            lblPasswordSecretQuestion.InnerText = securityQuestions[secretQuestion];

            Session["UsernameRetrieve"]  = username;
            Session["RetrievedPassword"] = recoverUser.Password;
            Session["SecretAnswer"]      = recoverUser.GetSecretAnswer(arrayIndex);
            divLogin.Visible             = false;
            divForgotPassword.Visible    = true;
        }
Esempio n. 2
0
        protected void btnUpdateProfile_Click(object sender, EventArgs e)
        {
            string oldUsername    = Session["Username"].ToString();
            string username       = txtUsername.Text;
            string firstName      = txtFirstName.Text;
            string lastName       = txtLastName.Text;
            string homeAddress    = txtHomeAddress.Text;
            string billingAddress = txtBillingAddress.Text;
            long   phoneNumber;
            string profileImage      = txtImage.Text;
            string securityQuestion1 = txtSecurity1.Text;
            string securityQuestion2 = txtSecurity2.Text;
            string securityQuestion3 = txtSecurity3.Text;
            string secretAnswers     = securityQuestion1 + "," + securityQuestion2 + "," + securityQuestion3;
            string secretQuestions   = ddlSecurity1.SelectedValue + "," + ddlSecurity2.SelectedValue + "," + ddlSecurity3.SelectedValue;
            bool   good = true;

            if (username == "")
            {
                smlUsernameHelp.InnerText = "Please enter a username";
                good = false;
            }
            else
            {
                smlUsernameHelp.InnerText = "";
            }
            if (firstName == "")
            {
                smlFirstNameHelp.InnerText = "Please enter a first name";
                good = false;
            }
            else
            {
                smlFirstNameHelp.InnerText = "";
            }
            if (lastName == "")
            {
                smlLastNameHelp.InnerText = "Please enter a last name";
                good = false;
            }
            else
            {
                smlLastNameHelp.InnerText = "";
            }
            if (homeAddress == "")
            {
                smlHomeAddressHelp.InnerText = "Please enter a home address";
                good = false;
            }
            else
            {
                smlHomeAddressHelp.InnerText = "";
            }
            if (billingAddress == "")
            {
                smlBillingAddressHelp.InnerText = "Please enter a billing address";
                good = false;
            }
            else
            {
                smlBillingAddressHelp.InnerText = "";
            }
            if (!Int64.TryParse(txtPhone.Text, out phoneNumber))
            {
                smlPhoneHelp.InnerText = "Please enter a valid phone number";
                good = false;
            }
            else
            {
                smlPhoneHelp.InnerText = "";
            }
            if (profileImage == "")
            {
                smlImageHelp.InnerText = "Please enter a valid image URL";
                good = false;
            }
            else
            {
                smlImageHelp.InnerText = "";
            }
            if (securityQuestion1 == "")
            {
                smlQuestion1Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlQuestion1Help.InnerText = "";
            }
            if (securityQuestion2 == "")
            {
                smlQuestion2Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlQuestion2Help.InnerText = "";
            }
            if (securityQuestion3 == "")
            {
                smlQuestion3Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlQuestion3Help.InnerText = "";
            }

            if (!good)
            {
                return;
            }

            UserService.UserService proxy = new UserService.UserService();
            bool validateUsername         = proxy.ValidateUsername(username);

            if (!validateUsername && username != Session["Username"].ToString())
            {
                smlUsernameHelp.InnerText = "New username already taken, pick a new one";
                return;
            }
            else
            {
                smlUsernameHelp.InnerText = "";
            }

            UserService.User user1 = new UserService.User();
            user1.Username        = username;
            user1.FirstName       = firstName;
            user1.LastName        = lastName;
            user1.HomeAddress     = homeAddress;
            user1.BillingAddress  = billingAddress;
            user1.Phone           = phoneNumber.ToString();
            user1.ProfileImage    = profileImage;
            user1.SecretQuestions = secretQuestions;
            user1.SecretAnswers   = secretAnswers;


            bool updateUser = proxy.UpdateUser(oldUsername, user1);

            if (!updateUser)
            {
                smlUsernameHelp.InnerText = "User profile update failed, try again later";
                return;
            }
            else
            {
                smlUsernameHelp.InnerText = "";
                Session["Username"]       = username;
                if (Request.Cookies["Username"] != null)
                {
                    Response.Cookies["Username"].Value = username;
                }
            }

//            divMyProfile.Visible = true;
//            divUpdateProfile.Visible = false;
//            divPostContainer.Visible = true;

//            UpdatePanelProfile.Update();
            Response.Redirect("UserProfile.aspx");
        }
        protected void btnSendNewPm_Click(object sender, EventArgs e)
        {
            bool   good     = true;
            string reciever = txtRecipient.Text;

            if (reciever.Equals(currentUsername) || string.IsNullOrEmpty(reciever))
            {
                smlRecipientHelp.InnerText = "Must Have Recipient";
                good = false;
            }
            else
            {
                smlRecipientHelp.InnerText = "";
            }

            UserService.UserService proxy = new UserService.UserService();
            bool validateUsername         = proxy.ValidateUsername(reciever);

            if (validateUsername)
            {
                smlRecipientHelp.InnerText = "Recipient does not exist, check spelling or try a different user";
                good = false;
            }
            else
            {
                smlRecipientHelp.InnerText = "";
            }

            string subject = txtSubject.Text;

            if (string.IsNullOrEmpty(subject))
            {
                smlSubjectHelp.InnerText = "Invalid Subject";
                good = false;
            }
            else
            {
                smlSubjectHelp.InnerText = "";
            }

            string message = taPMText.InnerText;

            if (string.IsNullOrEmpty(message))
            {
                smlTextHelp.InnerText = "Must have a message";
                good = false;
            }
            else
            {
                smlTextHelp.InnerText = "";
            }

            if (!good)
            {
                return;
            }

            TwitterClassLibrary.Models.PrivateMessage pm = new
                                                           TwitterClassLibrary.Models.PrivateMessage(
                0, currentUsername, reciever, DateTime.Now.ToString(), subject, message
                );
            DBSerialize.WriteSerializedPM(pm);
            divComposeNewPM.Visible = false;
            lblNewPmError.Text      = "Message sent.";
        }
Esempio n. 4
0
        protected void btnSubmitRegister_Click(object sender, EventArgs e)
        {
            string username       = txtRegUsername.Text;
            string password       = txtRegPassword.Text;
            string firstName      = txtRegFirstName.Text;
            string lastName       = txtRegLastName.Text;
            string emailAddress   = txtRegEmail.Text;
            string homeAddress    = txtRegHomeAddress.Text;
            string billingAddress = txtRegBillingAddress.Text;
            long   phoneNumber;
            string profileImage      = txtRegImage.Text;
            string securityQuestion1 = txtRegSecurity1.Text;
            string securityQuestion2 = txtRegSecurity2.Text;
            string securityQuestion3 = txtRegSecurity3.Text;
            string secretAnswers     = securityQuestion1 + "," + securityQuestion2 + "," + securityQuestion3;
            string secretQuestions   = ddlSecurity1.SelectedValue + "," + ddlSecurity2.SelectedValue + "," + ddlSecurity3.SelectedValue;
            bool   good = true;

            MD5CryptoServiceProvider hasher = new MD5CryptoServiceProvider();
            string addSalt = string.Concat("ummm salty ", password);

            byte[] hash = hasher.ComputeHash(Encoding.Unicode.GetBytes(addSalt));

            if (username == "")
            {
                smlRegUsernameHelp.InnerText = "Please enter a username";
                good = false;
            }
            else
            {
                smlRegUsernameHelp.InnerText = "";
            }
            if (password == "")
            {
                smlRegPasswordHelp.InnerText = "Please enter a password";
                good = false;
            }
            else
            {
                smlRegPasswordHelp.InnerText = "";
            }
            if (firstName == "")
            {
                smlRegFirstNameHelp.InnerText = "Please enter a first name";
                good = false;
            }
            else
            {
                smlRegFirstNameHelp.InnerText = "";
            }
            if (lastName == "")
            {
                smlRegLastNameHelp.InnerText = "Please enter a last name";
                good = false;
            }
            else
            {
                smlRegLastNameHelp.InnerText = "";
            }
            if (emailAddress == "")
            {
                smlRegEmailHelp.InnerText = "Please enter an email address";
                good = false;
            }
            else
            {
                smlRegEmailHelp.InnerText = "";
            }
            if (homeAddress == "")
            {
                smlRegHomeAddressHelp.InnerText = "Please enter a home address";
                good = false;
            }
            else
            {
                smlRegHomeAddressHelp.InnerText = "";
            }
            if (billingAddress == "")
            {
                smlRegBillingAddressHelp.InnerText = "Please enter a billing address";
                good = false;
            }
            else
            {
                smlRegBillingAddressHelp.InnerText = "";
            }
            if (!Int64.TryParse(txtRegPhone.Text, out phoneNumber))
            {
                smlRegPhoneHelp.InnerText = "Please enter a valid phone number";
                good = false;
            }
            else
            {
                smlRegPhoneHelp.InnerText = "";
            }
            if (profileImage == "")
            {
                smlRegImageHelp.InnerText = "Please enter a valid image URL";
                good = false;
            }
            else
            {
                smlRegImageHelp.InnerText = "";
            }
            if (securityQuestion1 == "")
            {
                smlRegQuestion1Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlRegQuestion1Help.InnerText = "";
            }
            if (securityQuestion2 == "")
            {
                smlRegQuestion2Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlRegQuestion2Help.InnerText = "";
            }
            if (securityQuestion3 == "")
            {
                smlRegQuestion3Help.InnerText = "Please enter a question response";
                good = false;
            }
            else
            {
                smlRegQuestion3Help.InnerText = "";
            }

            if (!good)
            {
                return;
            }

            UserService.UserService proxy = new UserService.UserService();
            bool validateUsername         = proxy.ValidateUsername(username);

            if (!validateUsername)
            {
                smlRegUsernameHelp.InnerText = "Username already taken, pick a new one";
                return;
            }
            else
            {
                smlRegUsernameHelp.InnerText = "";
            }

            bool validateEmail = proxy.ValidateEmail(emailAddress);

            if (!validateEmail)
            {
                smlRegEmailHelp.InnerText = "Email is taken, please try again with a new one";
                return;
            }
            else
            {
                smlRegEmailHelp.InnerText = "";
            }

            try
            {
                MailAddress fromAddress      = new MailAddress("*****@*****.**", "Not Twitter");
                MailAddress toAddress        = new MailAddress(emailAddress, "New User");
                MailMessage verificationMail = new MailMessage(fromAddress.Address, toAddress.Address);
                verificationMail.Subject = "Not Twitter: New Account Verification";
                verificationMail.Body    = "Click this link to verify your new account. http://localhost:62631/Verification.aspx?uname=" + username + "&mail=true";
                SmtpClient client = new SmtpClient();
                client.Host                  = "smtp.gmail.com";
                client.Port                  = 587;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = false;
                client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                client.Credentials           = new NetworkCredential(fromAddress.Address, "ajcqwouuvihbodbc");
                client.Send(verificationMail);
            }
            catch
            {
                smlRegEmailHelp.InnerText = "Invalid email address, try again";
                return;
            }
            smlRegEmailHelp.InnerText = "";

            UserService.User user1 = new UserService.User();
            user1.Username        = username;
            user1.FirstName       = firstName;
            user1.LastName        = lastName;
            user1.Password        = TwitterClassLibrary.Encryption.PasswordEncryption.EncryptPassword(password);
            user1.EmailAddress    = emailAddress;
            user1.HomeAddress     = homeAddress;
            user1.BillingAddress  = billingAddress;
            user1.Phone           = phoneNumber.ToString();
            user1.ProfileImage    = profileImage;
            user1.SecretQuestions = secretQuestions;
            user1.SecretAnswers   = secretAnswers;
            user1.Verified        = "false";


            bool addUser = proxy.AddUser(user1);

            if (!addUser)
            {
                smlRegUsernameHelp.InnerText = "User registration failed, try again later";
                return;
            }
            else
            {
                smlRegUsernameHelp.InnerText = "";
            }

            Session["Username"] = txtRegUsername.Text;
            if (chkRegCookie.Checked)
            {
                Response.Cookies["Username"].Value = txtRegUsername.Text;
            }

            Response.Redirect("Verification.aspx?mail=false");
        }