Beispiel #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ClientUser {
                    UserName = model.Email, Email = model.Email, Name = model.Name
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Client");
                    await SendEmailConfirmation(user);

                    if (model.WithPractice)
                    {
                        await _placesService.AddSharePlaceAtRegistration(user.Id, model.PracticeId);
                    }

                    if (!string.IsNullOrEmpty(model.MarketingCode))
                    {
                        await _clientRelationsService.SetMarketingCodeAsRegistered(model.MarketingCode);
                    }

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToAction(nameof(RegisterSuccess)));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }