Exemple #1
0
        public static UserPassModel ConvertUserToPost(this IdentityUser input)
        {
            var model = new UserPassModel();

            var inputType     = input.GetType().GetRealType();
            var inputProperty = inputType.GetProperties();
            var userType      = typeof(IdentityUser);
            var userProperty  = userType.GetProperties();

            foreach (var p in inputProperty)
            {
                if (userProperty.Where(b => b.Name == p.Name).FirstOrDefault() != null)
                {
                    try
                    {
                        p.SetValue(model, p.GetValue(input));
                    }
                    catch { }
                    continue;
                }
                var prop = p.GetContentPropertyByPropertyInfo(input);
                if (prop == null)
                {
                    continue;
                }
                model.Properties.Add(prop);
            }
            model.Properties = model.Properties.OrderBy(b => b.SortOrder).ToList();
            return(model);
        }
Exemple #2
0
        /// <summary>
        /// metoda zwracająca użytkownika według {id}
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IDictionary <string, object> > GetUserById(string id)
        {
            dynamic user           = new ExpandoObject();
            var     userDictionary = (IDictionary <string, object>)user;

            IdentityUser identityUser = await userManager.FindByIdAsync(id);

            var userAddress = await dbContext.Adresses.FindAsync(id);

            foreach (PropertyInfo prop in identityUser.GetType().GetProperties())
            {
                userDictionary.Add(prop.Name, prop.GetValue(identityUser, null));
            }

            foreach (PropertyInfo prop in userAddress.GetType().GetProperties())
            {
                userDictionary.Add(prop.Name, prop.GetValue(userAddress, null));
            }

            return(userDictionary);
        }
Exemple #3
0
        public static IdentityUser ConvertPostToUser(this UserPassModel input, IdentityUser user, bool deleteExistFile = true, List <string> oldFiles = null, List <string> newFiles = null)
        {
            var inputType     = user.GetType().GetRealType();
            var inputProperty = inputType.GetProperties();

            var userType     = typeof(IdentityUser);
            var userProperty = userType.GetProperties();

            foreach (var p in inputProperty)
            {
                try
                {
                    if (userProperty.Where(b => b.Name == p.Name).FirstOrDefault() != null)
                    {
                        continue;
                    }
                    p.SetPropertyValue(input, user, deleteExistFile, oldFiles, newFiles);
                }
                catch { }
            }

            return(user);
        }
        public void User_Ignore_PasswordHash_Test()
        {
            var context = Container.Resolve <BloggingDbContext>();

            var userName = "******";
            var user     = new IdentityUser <long>
            {
                UserName     = userName,
                PasswordHash = "password hash"
            };

            context.Users.Add(user);
            context.SaveChanges();

            var propertyChanges = context.EntityChanges
                                  .Where(x => x.ChangeType == EntityChangeType.Created && x.EntityTypeFullName == user.GetType().FullName)
                                  .SelectMany(x => x.PropertyChanges).ToList();

            propertyChanges.FirstOrDefault(x => x.PropertyName == nameof(user.UserName) && x.NewValue == userName)
            .ShouldNotBeNull();

            propertyChanges.FirstOrDefault(x => x.PropertyName == nameof(user.PasswordHash))
            .ShouldBeNull();
        }