public IActionResult AuthorizeAnEmail(AuthorizeAnEmail_vmodel model) { if (ModelState.IsValid) { if (authorizedEmailRepository.GetByEmail(model.Email) == null) { authorizedEmailRepository.AddAuthorizedEmail(model.Email); } return(RedirectToAction("AuthorizedEmails")); } return(View(model)); }
public async Task <IActionResult> Register(CreateAccount_vmodel model) { if (ModelState.IsValid) { if (authorizedEmailRepo.GetByEmail(model.Email) == null) { ModelState.AddModelError(string.Empty, "Su correo NO esta autorizado para registrarse"); return(View(model)); } var user = new App_IdentityUser() { UserName = model.Username, Email = model.Email, Gender = model.Gender }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var token = await userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token }, Request.Scheme); string message = HtmlEmailTemplate.CreateHtmlBody(user.UserName, "Has click para verificar su cuenta de correo electrónico:", confirmationLink, "Verificar Correo Electrónico"); mailService.SendEmail(user.Email, "Verificación de correo electrónico", message); logger.Log(LogLevel.Information, $"Se envio el token de confirmacion de email para el usuario {user.UserName}"); if (signInManager.IsSignedIn(User)) { return(RedirectToAction("ListUsers", "Administration")); } await signInManager.SignInAsync(user, isPersistent : false); if ((await userManager.GetClaimsAsync(user)).Count() > 0) { return(RedirectToAction("Index", "Home")); } return(RedirectToAction("WithoutClaims", new { emailConfirmed = user.EmailConfirmed })); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(View(model)); }