Esempio n. 1
0
        public static string CreateUser(CustomUserManager manager, ApplicationUser appUser, string password)
        {
            var user   = new Model.IdentityUser(appUser);
            var result = manager.CreateAsync(user, password).Result;

            return(result.Succeeded ? null : result.Errors.First().Description);
        }
Esempio n. 2
0
        private static Model.IdentityUser CreateLocalUserFromNltm(ClaimsPrincipal incomingPrincipal, ILog log, string name, CustomUserManager manager)
        {
            log.DebugFormat("Identity {0}, does not have local login. Creating...", name);
            var id = incomingPrincipal.FindFirstValue(System.Security.Claims.ClaimTypes.PrimarySid);
            var externalLoginInfo = new ExternalLoginInfo(
                incomingPrincipal,
                "NTLM",
                id,
                name);

            var email     = incomingPrincipal.FindFirst(System.Security.Claims.ClaimTypes.Email)?.Value ?? string.Empty;
            var givenName = incomingPrincipal.FindFirst(System.Security.Claims.ClaimTypes.GivenName)?.Value ?? string.Empty;

            var errors = CreateAndLoginUser(name, email, givenName, incomingPrincipal.Claims, externalLoginInfo, null);

            if (errors.Any())
            {
                throw new ApplicationException("Could not create local user!\r\n" + string.Join("\r\n", errors));
            }

            var user = manager.FindByName(name);

            return(user);
        }