Simplify using a custom TUser with DefaultUI
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
This came up as a part of investigating the fix to https://github.com/aspnet/Identity/issues/1679
Today to add additional basic data to a custom user requires overriding the Register/Manage pages,
which is still somewhat involved, see [DefaultUI sample](https://github.com/aspnet/Identity/tree/dev/samples/IdentitySample.DefaultUI/Areas/Identity/Pages/Account)
```
public class MyUser : IdentityUser {
public string Name { get; set; }
public int Age { get; set; }
}
```
I think we can simplify this to only needing to define only the additional properties + the corresponding input model if we add a basic mechanism for generating the appropriate inputs and introduce a new abstraction in the UI package around updating/creating the actual TUser:
```C#
public class MyUser : IdentityUser {
public string Name { get; set; }
public int Age { get; set; }
}
public class MyUserInputModel : RegisterInputModel, ManageInputModel {
[Required]
[DataType(DataType.Text)]
[Display(Name = "Full name")]
public string Name { get; set; }
[Required]
[Range(0,199, ErrorMessage = "Age must be between 0 and 199 years")]
[Display(Name = "Age")]
public int Age { get; set; }
}
```
We would have to introduce a couple of new abstractions/services in the UI package and update the Register/Manage pages to use them:
```C#
// Default implementation would reflect to work against properties
// only users with truly custom POCOs would need to implement this.
public interface IUserFactory {
TUser Create(IUserData data); // Register calls this to create a new user
void Update(TUser user, IUserData data); // Manage uses this to update the user
}
// Similarly we could generate the Register/manage inputs from the models
// we could some minor ability to customize the classes names if needed
IInputGenerator.Generate(InputModel):
// generates the:
```
Contributor guide
Assessment
This issue has not been assessed yet.