コード例 #1
0
        /// <summary>
        /// Creates an identity cookie for our guest and returns their new identity
        /// </summary>
        /// <returns></returns>
        public CookieIdentity SignInGuest()
        {
            //create the new anonymous identity
            var authenticationIdentity = new CookieIdentity
            {
                RememberMe     = false,
                Email          = CoreConstants.Authentication.GuestUserName,
                HasUserProfile = false
            };

            //update the identity cookie
            _cookieManager.Set(CoreConstants.Authentication.IdentityCookieName, authenticationIdentity.Encode(), DateTime.MaxValue);

            //remove the current user from the http context
            AppContext.RemoveFromHttpContext();

            return(authenticationIdentity);
        }
コード例 #2
0
        /// <summary>
        /// Method should only be invoked for users who have just successfully logged into the site
        /// </summary>
        /// <param name="email">the email they logged in with (could be username or email address)</param>
        public void SignIn(string email)
        {
            FormsAuthentication.SetAuthCookie(email, true);

            var authenticationIdentity = new CookieIdentity
            {
                RememberMe     = true,
                Email          = email,
                HasUserProfile = true,
            };

            _cookieManager.Set(
                CoreConstants.Authentication.IdentityCookieName,
                authenticationIdentity.Encode(),
                authenticationIdentity.RememberMe ? DateTime.MaxValue : (DateTime?)null);

            //remove the current user from the http context
            AppContext.RemoveFromHttpContext();
        }