public async Task <IActionResult> PostAsync([FromBody] UserAdd userAdd) { User user = new User() { Age = userAdd.Age, Verified = false, Role = "user", Password = userAdd.Password, Gender = userAdd.Gender, Mail = userAdd.Mail, Name = userAdd.Name }; if (!api.Exist(user.Mail)) { try { api.CreateUser(user); var token = api.GetUserToken(user.Mail); var link = "http://" + this.Request.Host + this.Request.Path + "Verify/?token=" + token; await new EmailSender(emailOptions).SendEmailAsync(user.Mail, "Verificacion de cuenta", $"Confirme su cuenta haciendo click <a href='{HtmlEncoder.Default.Encode(link)}'>Aquí</a>"); } catch (Exception e) { return(StatusCode(412, e.Message)); } return(StatusCode(204)); } else { return(StatusCode(400, "El usuario ya existe")); } }
public async Task<IActionResult> Register(UserAdd userAdd) { var captchaResponse = HttpContext.Request.Form["g-recaptcha-response"]; if(!CheckRecaptcha(captchaResponse)) { ModelState.AddModelError("captcha","El Captcha no ha sido ingresado correctamente"); return View(userAdd); } User user = new User() { Age = userAdd.Age, Verified = false, Role = "user", Password = userAdd.Password, Gender = userAdd.Gender, Mail = userAdd.Mail, Name = userAdd.Name }; bool exists = api.Exist(user.Mail); if (!exists) { try { api.CreateUser(user); var token = api.GetUserToken(user.Mail); var link = "http://" + this.Request.Host + this.Request.Path + "/Verify/?token=" + token; await new EmailSender(emailOptions).SendEmailAsync(user.Mail, "Verificacion de cuenta", $"Confirme su cuenta haciendo click <a href='{HtmlEncoder.Default.Encode(link)}'>Aquí</a>"); } catch (Exception e) { ModelState.AddModelError("Password", e.Message); return View("Register", userAdd); } return View("ToVerify", userAdd); } else { return RedirectToAction("Index","Login",new LoginViewModel(){Mail=userAdd.Mail}); } }