public AdminController() { if (System.Web.HttpContext.Current.Session["useremail"] != null) { PhotoGraphyDbContext dc = new PhotoGraphyDbContext(); string useremail = (string)System.Web.HttpContext.Current.Session["useremail"]; var ax = dc.Admins.Where(z => z.Email == useremail).FirstOrDefault(); AdminId = ax.AdminId; } else { RedirectToAction("Login", "Account"); } }
public ActionResult Login(VLogin login, string ReturnUrl = "") { string message = ""; using (PhotoGraphyDbContext dc = new PhotoGraphyDbContext()) { var v = dc.Clients.Where(a => a.Email == login.EmailID).FirstOrDefault(); var p = dc.PhotoGraphers.Where(x => x.Email == login.EmailID).FirstOrDefault(); var ax = dc.Admins.Where(z => z.Email == login.EmailID).FirstOrDefault(); if (v != null) { if (string.Compare(login.Password, v.Password) == 0) { int timeout = login.RememberMe ? 2 : 5; var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { Session["useremail"] = v.ClientId; Session["FullName"] = v.Name; return(RedirectToAction("Index", "Client")); // Response.Write("<script>alert('Welcome to User')</script>"); } } else { message = "Invalid Email Or Password"; } } else if (p != null) { var block = dc.Blocks.Where(z => z.Fk_PhotoGrapherID == p.PhotoGrapherId).SingleOrDefault(); var warn = dc.Warns.Where(z => z.Fk_PhotoGrapherID == p.PhotoGrapherId).SingleOrDefault(); //Warn warn = dc.Warns.Find(p.PhotoGrapherId); if (string.Compare(login.Password, p.Password) == 0) { if (block == null) { int timeout = login.RememberMe ? 2 : 1; var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { Session["useremail"] = p.PhotoGrapherId; Session["FullName"] = p.FullName; if (warn == null) { return(RedirectToAction("Index", "PhotoGrapher")); } else { return(RedirectToAction("Warning", "PhotoGrapher")); } // Response.Write("<script>alert('Welcome to User')</script>"); } } else { return(RedirectToAction("Block", "Account")); } } else { message = "Invalid Email Or Password"; } } else if (ax != null) { if (string.Compare(login.Password, ax.Password) == 0) { int timeout = login.RememberMe ? 2 : 1; var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { Session["useremail"] = ax.Email; Session["FullName"] = ax.Name; return(RedirectToAction("Index", "Admin")); // Response.Write("<script>alert('Welcome to User')</script>"); } } else { message = "Invalid Email Or Password"; } } else { message = "Invalid UserName Or Password"; } } ViewBag.Message = message; return(View()); }