Beispiel #1
0
        public async Task <IActionResult> SendConfirmation([FromBody] LoginModel signup)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var id              = PasswordSecurity.HashEmail(signup.Email);
                    var code            = PasswordSecurity.HashEmail(signup.Password);
                    var callbackUrl     = Url.Action(nameof(Confirm), "Email", new { userId = id, code = code }, protocol: HttpContext.Request.Scheme);
                    var applicationUser = new ApplicationUser {
                        UserId = id, Email = signup.Email, Code = code
                    };
                    await _context.AddAsync(applicationUser);

                    await _context.SaveChangesAsync();

                    _emailManager.Send(signup.Email, "Confirm your account", $"Please confirm your account by clicking <a href='{callbackUrl}'>here</a>");
                    return(Ok());
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("Errors", "There was a problem with the email client");
                    throw(e);
                }
            }
            return(BadRequest());
        }