Exemple #1
0
        /// <summary>
        /// Returns the user profile. An admin can get any user's profile.
        /// </summary>
        /// <param name="token">AuthenticatedToken of the logged on user.</param>
        /// <param name="logOnName">LogOnName of the user whose profile is requested.</param>
        /// <returns>ZentityUser instance filled with properties.</returns>
        /// <remarks>This method is expected to be called for the scenario where the administrator is requesting profile of a user.
        /// This method works when the AuthenticatedToken belongs to the administrator, or when the token
        /// belongs to the user whose logon name is passed as the second parameter.</remarks>
        public static ZentityUserProfile GetUserProfile(AuthenticatedToken token, string logOnName)
        {
            #region Input Validation
            ValidateToken(token);
            #endregion

            try
            {
                //// The token must be of the user who is updating the logon name or it must be an admin's token.
                if (!string.Equals(token.IdentityName, logOnName, StringComparison.OrdinalIgnoreCase) &&
                    !DataAccessLayer.IsAdmin(token.IdentityName))
                {
                    return(null);
                }

                ZentityUser user = new ZentityUser(logOnName, token);
                user.FillUserProperties();
                return(user.Profile);
            }
            catch (TypeInitializationException ex)
            {
                //// thrown in case of incorrect application configuration
                throw new AuthenticationException(ConstantStrings.TypeInitializationExceptionMessage, ex);
            }
        }
Exemple #2
0
        /// <summary>
        /// Retrieves user information for the given user
        /// </summary>
        /// <param name="logOnName">LogOn Name of the user whose information is to be retrieved</param>
        /// <param name="password">User password</param>
        /// <returns>ZentityUser instance in which property values are filled in from database</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
        ///    {
        ///        ZentityUser user = ZentityUserManager.GetUserProfile(&quot;JohnDE&quot;, &quot;john@123&quot;);
        ///        //The ZentityUser instance returned contains all property values filled in from the authentication store.
        ///        if (user != null)
        ///        {
        ///            Console.WriteLine(&quot;Email : {0}&quot;, user.Email);
        ///            //Display remaining properties.
        ///        }
        ///    }
        ///    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 ZentityUserProfile GetUserProfile(string logOnName, string password)
        {
            #region Input Validation
            ValidateParameters("logOnName", logOnName, "password", password);
            #endregion

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