public ActionResult Login(NewLoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { ModelState.AddModelError("", "Niepoprawne dane."); return(View(model)); } bool isPatientInDB = false, isAdminInDB = false; List <Patient> patient; List <Admin> admins; using (SurgeryModel db = new SurgeryModel()) { patient = (from p in db.Patients where p.PatientAccount_Login == model.Login && p.PatientAccount_Password == model.Password select p).ToList(); admins = (from p in db.Admins where p.Login == model.Login && p.Password == model.Password select p).ToList(); if (patient.Count == 1) { isPatientInDB = true; } else if (admins.Count == 1) { isAdminInDB = true; } } if (!isPatientInDB && !isAdminInDB) { ModelState.AddModelError("", "Niepoprawny login lub/i hasło."); return(View(model)); } if (isAdminInDB) { System.Web.Security.FormsAuthentication.SetAuthCookie("Admin", false); HttpContext.Response.AppendCookie(new HttpCookie("user", "admin")); return(RedirectToAction("Index", "Admin", null)); } else { var P = patient[0]; //ViewBag["Role"] = "Patient"; ViewBag.Id = P.Id; System.Web.Security.FormsAuthentication.SetAuthCookie($"{P.Name} {P.Surname}", false); HttpContext.Response.AppendCookie(new HttpCookie("user", "patient")); HttpContext.Response.AppendCookie(new HttpCookie("user_id", $"{P.Id}")); return(RedirectToAction("Main", "Patients", new { id = P.Id })); //znak - to jest jeszcze źle } }
public async Task <IActionResult> EditConfirmed(NewLoginViewModel model) { if (model.Password == model.PasswordConfirmation) { var user = await Auth.GetConnectedUserAsync(); var token = await UserManager.GeneratePasswordResetTokenAsync(user); var result = await UserManager.ResetPasswordAsync(user, token, model.Password); return(RedirectToAction("List", "Poll")); } else { ViewData["Message"] = "Le mot de passe et la confirmation ne correspondent pas!"; return(View(model)); } }
public async Task <IActionResult> UpdatePasswordConfirmed(NewLoginViewModel model) { if (model.Password == model.PasswordConfirmation) { var user = await(from u in PollContext.Users where u.UserName == model.UserName select u).SingleAsync(); var token = await UserManager.GeneratePasswordResetTokenAsync(user); var result = await UserManager.ResetPasswordAsync(user, token, model.Password); return(RedirectToAction("ListUsers")); } else { ViewData["Message"] = "Le mot de passe et la confirmation ne correspondent pas!"; return(View(model)); } }
public async Task <IActionResult> CreateConfirmed(NewLoginViewModel newUser) { if (newUser.Password == newUser.PasswordConfirmation) { var u = new UserHelper(); var roleStore = new RoleStore <IdentityRole <long>, PollContext, long>(PollContext); var firstUser = !PollContext.Users.Any(); var user = new User() { Email = u.RandomiseEmail(), UserName = newUser.UserName, SecurityStamp = Guid.NewGuid().ToString() }; if (firstUser) { user.Id = 1; } var result = await UserManager.CreateAsync(user, newUser.Password); if (firstUser) { await AddFirstUser(user, roleStore); } if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("ListNewPolls", "Poll")); } else { throw new IdentityException(result.Errors); } } else { ViewData["Message"] = "Le mot de passe et la onfirmation ne correspondent pas!"; return(View(new NewLoginViewModel())); } }
public async Task <ActionResult> NewLogin(NewLoginViewModel model) { if (ModelState.IsValid) { string photoURL = ""; if (model.Upload != null) { // получаем имя файла string fileName = System.IO.Path.GetFileName(model.Upload.FileName); photoURL = "/Content/UserImages/" + fileName; // сохраняем файл в папку Files в проекте model.Upload.SaveAs(Server.MapPath(photoURL)); } var user = _usersProvider.RegisterUser(model.Surname, model.Name, model.Middle_name, model.Email, model.Phone, model.Comments, photoURL, model.Password); UserContext.SetUser(user); // // наш email с заголовком письма // MailAddress from = new MailAddress("*****@*****.**", "Web Registration"); // // кому отправляем // MailAddress to = new MailAddress(model.Email); // // создаем объект сообщения // MailMessage m = new MailMessage(from, to); // // тема письма // m.Subject = "Email confirmation"; // // текст письма - включаем в него ссылку // m.Body = string.Format("Для завершения регистрации перейдите по ссылке:" + // "<a href=\"{0}\" title=\"Подтвердить регистрацию\">{0}</a>", // Url.Action("ConfirmEmail", "Account", new { Email = model.Email }, Request.Url.Scheme)); // m.IsBodyHtml = true; // // адрес smtp-сервера, с которого мы и будем отправлять письмо // SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25); // // логин и пароль // smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "ckfdbr16"); // smtp.Send(m); // return RedirectToAction("Confirm", "Account", new { Email = model.Email }); return(RedirectToAction("Profile")); } return(View(model)); }