123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Transactions;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Security;
- using DotNetOpenAuth.AspNet;
- using Microsoft.Web.WebPages.OAuth;
- using WebMatrix.WebData;
- using EMISOnline.Web.Filters;
- using EMISOnline.Web.Models;
- using Bowin.Common;
- using Bowin.Common.Utility;
- using EMISOnline.ViewModel.Account;
- using EMISOnline.CommonLogic.SystemServices;
- using EMISOnline.ViewModel.SystemView;
- using EMISOnline.ViewModel;
- using EMISOnline.Web.Controls;
- namespace EMISOnline.Web.Controllers
- {
- //[Authorize]
- [Authorization]
- public class AccountController : Controller
- {
- public IUserServices UserServices { get; set; }
- //
- // GET: /Account/Login
- [AllowAnonymous]
- public ActionResult Login(string returnUrl)
- {
- ViewBag.ReturnUrl = returnUrl;
- var model = this.GetUserCookies();
- if (model != null)
- {
- return View(model);
- }
- return View();
- }
- public ActionResult Register()
- {
- RegisterModel model = new RegisterModel();
- return View(model);
- }
- //
- // POST: /Account/Login
- [HttpPost]
- [AllowAnonymous]
- public ActionResult Login(LogOnModel model, string returnUrl)
- {
- if (ModelState.IsValid)
- {
- try
- {
- if (model.VerifyCode != Session["code"] as string)
- {
- ModelState.AddModelError("", "请输入正确的验证码!");
- return View(model);
- }
- if (UserServices.Login(model.UserName, model.Password))
- {
- try
- {
- this.LoginSureccessful(model, model.UserName);
- return RedirectToAction("Index", "Home");
- }
- catch (Exception ex)
- {
- ModelState.AddModelError("", ex.Message);
- return View(model);
- }
- }
- else
- {
- ModelState.AddModelError("", "用户名或密码不正确请检查后重新输入!");
- this.RemoveUserCookies(model);
- return View(model);
- }
- }
- catch (Exception ex)
- {
- this.RemoveUserCookies(model);
- ModelState.AddModelError("", "提供的用户名或密码不正确。");
- throw ex;
- }
- }
- return View(model);
- }
- private LogOnModel GetUserCookies()
- {
- LogOnModel model = new LogOnModel();
- HttpCookie cookie = HttpContext.Request.Cookies["username"];
- if (cookie != null)
- {
- model.UserName = cookie.Value;
- }
- HttpCookie cookie2 = HttpContext.Request.Cookies["password"];
- if (cookie2 != null)
- {
- model.Password = cookie2.Value;
- }
- HttpCookie cookie3 = HttpContext.Request.Cookies["rememberme"];
- if (cookie != null)
- {
- model.RememberMe = cookie3.Value.ToLower() == "true";
- }
- return model;
- }
- //
- // POST: /Account/LogOff
- public ActionResult LogOff()
- {
- var cookieName = EMISOnline.Utility.Const.LOCAL_SETTING_LOGIN_COOKIENAME;
- HttpCookie cookie = new HttpCookie(cookieName);
- cookie.Value = "";
- cookie.Expires = DateTime.Now.AddDays(-1);
- Response.Clear();
- Response.AppendCookie(cookie);
- if (EMISOnline.Utility.Const.SSO_IS_SSO_LOGIN)
- {
- return Redirect(EMISOnline.Utility.Const.SSO_HOST + "/Account/LogOff?url=" + HttpContext.Request.Url.AbsoluteUri);
- }
- else
- {
- return RedirectToAction("Index", "Home");
- }
- }
- [AllowAnonymous]
- public ActionResult ForgotPassword(string loginID)
- {
- return View();
- }
- public ActionResult ChangePassword()
- {
- return View();
- }
- }
- }
|