protected void ReviewGrid_Delete(object sender, GridViewDeleteEventArgs e) { string merchId = FooStringHelper.RemoveInvalidChars(merchView.SelectedValue.ToString()); if (!FooStringHelper.IsValidAlphanumeric(merchId, 16)) { errorLabel.Text = "Invalid request."; Reset_Page(string.Empty); return; } try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "DELETE FROM reviews WHERE reviewid= @REVIEWID", CommandType = CommandType.Text, Connection = conn }; var param = new NpgsqlParameter { ParameterName = "@REVIEWID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars( reviewGrid.DataKeys[e.RowIndex].Values[0].ToString()) }; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } Reset_Page(merchId); }
protected void PostView_ItemDeleting(object sender, DetailsViewDeleteEventArgs e) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "DELETE FROM posts WHERE postid= @POSTID", CommandType = CommandType.Text, Connection = conn }; var param = new NpgsqlParameter { ParameterName = "@POSTID", NpgsqlDbType = NpgsqlDbType.Integer, Size = 8, Direction = ParameterDirection.Input, Value = Convert.ToInt32(postView.SelectedValue) }; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } Reset_Page(-1); }
protected void submitButton_Click(object sender, EventArgs e) { string reviewBody = reviewText.Text; string userId = FooSessionHelper.GetUserObjectFromCookie(HttpContext.Current).UserId; string merchId = Request.QueryString["id"]; if (string.IsNullOrEmpty(reviewBody)) { RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); reviewErrorLabel.Text = "Incomplete input."; return; } if (!FooStringHelper.IsValidAlphanumeric(merchId, 16)) { RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); reviewErrorLabel.Text = "Invalid input."; return; } try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO reviews(reviewid, reviewtime, userid, merchid, reviewbody) VALUES (@REVIEWID, @REVIEWTIME, @USERID, @MERCHID, @REVIEWBODY)", CommandType = CommandType.Text, Connection = conn }; var idParam = new NpgsqlParameter { ParameterName = "@REVIEWID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RandomString(16) }; cmd.Parameters.Add(idParam); var timeParam = new NpgsqlParameter { ParameterName = "@REVIEWTIME", NpgsqlDbType = NpgsqlDbType.Timestamp, Size = 32, Direction = ParameterDirection.Input, Value = DateTime.Now }; cmd.Parameters.Add(timeParam); var userParam = new NpgsqlParameter { ParameterName = "@USERID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars(userId) }; cmd.Parameters.Add(userParam); var merchParam = new NpgsqlParameter { ParameterName = "@MERCHID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = merchId }; cmd.Parameters.Add(merchParam); var bodyParam = new NpgsqlParameter { ParameterName = "@REVIEWBODY", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 1024, Direction = ParameterDirection.Input, Value = reviewBody }; cmd.Parameters.Add(bodyParam); cmd.ExecuteNonQuery(); cmd.Dispose(); reviewErrorLabel.Text = ""; reviewText.Text = ""; } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); reviewErrorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); Load_Forms(merchId); }
protected void submitButton_Click(object sender, EventArgs e) { string email = emailText.Text.Trim(); if (!String.IsNullOrEmpty(email) || !FooStringHelper.IsValidEmailAddress(email)) { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { if (FooEmailHelper.CheckIfEmailExists(email, null)) { UserObject user = GetUserObjByEmail(email); if (user != null) { string resetToken = FooStringHelper.RandomString(24); string resetId = MakeResetRequest(user.UserId, resetToken); string resetUrl = FooStringHelper.MakeResetUrl(resetId, resetToken); string emailBody = String.Format( "Hi {0},<br/><br/>Your FooBlog password for account '{1}' can be reset by visiting the following link:<br/><br/><a href=\"{2}\">{3}</a><br/><br/>The link is valid for 24 hours. If you did not request this reset, simply do not visit the link - your current password will remain unchanged.<br/><br/>Cheers,<br/>The FooBlog Team.", user.UserAlias, user.Username, resetUrl, resetUrl); const string emailSubject = "FooBlog Password Reset"; var mailObj = new EmailObject { Body = emailBody, Subject = emailSubject, ToAddress = email }; bool sendMail = FooEmailHelper.SendEmail(mailObj); if (sendMail) { errorPanel.Visible = false; formPanel.Visible = false; successPanel.Visible = true; successLabel.Text = "A reset link has been sent to your registered email account."; } } else { errorPanel.Visible = true; errorLabel.Text = "Invalid details."; } } else { errorPanel.Visible = true; errorLabel.Text = "Invalid request."; } } else { errorPanel.Visible = true; errorLabel.Text = "Invalid details."; } } else { errorPanel.Visible = true; errorLabel.Text = "Incomplete or invalid details."; } RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); }
protected void CategoryGrid_Command(object sender, GridViewCommandEventArgs e) { int postId = Convert.ToInt32(postView.SelectedValue); var txtCatNameFooter = (TextBox)categoryGrid.FooterRow.FindControl("txtCatNameFooter"); if (!string.IsNullOrEmpty(txtCatNameFooter.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { if (e.CommandName.Equals("AddNew")) { // Define connection string. using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO categories(catid, catname) VALUES (@CATID, @NAME)", CommandType = CommandType.Text, Connection = conn }; var idParam = new NpgsqlParameter { ParameterName = "@CATID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RandomString(16) }; cmd.Parameters.Add(idParam); var nameParam = new NpgsqlParameter { ParameterName = "@NAME", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtCatNameFooter.Text }; cmd.Parameters.Add(nameParam); cmd.ExecuteNonQuery(); cmd.Dispose(); } } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(postId); }
protected void CategoryGrid_Update(object sender, GridViewUpdateEventArgs e) { int postId = Convert.ToInt32(postView.SelectedValue); var txtCatName = (TextBox)categoryGrid.Rows[e.RowIndex].FindControl("txtCatName"); if (!string.IsNullOrEmpty(txtCatName.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { // Define connection string. using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "UPDATE categories SET catname= @NAME WHERE catid= @CATID", CommandType = CommandType.Text, Connection = conn }; var nameParam = new NpgsqlParameter { ParameterName = "@NAME", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtCatName.Text }; cmd.Parameters.Add(nameParam); var idParam = new NpgsqlParameter { ParameterName = "@CATID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars( categoryGrid.DataKeys[e.RowIndex].Values[0].ToString()) }; cmd.Parameters.Add(idParam); cmd.ExecuteNonQuery(); } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(postId); }
protected void CategoryGrid_Delete(object sender, GridViewDeleteEventArgs e) { int postId = Convert.ToInt32(postView.SelectedValue); try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "DELETE FROM posts WHERE catid= @CATID", CommandType = CommandType.Text, Connection = conn }; var param = new NpgsqlParameter { ParameterName = "@CATID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars( categoryGrid.DataKeys[e.RowIndex].Values[0].ToString()) }; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } // Define connection string. using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "DELETE FROM categories WHERE catid= @CATID", CommandType = CommandType.Text, Connection = conn }; var param = new NpgsqlParameter { ParameterName = "@CATID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars( categoryGrid.DataKeys[e.RowIndex].Values[0].ToString()) }; cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } Reset_Page(postId); }
protected void PostView_ItemInserting(object sender, DetailsViewInsertEventArgs e) { var txtPostTitle = (TextBox)postView.FindControl("txtPostTitle"); var txtPostBrief = (TextBox)postView.FindControl("txtPostBrief"); var txtPostBody = (TextBox)postView.FindControl("txtPostBody"); var postEnabledCheckbox = (CheckBox)postView.FindControl("postEnabledCheckbox"); var catDropdown = (DropDownList)postView.FindControl("catDropdown"); if (!string.IsNullOrEmpty(txtPostTitle.Text) && !string.IsNullOrEmpty(txtPostBrief.Text) && !string.IsNullOrEmpty(txtPostBody.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { // Define connection string. using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO posts(catid, posttime, posttitle, postbrief, postbody, postenabled) VALUES (@CATID, @POSTTIME, @POSTTITLE, @POSTBRIEF, @POSTBODY, @POSTENABLED)", CommandType = CommandType.Text, Connection = conn }; var catParam = new NpgsqlParameter { ParameterName = "@CATID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = catDropdown.SelectedValue }; cmd.Parameters.Add(catParam); var timeParam = new NpgsqlParameter { ParameterName = "@POSTTIME", NpgsqlDbType = NpgsqlDbType.Timestamp, Size = 32, Direction = ParameterDirection.Input, Value = DateTime.Now }; cmd.Parameters.Add(timeParam); var titleParam = new NpgsqlParameter { ParameterName = "@POSTTITLE", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtPostTitle.Text }; cmd.Parameters.Add(titleParam); var briefParam = new NpgsqlParameter { ParameterName = "@POSTBRIEF", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 1024, Direction = ParameterDirection.Input, Value = txtPostBrief.Text }; cmd.Parameters.Add(briefParam); var bodyParam = new NpgsqlParameter { ParameterName = "@POSTBODY", NpgsqlDbType = NpgsqlDbType.Varchar, Direction = ParameterDirection.Input, Value = Server.HtmlDecode(txtPostBody.Text) }; cmd.Parameters.Add(bodyParam); var enabledParam = new NpgsqlParameter { ParameterName = "@POSTENABLED", NpgsqlDbType = NpgsqlDbType.Boolean, Direction = ParameterDirection.Input, Value = postEnabledCheckbox.Checked }; cmd.Parameters.Add(enabledParam); cmd.ExecuteNonQuery(); cmd.Dispose(); } } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(-1); }
protected void UserView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e) { UserObject userObj = FooSessionHelper.GetUserObjectFromCookie(HttpContext.Current); string userId = userObj.UserId; string userName = userObj.Username; if (!FooStringHelper.IsValidAlphanumeric(userId, 16)) { errorLabel.Text = "Invalid request."; Reset_Page(); return; } var txtUserAlias = (TextBox)userView.FindControl("txtUserAlias"); var txtUserEmail = (TextBox)userView.FindControl("txtUserEmail"); var txtUserAddress = (TextBox)userView.FindControl("txtUserAddress"); var txtUserCity = (TextBox)userView.FindControl("txtUserCity"); var txtUserCountry = (TextBox)userView.FindControl("txtUserCountry"); var txtUserBody = (TextBox)userView.FindControl("txtUserBody"); var imageUploadForm = (FileUpload)userView.FindControl("imageUploadForm"); if (!string.IsNullOrEmpty(txtUserAlias.Text) && !string.IsNullOrEmpty(txtUserEmail.Text) && !string.IsNullOrEmpty(txtUserAddress.Text) && !string.IsNullOrEmpty(txtUserCity.Text) && !string.IsNullOrEmpty(txtUserCountry.Text) && !string.IsNullOrEmpty(txtUserBody.Text) && !string.IsNullOrEmpty(txtUserEmail.Text) && FooStringHelper.IsValidEmailAddress(txtUserEmail.Text) && !FooEmailHelper.CheckIfEmailExists(txtUserEmail.Text, userName)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "UPDATE users SET (useralias, email, address, city, country, profilebody) = (@USERALIAS, @EMAIL, @ADDRESS, @CITY, @COUNTRY, @PROFILEBODY) WHERE userid= @USERID", CommandType = CommandType.Text, Connection = conn }; var idParam = new NpgsqlParameter { ParameterName = "@USERID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars(userId) }; cmd.Parameters.Add(idParam); var aliasParam = new NpgsqlParameter { ParameterName = "@USERALIAS", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserAlias.Text }; cmd.Parameters.Add(aliasParam); var emailParam = new NpgsqlParameter { ParameterName = "@EMAIL", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 64, Direction = ParameterDirection.Input, Value = txtUserEmail.Text }; cmd.Parameters.Add(emailParam); var addressParam = new NpgsqlParameter { ParameterName = "@ADDRESS", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 128, Direction = ParameterDirection.Input, Value = txtUserAddress.Text }; cmd.Parameters.Add(addressParam); var cityParam = new NpgsqlParameter { ParameterName = "@CITY", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserCity.Text }; cmd.Parameters.Add(cityParam); var countryParam = new NpgsqlParameter { ParameterName = "@COUNTRY", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserCountry.Text }; cmd.Parameters.Add(countryParam); var bodyParam = new NpgsqlParameter { ParameterName = "@PROFILEBODY", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 1024, Direction = ParameterDirection.Input, Value = txtUserBody.Text }; cmd.Parameters.Add(bodyParam); cmd.ExecuteNonQuery(); cmd.Dispose(); } if (imageUploadForm.HasFile) { string path = HttpContext.Current.Server.MapPath("~/uploads"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } HttpPostedFile file = HttpContext.Current.Request.Files[0]; if (file.ContentLength < 2097152) { string fileName; if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE") { string[] files = file.FileName.Split(new[] { '\\' }); fileName = files[files.Length - 1]; } else { fileName = file.FileName; } fileName = FooStringHelper.RandomFileName(fileName); string filePath = Path.Combine(path, fileName); try { file.SaveAs(filePath); Insert_NewImage(fileName, userId); Reset_Page(); } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Upload failed."; } } else { errorLabel.Text = "Invalid file."; } } } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(); }
protected void MerchView_ItemInserting(object sender, DetailsViewInsertEventArgs e) { string merchId = FooStringHelper.RandomString(16); var txtMerchName = (TextBox)merchView.FindControl("txtMerchName"); var txtMerchPrice = (TextBox)merchView.FindControl("txtMerchPrice"); var txtMerchBrief = (TextBox)merchView.FindControl("txtMerchBrief"); var txtMerchBody = (TextBox)merchView.FindControl("txtMerchBody"); var imageUploadForm = (FileUpload)merchView.FindControl("imageUploadForm"); var merchEnabledCheckbox = (CheckBox)merchView.FindControl("merchEnabledCheckbox"); if (!string.IsNullOrEmpty(txtMerchName.Text) && !string.IsNullOrEmpty(txtMerchPrice.Text) && FooStringHelper.IsValidPrice(txtMerchPrice.Text) && !string.IsNullOrEmpty(txtMerchBrief.Text) && !string.IsNullOrEmpty(txtMerchBody.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { // Define connection string. using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO merchandise (merchid, merchname, merchprice, merchbrief, merchbody, merchenabled) VALUES (@MERCHID, @MERCHNAME, @MERCHPRICE, @MERCHBRIEF, @MERCHBODY, @MERCHENABLED)", CommandType = CommandType.Text, Connection = conn }; var idParam = new NpgsqlParameter { ParameterName = "@MERCHID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = merchId }; cmd.Parameters.Add(idParam); var nameParam = new NpgsqlParameter { ParameterName = "@MERCHNAME", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 64, Direction = ParameterDirection.Input, Value = txtMerchName.Text }; cmd.Parameters.Add(nameParam); var priceParam = new NpgsqlParameter { ParameterName = "@MERCHPRICE", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 8, Direction = ParameterDirection.Input, Value = txtMerchPrice.Text }; cmd.Parameters.Add(priceParam); var briefParam = new NpgsqlParameter { ParameterName = "@MERCHBRIEF", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 1024, Direction = ParameterDirection.Input, Value = txtMerchBrief.Text }; cmd.Parameters.Add(briefParam); var bodyParam = new NpgsqlParameter { ParameterName = "@MERCHBODY", NpgsqlDbType = NpgsqlDbType.Varchar, Direction = ParameterDirection.Input, Value = txtMerchBody.Text }; cmd.Parameters.Add(bodyParam); var enabledParam = new NpgsqlParameter { ParameterName = "@MERCHENABLED", NpgsqlDbType = NpgsqlDbType.Boolean, Direction = ParameterDirection.Input, Value = merchEnabledCheckbox.Checked }; cmd.Parameters.Add(enabledParam); cmd.ExecuteNonQuery(); cmd.Dispose(); } if (imageUploadForm.HasFile) { HttpPostedFile file = HttpContext.Current.Request.Files[0]; Insert_NewImage(merchId, file); } else { Insert_NewImage(merchId, null); } } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(string.Empty); }
protected void submitButton_Click(object sender, EventArgs e) { string password = passText.Text.Trim(); string confirmation = confirmText.Text.Trim(); if (password != confirmation) { errorLabel.Text = "The password and confirmation do not match."; return; } string resetId = Request.QueryString["id"]; string token = Request.QueryString["token"]; if (!String.IsNullOrEmpty(resetId) && !String.IsNullOrEmpty(token) && !String.IsNullOrEmpty(password)) { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { string userId = GetAccountForReset(resetId, token); if (!String.IsNullOrEmpty(userId)) { bool doReset = UpdatePassword(userId, password); if (doReset) { errorPanel.Visible = false; formPanel.Visible = false; successPanel.Visible = true; string email = FooEmailHelper.GetEmailForAccount(userId); var emailObj = new EmailObject { Body = "Your FooBlog password has been reset. If you did not perform this action, please contact a FooBlog administrator using your registered email account", Subject = "FooBlog Password Reset", ToAddress = email }; FooEmailHelper.SendEmail(emailObj); successLabel.Text = "Your password has been reset. You can proceed to <a href=\"login.aspx\">login</a> again."; errorPanel.Visible = false; errorLabel.Text = ""; } } } else { errorPanel.Visible = true; errorLabel.Text = "Invalid request."; } } else { errorPanel.Visible = true; errorLabel.Text = "Passwords do not match."; } RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); }
protected void submitButton_Click(object sender, EventArgs e) { string commentBody = commentText.Text; string userId = FooSessionHelper.GetUserObjectFromCookie(HttpContext.Current).UserId; string postId = Request.QueryString["id"]; if (!string.IsNullOrEmpty(commentBody)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO comments(commentid, commenttime, userid, postid, commentbody) VALUES (@COMMENTID, @COMMENTTIME, @USERID, @POSTID, @COMMENTBODY)", CommandType = CommandType.Text, Connection = conn }; var idParam = new NpgsqlParameter { ParameterName = "@COMMENTID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RandomString(16) }; cmd.Parameters.Add(idParam); var timeParam = new NpgsqlParameter { ParameterName = "@COMMENTTIME", NpgsqlDbType = NpgsqlDbType.Timestamp, Size = 32, Direction = ParameterDirection.Input, Value = DateTime.Now }; cmd.Parameters.Add(timeParam); var userParam = new NpgsqlParameter { ParameterName = "@USERID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars(userId) }; cmd.Parameters.Add(userParam); var postParam = new NpgsqlParameter { ParameterName = "@POSTID", NpgsqlDbType = NpgsqlDbType.Integer, Size = 16, Direction = ParameterDirection.Input, Value = FooStringHelper.RemoveInvalidChars(postId) }; cmd.Parameters.Add(postParam); var bodyParam = new NpgsqlParameter { ParameterName = "@COMMENTBODY", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 1024, Direction = ParameterDirection.Input, Value = commentBody }; cmd.Parameters.Add(bodyParam); cmd.ExecuteNonQuery(); cmd.Dispose(); commentText.Text = ""; commentErrorLabel.Text = ""; } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); commentErrorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } Load_Forms(); } else { commentErrorLabel.Text = "Incomplete input."; } RequestToken.Value = FooSessionHelper.SetToken(HttpContext.Current); }
protected void GridView_Command(object sender, GridViewCommandEventArgs e) { string userId = FooStringHelper.RandomString(16); var txtUserNameFooter = (TextBox)userGrid.FooterRow.FindControl("txtUserNameFooter"); var txtUserAliasFooter = (TextBox)userGrid.FooterRow.FindControl("txtUserAliasFooter"); var txtEmailFooter = (TextBox)userGrid.FooterRow.FindControl("txtEmailFooter"); var txtUserPasswordFooter = (TextBox)userGrid.FooterRow.FindControl("txtUserPasswordFooter"); var groupDropdownFooter = (DropDownList)userGrid.FooterRow.FindControl("groupDropdownFooter"); if (!string.IsNullOrEmpty(txtUserNameFooter.Text) && !string.IsNullOrEmpty(txtUserAliasFooter.Text) && !string.IsNullOrEmpty(txtEmailFooter.Text) && FooStringHelper.IsValidEmailAddress(txtEmailFooter.Text) && !string.IsNullOrEmpty(txtUserPasswordFooter.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { if (e.CommandName.Equals("AddNew")) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "INSERT INTO users(userid,username,useralias,groupid,email,passwordhash,profileimg) VALUES (@USERID,@NAME,@DISP,@GROUP,@EMAIL,@HASH,'profile_default.jpg')", CommandType = CommandType.Text, Connection = conn }; var userIdParam = new NpgsqlParameter { ParameterName = "@USERID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = userId }; cmd.Parameters.Add(userIdParam); var nameParam = new NpgsqlParameter { ParameterName = "@NAME", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserNameFooter.Text }; cmd.Parameters.Add(nameParam); var dispParam = new NpgsqlParameter { ParameterName = "@DISP", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserAliasFooter.Text }; cmd.Parameters.Add(dispParam); var groupParam = new NpgsqlParameter { ParameterName = "@GROUP", NpgsqlDbType = NpgsqlDbType.Varchar, Direction = ParameterDirection.Input, Value = groupDropdownFooter.SelectedValue }; cmd.Parameters.Add(groupParam); var emailParam = new NpgsqlParameter { ParameterName = "@EMAIL", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 64, Direction = ParameterDirection.Input, Value = txtEmailFooter.Text }; cmd.Parameters.Add(emailParam); var hashParam = new NpgsqlParameter { ParameterName = "@HASH", NpgsqlDbType = NpgsqlDbType.Varchar, Direction = ParameterDirection.Input, Value = FooCryptHelper.CreateShaHash(txtUserPasswordFooter.Text) }; cmd.Parameters.Add(hashParam); cmd.ExecuteNonQuery(); cmd.Dispose(); } } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } Reset_Page(); }
protected void GridView_Update(object sender, GridViewUpdateEventArgs e) { string userId = userGrid.DataKeys[e.RowIndex].Values[0].ToString(); if (!FooStringHelper.IsValidAlphanumeric(userId, 16)) { errorLabel.Text = "Invalid request."; Reset_Page(); return; } var txtUserName = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txtUserName"); var txtUserAlias = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txtUserAlias"); var txtEmail = (TextBox)userGrid.Rows[e.RowIndex].FindControl("txtEmail"); var groupDropdown = (DropDownList)userGrid.Rows[e.RowIndex].FindControl("groupDropdown"); if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtUserAlias.Text) && !string.IsNullOrEmpty(txtEmail.Text) && FooStringHelper.IsValidEmailAddress(txtEmail.Text)) { try { if (FooSessionHelper.IsValidRequest(HttpContext.Current, RequestToken.Value)) { using (var conn = new NpgsqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString; conn.Open(); var cmd = new NpgsqlCommand { CommandText = "UPDATE users SET (username, useralias, groupid, email) = (@NAME, @USERALIAS, @GROUP, @EMAIL) WHERE userID= @USERID", CommandType = CommandType.Text, Connection = conn }; var param = new NpgsqlParameter { ParameterName = "@USERID", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = userId }; cmd.Parameters.Add(param); var nameParam = new NpgsqlParameter { ParameterName = "@USERNAME", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserName.Text }; cmd.Parameters.Add(nameParam); var dispParam = new NpgsqlParameter { ParameterName = "@USERALIAS", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 32, Direction = ParameterDirection.Input, Value = txtUserAlias.Text }; cmd.Parameters.Add(dispParam); var emailParam = new NpgsqlParameter { ParameterName = "@EMAIL", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 64, Direction = ParameterDirection.Input, Value = txtEmail.Text }; cmd.Parameters.Add(emailParam); var groupParam = new NpgsqlParameter { ParameterName = "@GROUP", NpgsqlDbType = NpgsqlDbType.Varchar, Size = 16, Direction = ParameterDirection.Input, Value = groupDropdown.SelectedValue }; cmd.Parameters.Add(groupParam); cmd.ExecuteNonQuery(); } } else { errorLabel.Text = "Invalid request."; } } catch (Exception ex) { FooLogging.WriteLog(ex.ToString()); errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator."; } } else { errorLabel.Text = "Incomplete or invalid input."; } Reset_Page(); }