public ActionResult Registration(RegistrationViewModel registrationViewModel) { //using (var db = new DataBaseConnectionDataContext()) //{ //} if (ModelState.IsValid) { var notConfirmedUser = new NotConfirmedUser() { FirstName = registrationViewModel.FirstName, LastName = registrationViewModel.LastName, Email = registrationViewModel.Email, Password = AccountHelper.GetHash256ByString(registrationViewModel.Password + AccountHelper.AuthSecret), ConfirmationCode = AccountHelper.RandomString(), CreateDate = DateTime.Now, RequestIp = Request.UserHostAddress }; db.NotConfirmedUsers.InsertOnSubmit(notConfirmedUser); db.SubmitChanges(); ModelState.Clear(); } return(Content("თქვენ წარმატებით გაიარეთ რეგისტრაცია")); }
public ActionResult Registration(RegistrationViewModel registrationViewModel) { if (String.IsNullOrEmpty(registrationViewModel.Name) || String.IsNullOrEmpty(registrationViewModel.SurName) || String.IsNullOrEmpty(registrationViewModel.Email) || String.IsNullOrEmpty(registrationViewModel.Password) || String.IsNullOrEmpty(registrationViewModel.RepeatPassword)) { ViewBag.error = "საჭიროა ყველა ველის შევსება"; return(View()); } if (registrationViewModel.Password != registrationViewModel.RepeatPassword) { ViewBag.error = "პაროლები არ ემთხვევა"; return(View()); } var NotConfirmedUser = new NotConfirmedUser() { Name = registrationViewModel.Name, Surname = registrationViewModel.SurName, Email = registrationViewModel.Email, Password = Helper.ComputeSha256Hash(registrationViewModel.Password + Helper.AuthKey), CreateDate = DateTime.Now, ConfirmationCode = Helper.RandomString(), RequestIp = Request.UserHostAddress, }; db.NotConfirmedUsers.InsertOnSubmit(NotConfirmedUser); db.SubmitChanges(); return(RedirectToAction("succes", new { email = NotConfirmedUser.Email })); }
public ActionResult Registration(RegistrationViewModel registrationViewModel) { if (String.IsNullOrEmpty(registrationViewModel.name) || String.IsNullOrEmpty(registrationViewModel.surName) || String.IsNullOrEmpty(registrationViewModel.mail) || String.IsNullOrEmpty(registrationViewModel.birthdate) || String.IsNullOrEmpty(registrationViewModel.dog_breed) || String.IsNullOrEmpty(registrationViewModel.password) || String.IsNullOrEmpty(registrationViewModel.repeatPassword)) { ViewBag.error = "საჭიროა ყველა ველის შევსება"; return(View()); } else if (!ModelState.IsValid) { return(View(registrationViewModel)); } else if (db.ConfirmedUsers.Where(x => x.Email == registrationViewModel.mail).Count() > 0) //ეს კაი როჯაა { ViewBag.error = "ელფოსტა უკვე დარეგისტრირებულია !"; return(View()); } else if (registrationViewModel.password != registrationViewModel.repeatPassword) { ViewBag.error = "პაროლები არ ემთხვევა"; return(View()); } else { string confirmCode = Helper.RandomString(); var NotConfirmedUser = new NotConfirmedUser() { Name = registrationViewModel.name, Surname = registrationViewModel.surName, BirthDate = registrationViewModel.birthdate, DogBreed = registrationViewModel.dog_breed, Email = registrationViewModel.mail, Password = Helper.ComputeSha256Hash(registrationViewModel.password + Helper.AuthKey), CreateDate = DateTime.Now, ConfirmationCode = confirmCode, RequestIp = Request.UserHostAddress, }; db.NotConfirmedUsers.InsertOnSubmit(NotConfirmedUser); db.SubmitChanges(); // მაილზე კოდის გაგზავნა try { if (ModelState.IsValid) { var senderEmail = new MailAddress("მაილი", "veterinar"); var receiverEmail = new MailAddress(registrationViewModel.mail, "Receiver"); var password = "******"; var sub = "ელ.ფოსტის დადასტურება"; var body = "დაადასტურეთ თქვენი ელ.ფოსტა მოცემულ ლინკზე გადასვლით: http://localhost:54637/Account/Confirmation/" + confirmCode; // view რო გვექნება მერე გავტესტავ, წესით უდნა იმუშაოს. შენ რომ გაუშვებ localHost შეცვალე var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, password) }; using (var mess = new MailMessage(senderEmail, receiverEmail) { Subject = sub, Body = body }) { smtp.Send(mess); } return(RedirectToAction("succes", new { email = NotConfirmedUser.Email })); } } catch (Exception) { ViewBag.Error = "Some Error"; } return(View()); } }