Skip to content

Instantly share code, notes, and snippets.

@Grinderofl
Created January 9, 2019 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grinderofl/740422fe66ed795e1eea76d45d283fee to your computer and use it in GitHub Desktop.
Save Grinderofl/740422fe66ed795e1eea76d45d283fee to your computer and use it in GitHub Desktop.
Update last login date
public class MySigninManager : SignInManager<IdentityUser>
{
public MySigninManager(UserManager<IdentityUser> userManager, IHttpContextAccessor contextAccessor,
IUserClaimsPrincipalFactory<IdentityUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor,
ILogger<SignInManager<IdentityUser>> logger, IAuthenticationSchemeProvider schemes)
: base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
{
}
protected override async Task<SignInResult> SignInOrTwoFactorAsync(IdentityUser user, bool isPersistent, string loginProvider = null, bool bypassTwoFactor = false)
{
var result = await base.SignInOrTwoFactorAsync(user, isPersistent, loginProvider, bypassTwoFactor);
if (result.Succeeded)
{
user.LastLogin = DateTimeOffset.UtcNow;
await UserManager.UpdateAsync(user);
}
return result;
}
}
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddDefaultIdentity<IdentityUser>()
.AddSignInManager<MySigninManager>()
.AddEntityFrameworkStores<ApplicationDbContext>();
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment