Example #1
0
 public static async Task<IndexViewModel> ToViewModel(this ApplicationUser user, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
 {
     var result = new IndexViewModel
     {
         HasPassword = await userManager.HasPasswordAsync(user),
         EmailAddress = user.Email,
         IsEmailAddressConfirmed = user.EmailConfirmed,
         IsPhoneNumberConfirmed = user.PhoneNumberConfirmed,
         PhoneNumber = await userManager.GetPhoneNumberAsync(user),
         TwoFactor = await userManager.GetTwoFactorEnabledAsync(user),
         Logins = await userManager.GetLoginsAsync(user),
         BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user),
         AssociatedSkills = user.AssociatedSkills,
         TimeZoneId = user.TimeZoneId,
         Name = user.Name,
         ProposedNewEmailAddress = user.PendingNewEmail
     };
     return result;
 }
 public static async Task<IndexViewModel> ToViewModel(this ApplicationUser user, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
 {
     var profileCompletenessWarnings = user.ValidateProfileCompleteness();
     var result = new IndexViewModel
     {
         HasPassword = await userManager.HasPasswordAsync(user),
         EmailAddress = user.Email,
         IsEmailAddressConfirmed = user.EmailConfirmed,
         IsPhoneNumberConfirmed = user.PhoneNumberConfirmed,
         PhoneNumber = await userManager.GetPhoneNumberAsync(user),
         TwoFactor = await userManager.GetTwoFactorEnabledAsync(user),
         Logins = await userManager.GetLoginsAsync(user),
         BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user),
         AssociatedSkills = user.AssociatedSkills,
         TimeZoneId = user.TimeZoneId,
         FirstName = user.FirstName,
         LastName = user.LastName,
         ProposedNewEmailAddress = user.PendingNewEmail,
         IsProfileComplete = user.IsProfileComplete(),
         ProfileCompletenessWarnings = profileCompletenessWarnings.Select(p => p.ErrorMessage)
     };
     return result;
 }
        public void PasswordHash()
        {
            using (UserStore<IdentityUser> store = new UserStore<IdentityUser>())
            {
                using (UserManager<IdentityUser> manager = new UserManager<IdentityUser>(store))
                {
                    var user = User;
                    string passwordPlain = Guid.NewGuid().ToString("N");
                    string passwordHash = manager.PasswordHasher.HashPassword(passwordPlain);

                    var taskUserSet = store.SetPasswordHashAsync(user, passwordHash);
                    taskUserSet.Wait();

                    var taskHasHash = manager.HasPasswordAsync(user.Id);
                    taskHasHash.Wait();
                    Assert.IsTrue(taskHasHash.Result, "PasswordHash not set");

                    var taskUser = store.GetPasswordHashAsync(user);
                    taskUser.Wait();
                    Assert.AreEqual<string>(passwordHash, taskUser.Result, "PasswordHash not equal");
                    user.PasswordHash = passwordHash;
                    try
                    {
                        var task = store.GetPasswordHashAsync(null);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }

                    try
                    {
                        var task = store.HasPasswordAsync(null);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }

                    try
                    {
                        var task = store.SetPasswordHashAsync(null, passwordHash);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }

                    try
                    {
                        var task = store.SetPasswordHashAsync(user, null);
                        task.Wait();
                    }
                    catch (Exception ex)
                    {
                        Assert.IsNotNull(ex, "Argument exception not raised");
                    }
                }
            }
        }