Support custom subclasses of the User model

Provide API supporting custom model classes extending the built-in User
model.

Change `UserRepository` to accept a generic parameter `U`, where `U`
is a subclass of `User`.