public async Task <ActionResult> Index(LoginInfo loginInfoInfo, string ReturnUrl) { if (ModelState.IsValid) { var authSystem = new AuthenticationSystem(HttpContext.GetOwinContext().Authentication); ///// STSTEM Admin Login ///// if (loginInfoInfo.UserName == "sysadmin" && loginInfoInfo.Password == "sys123") { bool isAdminRegistered = await authSystem.IsUserRegistered(loginInfoInfo.UserName, loginInfoInfo.Password); if (isAdminRegistered) { await authSystem.SignInAsync(loginInfoInfo.UserName, loginInfoInfo.Password, false); } else { await authSystem.CreateAndSignInAsync(loginInfoInfo.UserName, loginInfoInfo.Password, false); } if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } ///// STSTEM Admin Login ///// bool isValidUser = db.Doctors.Count(d => d.UserName == loginInfoInfo.UserName && d.Password == loginInfoInfo.Password) > 0; if (isValidUser) { await authSystem.SignInAsync(loginInfoInfo.UserName, loginInfoInfo.Password, loginInfoInfo.RememberMe); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } } return(View()); }
public async Task <ActionResult> Create([Bind(Include = "DoctorId,Name,Degree,Specialization,Email,Phone,UserName,Password,ImagePath,Fee")] Doctor doctor, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { if (imageFile != null) { imageFile.SaveAs(HttpContext.Server.MapPath("~/Images/" + imageFile.FileName)); doctor.ImagePath = imageFile.FileName; } // create authentication user id var authSystem = new AuthenticationSystem(HttpContext.GetOwinContext().Authentication); await authSystem.CreateWithoutSignInAsync(doctor.UserName, doctor.Password); db.Doctors.Add(doctor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(doctor)); }