aspnet / Identity

[Archived] ASP.NET Core Identity is the membership system for building ASP.NET Core web applications, including membership, login, and user data. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
1.96k stars 870 forks source link

asp.net Core Activate/deativate User #1901

Closed Karthik2610 closed 6 years ago

Karthik2610 commented 6 years ago

Hi I am deactivating the user with the following code await _userManager.SetLockoutEndDateAsync(user, DateTime.MaxValue.AddYears(-1)); now i need to create a new user with same credentials that locked out user has because that username and email will be given to new joined user. Please let me know if there is any other way Please guide me if we can do this.

blowdart commented 6 years ago

There is a method for this

public abstract Task<IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));

but if you have linked tables outside of identity you'd have to manually clean those first.

Karthik2610 commented 6 years ago

Hi blowdart

Thanks. If we use DeleteAsync it will delete from DB. My requirement is 1) A person joins a company we create a user 2) He resigns and we make that user to be deactivate using (locking out) , report will use deleted user created item to be shown for admin. (PDF or excel). await _userManager.SetLockoutEndDateAsync(user, DateTime.MaxValue.AddYears(-1)); 3) The reason we lock is if he joins back we need to give back the same ID, so we did not delete 4) If he does not come back and there is a requirement that we need to give the same ID (Email and Username), so new user should not see old details which user 1 created 5) Now when i create _userManager.CreateAsync is not allowing me and says email and username already exist.

My question If we lock the user and if we create new user with email and user name of that locked user will it allow (please guide me) ? or we need to deleted the user and create new one.

blowdart commented 6 years ago

You must delete. You cannot duplicate usernames they are designed to be unique.

Karthik2610 commented 6 years ago

Thanks