Guest User

Untitled

a guest
May 3rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. [HttpPost]
  2. public ActionResult Index(string username,string password)
  3. {
  4.  
  5. User user = db.Users.Where(t => t.username == username && t.password == password).SingleOrDefault();
  6. if (user != null)
  7. {
  8.  
  9. HttpCookie aCookie = new HttpCookie("cookie");
  10. aCookie.Values["username"] = username;
  11. aCookie.Values["role"] = user.role.ToString();
  12. aCookie.Values["UserID"] = user.UserID.ToString();
  13. aCookie.Values["route"] = "AdminReports";
  14. aCookie.Secure = false;
  15. aCookie.Expires = DateTime.Now.AddDays(1);
  16. Response.Cookies.Add(aCookie);
  17.  
  18. isLogedIn = true;
  19. return RedirectToAction("AdminReports", "Home");
  20. }
  21. TempData["ErrorMessage"] = "Wrong username or password!";
  22. return View();
  23. }
  24.  
  25. public ActionResult AdminReports()
  26. {
  27.  
  28.  
  29.  
  30.  
  31. Response.Write(Server.HtmlEncode(Request.Cookies["cookie"]["username"]));
  32. // Response.Write(Request.Cookies["cookie"]["username"]);
  33.  
  34.  
  35. if (Request.Cookies["cookie"] != null)
  36. {
  37. if (Convert.ToInt32(Request.Cookies["cookie"]["role"]) == (int)Enums.Role.Admin)
  38. {
  39.  
  40. return View();
  41. }
  42. else if (Convert.ToInt32(Request.Cookies["cookie"]["role"]) == (int)Enums.Role.The70Hospitals)
  43. {
  44.  
  45. return View("The70Hospitals");
  46. }
  47. else if (Convert.ToInt32(Request.Cookies["cookie"]["role"]) == (int)Enums.Role.The380Hospitals)
  48. {
  49.  
  50. return View("The380Hospitals");
  51. }
  52. else
  53. {
  54. return View("LoginView");
  55. }
  56. }
  57. else
  58. {
  59. return View("LoginView");
  60. }
  61. }
Add Comment
Please, Sign In to add comment