public JsonResult Register(RegisterViewModel model) { List <string> errors = new List <string>(); if (string.IsNullOrEmpty(model.Password)) { errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json(errors, JsonRequestBehavior.AllowGet)); } if (model.Password.Count() < 8) { ModelState.AddModelError("", "Şifre en az 8 karakter uzunluğunda olmalıdır!"); errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json(errors, JsonRequestBehavior.AllowGet)); } if (!ModelState.IsValid) { errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json(errors, JsonRequestBehavior.AllowGet)); } var usermanager = IdentityTools.NewUserManager(); var kullanici = usermanager.FindByEmail(model.Email); if (kullanici != null) { ModelState.AddModelError("", "Bu E-Posta Sistemde Kayıtlı!"); errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json(errors, JsonRequestBehavior.AllowGet)); } ApplicationUser user = new ApplicationUser(); user.Name = model.Name; user.Surname = model.Surname; user.Email = model.Email; user.UserName = model.Email; user.DogumTarihi = model.DogumTarihi; var result = usermanager.Create(user, model.Password); if (result.Succeeded) { usermanager.AddToRole(user.Id, "User"); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = "" }, protocol: Request.Url.Scheme); IdentityMessage msg = new IdentityMessage(); msg.Destination = user.Email; msg.Body = "Nerdeyse tamamlandı! NeYapsak ağına katılmak için <a href=\"" + callbackUrl + "\">neyapsak</a> linkine tıkla."; msg.Subject = "NeYapsak Hesap Doğrulama Servisi"; mail.SendMail(msg); errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json("True", JsonRequestBehavior.AllowGet)); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error); } } errors = ModelState.Values.SelectMany(state => state.Errors).Select(error => error.ErrorMessage).ToList(); return(Json(errors, JsonRequestBehavior.AllowGet)); }
public ActionResult ConfirmEmail(string userId) { if (userId == null) { return(View("Error")); } var usermanager = IdentityTools.NewUserManager(); ApplicationUser user = new ApplicationUser(); NeYapsakContext ent = new NeYapsakContext(); user = ent.Users.Where(u => u.Id == userId).FirstOrDefault(); if (user != null) { user.EmailConfirmed = true; ent.SaveChanges(); } else { return(View("Error")); } return(View("ConfirmEmail")); }