示例#1
0
        protected void updateUser_Click(object sender, EventArgs e)
        {
            string nameString;
            string phoneString;
            string fbString;
            string linkedinString;
            string twitterString;
            string skypeString;
            string descString;
            string emailString;
            string responseMessage;

            emailString = txtEmail.Text;

            DataAccessLayer dao = new DataAccessLayer();

            nameString     = (txtName.Text.Length > 0)? txtName.Text : "";
            phoneString    = (txtPhone.Text.Length > 0) ? txtPhone.Text : "";
            fbString       = (txtFB.Text.Length > 0) ? txtFB.Text : "";
            linkedinString = (txtLinkedin.Text.Length > 0) ? txtLinkedin.Text : "";
            twitterString  = (txtTwitter.Text.Length > 0) ? txtTwitter.Text : "";
            skypeString    = (txtSkype.Text.Length > 0) ? txtSkype.Text : "";
            descString     = (txtDescription.InnerText.Length > 0) ? txtDescription.InnerText : "";

            string applicationPath = Constants.path;

            if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
            {
                string imageName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
                string location  = applicationPath + "userassets" + @"\" + emailString;

                if (!Directory.Exists(location))
                {
                    Directory.CreateDirectory(location);
                }

                string SaveLocation = location + "\\" + imageName;
                try
                {
                    FileUpload1.PostedFile.SaveAs(SaveLocation);
                    dao.UpdateProfilePicture(imageName, emailString);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }

            if (dao.UpdateUser(nameString, emailString, phoneString, fbString, linkedinString, twitterString, skypeString, descString) == true)
            {
                responseMessage  = "User details updated";
                respMessage.Text = responseMessage;
            }
            else
            {
                Console.WriteLine("Error");
            }
        }
示例#2
0
        protected void userUpdate_Click(object sender, EventArgs e)
        {
            DataAccessLayer dao = new DataAccessLayer();

            string responseMessage = null;
            string name            = txtName.Text;
            string email           = txtEmail.Text;
            string phone           = txtPhone.Text;
            string fbUrl           = userFBlink.Text;
            string linkedinURL     = userLinkedinLink.Text;
            string twitterURL      = userTwitterLink.Text;
            string skypeURL        = userSkypeLink.Text;
            string pass            = userConfirmPass.Text;
            string description     = txtDescription.InnerText;

            string applicationPath = Constants.path;

            if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
            {
                string imageName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
                string location  = applicationPath + "userassets" + @"\" + email;

                if (!Directory.Exists(location))
                {
                    Directory.CreateDirectory(location);
                }

                string SaveLocation = location + "\\" + imageName;
                try
                {
                    FileUpload1.PostedFile.SaveAs(SaveLocation);
                    FileUploadStatus.Text = "The file has been uploaded.";
                    dao.UpdateProfilePicture(imageName, email);
                }
                catch (Exception ex)
                {
                    FileUploadStatus.Text = "Error: " + ex.Message;
                }
            }
            else
            {
                FileUploadStatus.Text = "Please select a file to upload.";
            }

            if (pass != "")
            {
                byte[] bytePassword = System.Text.ASCIIEncoding.ASCII.GetBytes(pass);
                System.Security.Cryptography.HashAlgorithm hashAlgorithm;

                if (email.Length % 3 == 0)
                {
                    hashAlgorithm = SHA256.Create();
                }
                else if (email.Length % 3 == 1)
                {
                    hashAlgorithm = SHA512.Create();
                }
                else
                {
                    hashAlgorithm = SHA1.Create();
                }

                byte[] byteHashPassword  = hashAlgorithm.ComputeHash(bytePassword);
                string encryptedPassword = Convert.ToBase64String(byteHashPassword);

                dao.UpdateUserPassword(encryptedPassword, email);
            }


            if (dao.UpdateUser(name, email, phone, fbUrl, linkedinURL, twitterURL, skypeURL, description) == true)
            {
                responseMessage  = "User details updated";
                respMessage.Text = responseMessage;
            }
            else
            {
                Console.WriteLine("Error");
            }
        }