0

Please or Register to create posts and topics.

Register User not working in QuickApp Pro

Using the latest QuickApp Pro premium template using .Net Core 2.2 & Angular 8.

This template now has the "Forgotten password" and "Register" links on the login dialog box, but the Register function doesn't work, throwing this error:

InvalidOperationException: Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance.

AutoMapper.Mapper.get_Instance() in Mapper.cs, line 36

And this is where it gets thrown in the PublicRegister() function in AccountController.cs:

         if (ModelState.IsValid)
{
if (user == null)
return BadRequest($"{nameof(user)} cannot be null");
ApplicationUser appUser = Mapper.Map<ApplicationUser>(user);
var result = await _accountManager.CreateUserAsync(appUser, new string[] { _publicRoleName }, user.NewPassword);
if (result.Succeeded)
{
await SendVerificationEmail(appUser);

 

As far as I can tell, the other mappings for ApplicationUser are working OK, just not the one for UserPublicRegisterViewModel, but this is registered in AutoMapperProfile class.

 

Any suggestions?

 

yeap - minor issue - automapper 8 has moved from a static mapper to an instance one, Eben just missing this one instance of the from the old method on line 318 of AccountController, change to:

ApplicationUser appUser = _mapper.Map<ApplicationUser>(user);

_mapper is a local instance of the automapper created by the IOC..

I like the simple add user/reset user, this has saved me 100s of hours.....

PS, also there is a minor bug in user-editor.component.ts where the following two methods need to be marked as public (this will stop deployment to a web server, but doesn't error on local running:

line 35: public isSendingEmail = false;

line 307: public sendVerificationEmail() {

PSS, remember to update the timeout as sometimes the run local will just take too much time (maybe my slow PC) by changing the following in startup.cs:

spa.Options.StartupTimeout = TimeSpan.FromSeconds(240);

PSSS - Eben has added a concept of 'default role' to allow your registered users to be autologged based on appsettings: "DefaultUserRole": "User",

I've got both the STD and PRO deployed onto my azure accounts with azsure SQL backends, all working well.. (adding users etc) - I just swapped the email stuff out / added my DB (I actually used a clean new DB, but there were no breaking changes in the DB as far as I can see).

Now to upgrade my 3 projects based on the new template!! (a evening's work well worth the new features and Ang8!!, and fulling implement new users, reset password etc....

 

Eben Monney has reacted to this post.
Eben Monney