Exemplo n.º 1
0
        public async Task <IActionResult> CreateUserByForm([FromBody] CreateUserFromFormDto dto)
        {
            User user;

            try
            {
                user = await _userService.CreateUserFromFormAsync(dto.FormId);
            }
            catch (ApplicationException)
            {
                return(NotFound("Form with this id was not found"));
            }

            if (user == null)
            {
                return(BadRequest("Can't create user"));
            }

            var resetPassToken = await _userManager.GeneratePasswordResetTokenAsync(user);

            await _emailSendService.SendAsync(user.Email,
                                              "Registration in B2B",
                                              EmailTemplates.GetCreateUserFromForm(user, $"{dto.RedirectUrl}/{resetPassToken}/{user.Id}", dto.ServiceUrl));

            return(Created(Url.GetEntityByIdUrl(nameof(Get), "User", user.Id, Request.Scheme), _mapper.Map <User, ExternalUserDto>(user)));
        }