public PlantEngContext() { ILoginAdapter login = new LoginAdapter(); if(login.IsClientLogin()){ LoginUserInfo = login.GetLoginedUserInfo(); } }
public ActionResult Rest(FormCollection fc) { string method = CECRequest.GetQueryString("method").ToLower(); #region == 登录 == if (method == "login") { string userName = CECRequest.GetFormString("username"); string password = CECRequest.GetFormString("password"); string returnUrl = CECRequest.GetQueryString("url"); var userInfo = MemberService.Get(userName); if (userInfo.Id > 0 && userInfo.Password == password) { //写登录Cookie ILoginAdapter la = new LoginAdapter(); la.WriteLoginCookie(new LoginUserInfo() { Email = userInfo.Email, UserId = userInfo.Id, RoleId = (int)userInfo.Type, UserName = userInfo.UserName, Password = userInfo.Password }); } else { return Content("<script type=\"text/javascript\">alert(\"用户名或密码错误,请重新输入!\");location.href = location.href;</script>"); } if (!string.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } } #endregion #region == 登出 == if (method == "logout") { string returnUrl = CECRequest.GetQueryString("url"); ILoginAdapter la = new LoginAdapter(); if (la.IsClientLogin()) { la.LoginOut(); } if (!string.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } } #endregion #region == 是否在线 == if (method == "isolineuser") { var userName = CECRequest.GetFormString("UserName"); var userPwd = CECRequest.GetFormString("PassWord"); var memberInfo = MemberService.Get(userName); if (memberInfo.Id > 0 && memberInfo.Password == userPwd) { return Content("true"); } return Content("false"); } #endregion #region == 获取用户信息 == if (method == "getuserinfo") { StringBuilder sb = new StringBuilder(); var userName = CECRequest.GetFormString("UserName"); var memberInfo = MemberService.Get(userName); if (memberInfo.Id > 0) { sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); sb.Append("<root>"); sb.AppendFormat("<Email>{0}</Email>", memberInfo.Email); sb.AppendFormat("<MobilePhone>{0}</MobilePhone>", memberInfo.Mobile); sb.AppendFormat("<Realname>{0}</Realname>", memberInfo.RealName); sb.Append("</root>"); } return Content(sb.ToString()); } #endregion return Content(string.Empty); }