Exemple #1
0
        /// <summary>
        /// Unregisters a user. An admin can unregister any user, while a user can request unregistration for himself.
        /// </summary>
        /// <param name="token">Authenticated token of the logged on user.</param>
        /// <param name="logOnName">LogOn name of the user whose account is to be unregistered.</param>
        /// <returns>True if unregister operation completes successfully.</returns>
        /// <remarks>This method succeeds for any user's logon name when an admin token is passed.
        /// When a user token is passed, the logon name must be of the same user. Or else call the overload with just
        /// AuthenticatedToken parameter for unregistering a user. </remarks>
        public static bool Unregister(AuthenticatedToken token, string logOnName)
        {
            #region Input Validation
            ValidateToken(token);
            ValidateParameters("logOnName", logOnName);
            #endregion

            try
            {
                //// The token must be of the admin or the user who wants to unregister.
                if (!string.Equals(token.IdentityName, logOnName, StringComparison.OrdinalIgnoreCase) &&
                    !DataAccessLayer.IsAdmin(token.IdentityName))
                {
                    return(false);
                }

                ZentityUser user    = new ZentityUser(logOnName, token);
                bool        success = user.Unregister();
                return(success);
            }
            catch (TypeInitializationException ex)
            {
                //// thrown in case of incorrect application configuration
                throw new AuthenticationException(ConstantStrings.TypeInitializationExceptionMessage, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Unregisters a user account.
        /// </summary>
        /// <param name="logOnName">LogOnName of the user</param>
        /// <param name="password">Password of the user account</param>
        /// <returns>True if user is successfully unsubscribed</returns>
        /// <example>
        /// Pre-requisites for running this code sample
        /// <list type="bullet">
        /// <item>Refer to the sample application configuration file given in help, and create a similar one for your application.</item>
        /// <item>Add reference to Zentity.Security.Authentication.dll and Zentity.Security.AuthenticationProvider.dll </item>
        /// <item>Run the sample for registering new users to create the user accounts in the authentication database.</item>
        /// <item>Then run this sample, replacing inputs with valid values</item>
        /// </list>
        /// <code>
        /// try
        ///    {
        ///        //Call unregister method passing user credentials
        ///        bool isUserUnregistered = ZentityUserManager.Unregister(&quot;JohnDE&quot;, &quot;john@123&quot;);
        ///        if (isUserUnregistered)
        ///        {
        ///            Console.WriteLine(&quot;User unregistered successfully&quot;);
        ///        }
        ///        else
        ///        {
        ///            Console.WriteLine(&quot;User could not be unregistered. Please verify the logon name / password.&quot;);
        ///        }
        ///    }
        ///    //AuthenticationException might be thrown in case of errors in connecting to the authentication store
        ///    catch (AuthenticationException ex)
        ///    {
        ///        Console.WriteLine(ex.Message);
        ///        //In case of database errors the AuthenticationException object will wrap the sql exception.
        ///        if (ex.InnerException != null)
        ///        {
        ///            Console.WriteLine(ex.InnerException.Message);
        ///        }
        ///    }
        ///
        /// </code>
        /// </example>
        public static bool Unregister(string logOnName, string password)
        {
            #region Input Validation
            ValidateParameters("logOnName", logOnName, "password", password);
            #endregion

            try
            {
                ZentityUser user    = new ZentityUser(logOnName, password);
                bool        success = user.Unregister();
                return(success);
            }
            catch (TypeInitializationException ex)
            {
                //// thrown in case of incorrect application configuration
                throw new AuthenticationException(ConstantStrings.TypeInitializationExceptionMessage, ex);
            }
        }