<commit_before>using System.Security.Principal;
using System.Web.Security;

namespace Crowbar
{
    /// <summary>
    /// Represents the context of a partial view that should be rendered for form submission.
    /// </summary>
    public class PartialViewContext
    {
        public PartialViewContext(string viewName)
        {
            ViewName = viewName;
            ClientValidationEnabled = true;         // Read from Web.config?
            UnobtrusiveJavaScriptEnabled = true;    // Read from Web.config?
        }

        public bool ClientValidationEnabled { get; set; }
        
        public bool UnobtrusiveJavaScriptEnabled { get; set; }
        
        /// <summary>
        /// Gets or sets the security principal in which the view should be rendered.
        /// </summary>
        public IPrincipal User { get; set; }

        /// <summary>
        /// Gets the name of the partial view that should be rendered.
        /// </summary>
        public string ViewName { get; private set; }

        /// <summary>
        /// Sets the security principal, using forms authentication, in which the view should be rendered.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="timeout">The time, in minutes, for which the forms authentication cookie is valid.</param>
        public void SetFormsAuthPrincipal(string username, int timeout = 30)
        {
            var ticket = new FormsAuthenticationTicket(username, false, timeout);
            User = new GenericPrincipal(new FormsIdentity(ticket), new string[0]);
        }

        public static implicit operator PartialViewContext(string viewName)
        {
            return new PartialViewContext(viewName);
        }
    }
}<commit_msg>Added a convenience method for setting the principal to an anonymous user.<commit_after>using System.Security.Principal;
using System.Web.Security;

namespace Crowbar
{
    /// <summary>
    /// Represents the context of a partial view that should be rendered for form submission.
    /// </summary>
    public class PartialViewContext
    {
        public PartialViewContext(string viewName)
        {
            ViewName = viewName;
            ClientValidationEnabled = true;         // Read from Web.config?
            UnobtrusiveJavaScriptEnabled = true;    // Read from Web.config?
        }

        public bool ClientValidationEnabled { get; set; }

        public bool UnobtrusiveJavaScriptEnabled { get; set; }

        /// <summary>
        /// Gets or sets the security principal in which the view should be rendered.
        /// </summary>
        public IPrincipal User { get; set; }

        /// <summary>
        /// Gets the name of the partial view that should be rendered.
        /// </summary>
        public string ViewName { get; private set; }

        /// <summary>
        /// Sets the security principal, using forms identity, in which the view should be rendered.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="timeout">The time, in minutes, for which the forms authentication cookie is valid.</param>
        public PartialViewContext SetFormsAuthPrincipal(string username, int timeout = 30)
        {
            var ticket = new FormsAuthenticationTicket(username, false, timeout);
            User = new GenericPrincipal(new FormsIdentity(ticket), new string[0]);

            return this;
        }

        /// <summary>
        /// Sets the security principal to an anonymous user (no username), using a generic identity.
        /// </summary>
        public PartialViewContext SetAnonymousPrincipal()
        {
            User = new GenericPrincipal(new GenericIdentity(""), new string[0]);

            return this;
        }

        public static implicit operator PartialViewContext(string viewName)
        {
            return new PartialViewContext(viewName);
        }
    }
}
{'fraction_non_alphanumeric': 0.09159919028340081, 'fraction_numerical': 0.001771255060728745, 'mean_word_length': 2.093114241001565, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4871693', 'n_tokens_mistral': 948, 'n_tokens_neox': 908, 'n_words': 338}