internal static TBLogEvento Novo(AspNetUser user, DateTime dt, string acao)
 {
     return new TBLogEvento
     {
         UserId = user.Id,
         nmUsuario = user.TBUsuario.nmUsuario,
         dtDataAcao = dt,
         PrefeituraID = user.TBUsuario.PrefeituraID,
         Acao = acao
     };
 }
        private static Task<bool> VerifyClientIdAsync(ApplicationUserManager manager, AspNetUser user,
            CookieValidateIdentityContext context)
        {
            var clientId = context.Identity.FindFirstValue("AspNet.Identity.ClientId");
            if (!string.IsNullOrEmpty(clientId) && user.Clients.Any(c => c.Id.ToString() == clientId))
            {
                user.CurrentClientId = clientId;
                return Task.FromResult(true);
            }

            return Task.FromResult(false);
        }
        public async Task<ActionResult> Registrar(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new AspNetUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    var callbackUrl = Url.Action("ConfirmaEmail", "Autenticacao", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    await UserManager.SendEmailAsync(user.Id, "Confirme sua Conta", "Por favor confirme sua conta clicando neste link: <a href='" + callbackUrl + "'></a>");
                    ViewBag.Link = callbackUrl;
                    return View("DisplayEmail");
                }
                AddErrors(result);
            }

            // No caso de falha, reexibir a view. 
            return View(model);
        }
        private async Task SignInAsync(AspNetUser user, bool isPersistent)
        {
            var clientKey = Request.Browser.Type;// +Request.Headers["X-NuGet-ApiKey"];
            await UserManager.SignInClientAsync(user, clientKey);
            // Zerando contador de logins errados.
            await UserManager.ResetAccessFailedCountAsync(user.Id);

            // Coletando Claims externos (se houver)
            ClaimsIdentity ext = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
            // Criação da instancia do Identity e atribuição dos Claims
            var claims = await user.GenerateUserIdentityAsync(UserManager, ext);
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie, DefaultAuthenticationTypes.ApplicationCookie);
            AuthenticationManager.SignIn(
                    new AuthenticationProperties { IsPersistent = isPersistent },
                    claims
                );
        }
 private static async Task<bool> VerifySecurityStampAsync(ApplicationUserManager manager, AspNetUser user,
     CookieValidateIdentityContext context)
 {
     var stamp = context.Identity.FindFirstValue("AspNet.Identity.SecurityStamp");
     return (stamp == await manager.GetSecurityStampAsync(context.Identity.GetUserId()));
 }
 internal static UsuarioBasicoVM ToDomain(AspNetUser item)
 {
     return new UsuarioBasicoVM();
 }
 internal static UsuarioAutoEditVM ToDomain(AspNetUser item)
 {
     return new UsuarioAutoEditVM();
 }