public ActionResult Register() { ViewBag.Recaptcha = ReCaptcha.GetHtml(ConfigurationManager.AppSettings["ReCaptcha:SiteKey"], "light", "image"); var roles = roleService.GetMany(s => s.Id < 3).ToList(); var model = new RegisterViewModel(roles); return View(model); }
public ActionResult Register(RegisterViewModel user) { var roles = roleService.GetMany(s => s.Id < 3).ToList(); user.Roles = roles; try { if (ModelState.IsValid && ReCaptcha.Validate(ConfigurationManager.AppSettings["ReCaptcha:SecretKey"])) { var model = new User(); model.Firstname = user.Firstname; model.Lastname = user.Lastname; model.Age = user.Age; model.Email = user.Email; model.Password = Crypto.HashPassword(user.Password); model.RoleID = user.RoleId; model.City = user.City; model.Address = user.Address; model.CreationDate = DateTime.Now; userService.Add(model); ViewBag.Message = "Paldies. Reģistrācija noritēja veiksmīgi"; return RedirectToAction("Index", "Home"); } ViewBag.RecaptchaLastErrors = ReCaptcha.GetLastErrors(this.HttpContext); ViewBag.Recaptcha = ReCaptcha.GetHtml(ConfigurationManager.AppSettings["ReCaptcha:SiteKey"], "light", "image"); } catch (Exception) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError); } return View(user); }