예제 #1
0
        public async Task <IActionResult> CheckEmailAsync()
        {
            var model = new UserActivationEmailModel
            {
                UserName         = "******",
                Email            = "*****@*****.**",
                ConfirmationLink = "somelink"
            };

            await _notificationService.NotifyAsync(model);

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> CreateAsync([FromBody] RegisterDto registerModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser
            {
                UserName = registerModel.Email,
                Email    = registerModel.Email,
                ChangePasswordRequired  = false,
                LastPasswordChangedDate = DateTime.UtcNow
            };

            var result = await _userManager.CreateAsync(user, registerModel.Password);

            if (result.Succeeded)
            {
                _logger.LogInformation("User created a new account with password.");


                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                string callbackUrl = Url.Link("ConfirmEmail", new { userId = user.Id, code = code });

                var model = new UserActivationEmailModel
                {
                    UserName         = user.UserName,
                    Email            = user.Email,
                    ConfirmationLink = callbackUrl
                };

                await _notificationService.NotifyAsync(model);

                //await _signInManager.SignInAsync(user, isPersistent: false);

                _logger.LogInformation("User created a new account with password.");
                return(Created("", result));
            }

            AddErrors(result);
            return(BadRequest(result));
        }