protected override void Act() { addCommandForKeyedHashAlgorithmProvider = CryptographyModel.CreateCollectionElementAddCommand( typeof(KeyedHashAlgorithmProviderData), hashProviderCollection) .First(); }
protected void btnSignUp_Click(object sender, EventArgs e) { //only update if validators were passed if (Page.IsValid) { Customer user = (Customer)Session["user"]; //only update if user is currently logged in if (user != null) { //only update if the user entered the correct old password if (inputOldPassword.Value.Equals(CryptographyModel.decryptPassword(user.password))) { //update customer Customer customer = user; customer.name = inputName.Value; customer.email = inputEmail.Value; if (cbPassword.Checked) { //user wanted a new password, update it customer.password = CryptographyModel.encryptPassword(inputPassword.Value); } else { //user did not want to change his password, keep the old one customer.password = customer.password; } //update user's database data CustomerService customerService = new CustomerService(); customerService.updateCustomer(customer); //also update his info in the session Session["user"] = customer; lblStatus.Text = "Your info was succesfully updated."; lblStatus.ForeColor = System.Drawing.Color.Green; } else { lblStatus.Text = "Incorrect old password!"; lblStatus.ForeColor = System.Drawing.Color.Red; } } else { string script = "alert(\"You have been logged out due to inactivity. Please log in to change your details.\");"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); //redirect to login Response.Redirect("Index.aspx"); } } }
protected void btnSignup_Click(object sender, EventArgs e) { Page.Validate(); if (Page.IsValid) { Customer customer = new Customer { email = txtEmail.Text, password = CryptographyModel.encryptPassword(txtPassword.Text), name = txtName.Text, street = txtStreet.Text, zip = txtPostalcode.Text, municipality = txtMunicipality.Text, isVerified = false }; try { SignUpModel signUpModel = new SignUpModel(); if (signUpModel.beginSignUpProcess(customer)) //Throws NoRecordException || DALException { pnlSignup.Visible = false; lblHeader.Text = "Welcome to Taboelaert Raesa!"; lblEmailSent.Text = "An email has been sent to " + customer.email + ". Please follow the instructions in the email to complete your registration."; pnlSignupCompleted.Visible = true; } else { pnlSignup.Visible = false; lblEmailSent.Text = "An error occured while completing your registration, please try again later. Contact our support if this problem persists."; pnlSignupCompleted.Visible = true; } } catch (NoRecordException) { pnlSignup.Visible = false; lblEmailSent.Text = "An error occured while completing your registration, please try again later. Contact our support if this problem persists."; pnlSignupCompleted.Visible = true; } } }
public async Task <resultStatus> PostFormData() { resultStatus ret = new resultStatus(); ret.success = true; CloudStorageAccount storageAccount = CloudStorageAccount.Parse( ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); // Retrieve a reference to a container. string currentUserID = HttpContext.Current.User.Identity.GetUserId(); string currentUserName = HttpContext.Current.User.Identity.GetUserName(); string containerString = CryptographyModel.GetUserContainer(currentUserName, currentUserID); System.Text.StringBuilder str = new System.Text.StringBuilder(CryptographyModel.GetUserAvatarHash(currentUserName, currentUserID)); str.Append(".png"); string blobString = str.ToString(); CloudBlobContainer container = blobClient.GetContainerReference(containerString); container.CreateIfNotExists(); container.SetPermissions( new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); // string root = HttpContext.Current.Server.MapPath("~/App_Data"); // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent()) { ret.success = false; ret.actionRes = "jednak tu: " + System.Net.HttpStatusCode.UnsupportedMediaType.ToString(); return(ret); //throw new HttpResponseException(System.Net.HttpStatusCode.UnsupportedMediaType); } // await Request.Content.ReadAsMultipartAsync(provider); try { var provider = new MultipartMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); foreach (var file in provider.Contents) { //var filename = file.Headers.ContentDisposition.FileName.Trim('\"'); var buffer = await file.ReadAsByteArrayAsync(); //Do whatever you want with filename and its binaray data. Stream stream = new MemoryStream(buffer); CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobString); if (CryptographyModel.FileIsWebFriendlyImage(stream)) { await blockBlob.UploadFromStreamAsync(stream); } else { ret.success = false; ret.actionRes = "bad format"; } } //var User = System.Web.HttpContext.Current.User; str = new System.Text.StringBuilder("https://st-cdn-scus.azureedge.net/"); str.Append(containerString); str.Append("/"); str.Append(blobString); using (var db = new ApplicationDbContext()) { var userId = User.Identity.GetUserId(); var usr = db.Users.Find(userId); usr.AvatarUrl = str.ToString(); await db.SaveChangesAsync(); } //var manager = new Microsoft.AspNet.Identity.UserManager<User,>(store,); //using (var db = new join_dbEntities()) //{ // AspNetUser user = await db.AspNetUsers.FindAsync(currentUserID); // //} ret.actionRes = str.ToString(); return(ret); } catch (System.Exception e) { ret.success = false; ret.actionRes = "tu sie jeblo" + e.Message.ToString() + " " + e.InnerException.Message.ToString(); return(ret); } }