// Note: For an explanation of the forums authentication code used // in this function, please refer to Heath Stewart's article on Code Project: // Role-based Security with Forms Authentication // http://www.codeproject.com/aspnet/formsroleauth.asp private void LoginButton_Click(object sender, System.EventArgs e) { // If email and password are entered, try to log user on if (_emailValidator.IsValid && _passwordValidator.IsValid) { int userID = UserDB.GetUserIDFromEmail(_emailTextBox.Text, WebID); if (userID > 0) { // Get information for user with identifier userID User user = UserDB.GetUser(userID); if (user.Password == _passwordTextBox.Text) { // Record the user that is going to be logged on _userID = userID; // Initialise forms authentication FormsAuthentication.Initialize(); // Create a new ticket used for authentication DateTime expire = DateTime.Now; if (_rememberMeCheckBox.Checked) { expire = expire.AddYears(10); } else { expire = expire.AddMinutes(30); } FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // Ticket version userID.ToString(), // Username associated with ticket DateTime.Now, // Date/time issued expire, // Date/time to expire _rememberMeCheckBox.Checked, // "true" for a persistent user cookie user.Roles, // User-data, in this case the roles FormsAuthentication.FormsCookiePath); // Path cookie valid for // Encrypt the cookie using the machine key for secure transport string hash = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie( FormsAuthentication.FormsCookieName, // Name of auth cookie hash); // Hashed ticket // Set the cookie's expiration time to the tickets expiration time if (ticket.IsPersistent) { cookie.Expires = ticket.Expiration; } // Add the cookie to the list for outgoing response Page.Response.Cookies.Add(cookie); RedirectReturnURL(); } } } }
private void DeletePreviousAvatar(string previousFilename) { User user = UserDB.GetUser(_userID); if (user.Avatar != string.Empty && user.Avatar != previousFilename) { string avatarPath = GetAvatarPath(user.Avatar); try { File.Delete(avatarPath); } catch (Exception) { } } }
private void PopulateUserSettings() { // Initially populate units with user's profile settings int userID = LoggedOnUserID; User user = UserDB.GetUser(userID); _aliasValidator.Allow = user.Alias; _emailValidator.Allow = user.Email; _emailTextBox.Text = user.Email; _aliasTextBox.Text = user.Alias; // CHANGED by Arthur Zaczek // _passwordTextBox.Text = user.Password; // _confirmTextBox.Text = user.Password; _rememberMeCheckBox.Visible = false; }
public override void Render(HtmlTextWriter writer) { RenderTableBegin(writer, 1, 0); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); // Check to see whether a user is currently logged on. If not, no need // to display logoff info message and logoff button. if (_loggedOff || LoggedOnUserID == 0) { writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write("Nobody is logged on."); writer.RenderEndTag(); } else { // Display logged on user writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); ForumText aliasForumText = new ForumText(UserDB.GetUser(LoggedOnUserID).Alias); writer.Write(aliasForumText.ProcessSingleLine(GetImages()) + " is logged on."); writer.RenderEndTag(); // P // Informative message writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write("Click the button below to logoff."); writer.RenderEndTag(); // Logoff button writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); _logoffButton.RenderControl(writer); writer.RenderEndTag(); } writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr RenderTableEnd(writer); // Table }
private void EmailReplyNotification(ForumPost parentForumPost, ForumPost forumPost) { User user = UserDB.GetUser(forumPost.User.UserID); User userParent = UserDB.GetUser(parentForumPost.User.UserID); StringBuilder sb = new StringBuilder(); sb.AppendFormat("A reply from {0} has been posted to your message entitled \"{1}\"\r\n\r\n", user.Alias, parentForumPost.Subject); sb.AppendFormat("Subject: \"{0}\"\r\n\r\n", forumPost.Subject); sb.AppendFormat("Reply: \r\n\r\n{0}\r\n\r\n", forumPost.Body); string url = "http://" + Page.Request.ServerVariables["SERVER_NAME"] + "/" + WebSolutionUtils.GetURL(GetDocument(), Page, "postid=" + forumPost.PostID + "#" + forumPost.PostID, "forumaction=&threadspage=&searchpage="); sb.Append("To view this reply at the forum, click on the following link:\r\n\r\n"); sb.Append(url); MailMessage mailMessage = new MailMessage(); mailMessage.To = userParent.Email; mailMessage.Subject = "Message board reply"; mailMessage.Body = sb.ToString(); mailMessage.BodyFormat = MailFormat.Text; string host = Page.Request.Url.Host; if (host.Length > 4 && host.Substring(0, 4) == "www.") { host = host.Substring(4, host.Length - 4); } mailMessage.From = "forums@" + host; SmtpMail.SmtpServer = Page.Request.ServerVariables["SERVER_NAME"]; try { SmtpMail.Send(mailMessage); } catch (Exception) { } }
public override void Render(HtmlTextWriter writer) { RenderTableBegin(writer, 1, 0); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); // Display logged on user if (LoggedOnUserID > 0 || _userID > 0) { int userID = _userID; if (userID == 0) { userID = LoggedOnUserID; } User user = UserDB.GetUser(userID); writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.Write(user.Alias + " is logged on."); writer.RenderEndTag(); // P } // On post back, display whether user is or is not logged on if (Page.IsPostBack) { if (_userID == 0) { // Login attempt must have been invalid. So display this fact. writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.P); writer.AddAttribute(HtmlTextWriterAttribute.Class, "WebSolutionErrorText"); writer.RenderBeginTag(HtmlTextWriterTag.Span); writer.Write("Invalid login attempt. Please try again."); writer.RenderEndTag(); // Span writer.RenderEndTag(); // P } } // Start table into which we will render login controls writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1"); writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "1"); writer.AddAttribute(HtmlTextWriterAttribute.Border, "0"); writer.RenderBeginTag(HtmlTextWriterTag.Table); // E-mail row writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write("E-mail:"); writer.RenderEndTag(); // B writer.RenderEndTag(); // Td writer.RenderBeginTag(HtmlTextWriterTag.Td); _emailTextBox.RenderControl(writer); writer.RenderEndTag(); // Td writer.RenderBeginTag(HtmlTextWriterTag.Td); _emailValidator.RenderControl(writer); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr // Password row writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.RenderBeginTag(HtmlTextWriterTag.B); writer.Write("Password:"******"Normal"); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.RenderEndTag(); // Td writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); writer.RenderBeginTag(HtmlTextWriterTag.Td); _rememberMeCheckBox.RenderControl(writer); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr // Gap row writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "3"); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.Write(" "); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr // Login button writer.AddAttribute(HtmlTextWriterAttribute.Class, "Normal"); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.RenderBeginTag(HtmlTextWriterTag.Td); writer.RenderEndTag(); // Td writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); writer.RenderBeginTag(HtmlTextWriterTag.Td); _loginButton.RenderControl(writer); writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr // Close table writer.RenderEndTag(); // Table writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr RenderTableEnd(writer); // Table }
private void PopulateUnits() { if (_action == "new" || _action == "reply" || _action == "quote") { ForumText aliasForumText = new ForumText(UserDB.GetUser(_userID).Alias); _nameLabel.Text = aliasForumText.ProcessSingleLine(GetImages()); } if (_action == "edit" || _action == "reply" || _action == "quote") { _forumPost = ForumDB.GetPost(_postID); if (_action == "edit") { if (LoggedOnUserID != _forumPost.User.UserID && !Page.User.IsInRole("ForumAdmin")) { RedirectUserHasNoAuthority(); } ForumText postAliasForumText = new ForumText(_forumPost.User.Alias); _nameLabel.Text = postAliasForumText.ProcessSingleLine(GetImages()); _subjectTextBox.Text = _forumPost.Subject; _bodyTextBox.Text = _forumPost.Body; _notifyCheckBox.Checked = _forumPost.Notify; } else { // If action is quote or reply, make sure subject begins "Re:" string subject = _forumPost.Subject; string replySubject = subject; if (replySubject.Length >= 3) { if (replySubject.Substring(0, 3) != "Re:") { replySubject = "Re: " + replySubject; } } else { replySubject = "Re: " + replySubject; } _subjectTextBox.Text = replySubject; // If action is quote, add message being replied to within QUOTE tags if (_action == "quote") { ForumText forumText = new ForumText(_forumPost.Body); _bodyTextBox.Text = forumText.ProcessQuoteBody(_forumPost.User.Alias); } } } if (_pinnedDropDownList != null && !Page.IsPostBack) { _pinnedDropDownList.Items.Add(new ListItem("Not Sticky", "0")); _pinnedDropDownList.Items.Add(new ListItem("1 Day", "1")); _pinnedDropDownList.Items.Add(new ListItem("3 Days", "3")); _pinnedDropDownList.Items.Add(new ListItem("1 Week", "7")); _pinnedDropDownList.Items.Add(new ListItem("2 Weeks", "14")); _pinnedDropDownList.Items.Add(new ListItem("1 Month", "30")); _pinnedDropDownList.Items.Add(new ListItem("3 Months", "90")); _pinnedDropDownList.Items.Add(new ListItem("6 Months", "180")); _pinnedDropDownList.Items.Add(new ListItem("1 Year", "365")); _pinnedDropDownList.Items.Add(new ListItem("3 Years", "1095")); } }