Exemplo n.º 1
0
        /// <summary>
        /// Logs an authenticated user out.
        /// </summary>
        /// <remarks>
        /// This method will return a single, anonymous user.
        /// <para>
        /// By default, this method can only be used for forms authentication and leverages
        /// ASP.NET <see cref="FormsAuthentication"/>.
        /// </para>
        /// </remarks>
        /// <returns>A single, default user.</returns>
        /// <exception cref="InvalidOperationException"> is thrown if the ASP.NET
        /// authentication mode is not <see cref="AuthenticationMode.Forms"/>.
        /// </exception>
        /// <seealso cref="GetUser()"/>
        public T Logout()
        {
            AuthenticationBase <T> .CheckAuthenticationMode();

            this.ClearAuthenticationToken();

            return(this.GetUserCore(AuthenticationBase <T> .DefaultPrincipal));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Authenticates and returns the user with the specified name and password.
        /// </summary>
        /// <remarks>
        /// This method will return a single user if the
        /// authentication was successful. If the user could not be authenticated, <c>null</c>
        /// will be returned.
        /// <para>
        /// By default, this method can be only used for forms authentication and leverages
        /// ASP.NET <see cref="Membership"/> and <see cref="FormsAuthentication"/>.
        /// </para>
        /// </remarks>
        /// <param name="userName">The userName associated with the user to authenticate</param>
        /// <param name="password">The password associated with the user to authenticate</param>
        /// <param name="isPersistent">Whether the authentication should persist between sessions</param>
        /// <param name="customData">Optional implementation-specific data. It is unused by this base class.</param>
        /// <returns>A single user or <c>null</c> if authentication failed</returns>
        /// <exception cref="InvalidOperationException"> is thrown if the ASP.NET
        /// authentication mode is not <see cref="AuthenticationMode.Forms"/>.
        /// </exception>
        /// <seealso cref="GetUser()"/>
        public T Login(string userName, string password, bool isPersistent, string customData)
        {
            AuthenticationBase <T> .CheckAuthenticationMode();

            if (this.ValidateUser(userName, password))
            {
                IPrincipal principal = new GenericPrincipal(
                    new GenericIdentity(userName, "Forms"),
                    AuthenticationBase <T> .DefaultRoles.ToArray());

                this.IssueAuthenticationToken(principal, isPersistent);

                return(this.GetUserCore(principal));
            }
            return(default(T));
        }