AccountController.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Transactions;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using System.Web.Security;
  8. using DotNetOpenAuth.AspNet;
  9. using Microsoft.Web.WebPages.OAuth;
  10. using WebMatrix.WebData;
  11. using EMISOnline.Web.Filters;
  12. using EMISOnline.Web.Models;
  13. using Bowin.Common;
  14. using Bowin.Common.Utility;
  15. using EMISOnline.ViewModel.Account;
  16. using EMISOnline.CommonLogic.SystemServices;
  17. using EMISOnline.ViewModel.SystemView;
  18. using EMISOnline.ViewModel;
  19. using EMISOnline.Web.Controls;
  20. namespace EMISOnline.Web.Controllers
  21. {
  22. //[Authorize]
  23. [Authorization]
  24. public class AccountController : Controller
  25. {
  26. public IUserServices UserServices { get; set; }
  27. //
  28. // GET: /Account/Login
  29. [AllowAnonymous]
  30. public ActionResult Login(string returnUrl)
  31. {
  32. ViewBag.ReturnUrl = returnUrl;
  33. var model = this.GetUserCookies();
  34. if (model != null)
  35. {
  36. return View(model);
  37. }
  38. return View();
  39. }
  40. public ActionResult Register()
  41. {
  42. RegisterModel model = new RegisterModel();
  43. return View(model);
  44. }
  45. //
  46. // POST: /Account/Login
  47. [HttpPost]
  48. [AllowAnonymous]
  49. public ActionResult Login(LogOnModel model, string returnUrl)
  50. {
  51. if (ModelState.IsValid)
  52. {
  53. try
  54. {
  55. if (model.VerifyCode != Session["code"] as string)
  56. {
  57. ModelState.AddModelError("", "请输入正确的验证码!");
  58. return View(model);
  59. }
  60. if (UserServices.Login(model.UserName, model.Password))
  61. {
  62. try
  63. {
  64. this.LoginSureccessful(model, model.UserName);
  65. return RedirectToAction("Index", "Home");
  66. }
  67. catch (Exception ex)
  68. {
  69. ModelState.AddModelError("", ex.Message);
  70. return View(model);
  71. }
  72. }
  73. else
  74. {
  75. ModelState.AddModelError("", "用户名或密码不正确请检查后重新输入!");
  76. this.RemoveUserCookies(model);
  77. return View(model);
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. this.RemoveUserCookies(model);
  83. ModelState.AddModelError("", "提供的用户名或密码不正确。");
  84. throw ex;
  85. }
  86. }
  87. return View(model);
  88. }
  89. private LogOnModel GetUserCookies()
  90. {
  91. LogOnModel model = new LogOnModel();
  92. HttpCookie cookie = HttpContext.Request.Cookies["username"];
  93. if (cookie != null)
  94. {
  95. model.UserName = cookie.Value;
  96. }
  97. HttpCookie cookie2 = HttpContext.Request.Cookies["password"];
  98. if (cookie2 != null)
  99. {
  100. model.Password = cookie2.Value;
  101. }
  102. HttpCookie cookie3 = HttpContext.Request.Cookies["rememberme"];
  103. if (cookie != null)
  104. {
  105. model.RememberMe = cookie3.Value.ToLower() == "true";
  106. }
  107. return model;
  108. }
  109. //
  110. // POST: /Account/LogOff
  111. public ActionResult LogOff()
  112. {
  113. var cookieName = EMISOnline.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
  114. HttpCookie cookie = new HttpCookie(cookieName);
  115. cookie.Value = "";
  116. cookie.Expires = DateTime.Now.AddDays(-1);
  117. Response.Clear();
  118. Response.AppendCookie(cookie);
  119. if (EMISOnline.Utility.Const.SSO_IS_SSO_LOGIN)
  120. {
  121. return Redirect(EMISOnline.Utility.Const.SSO_HOST + "/Account/LogOff?url=" + HttpContext.Request.Url.AbsoluteUri);
  122. }
  123. else
  124. {
  125. return RedirectToAction("Index", "Home");
  126. }
  127. }
  128. [AllowAnonymous]
  129. public ActionResult ForgotPassword(string loginID)
  130. {
  131. return View();
  132. }
  133. public ActionResult ChangePassword()
  134. {
  135. return View();
  136. }
  137. }
  138. }