/// <summary> /// 切换用户 /// </summary> /// <returns></returns> public ActionResult ChangeUser() { if (_Request == null) { _Request = Request; } if (_Response == null) { _Response = Response; } if (_Session == null) { _Session = Session; } SetRequest(_Request); UserInfo currUser = GetCurrentUser(_Request); if (currUser == null) { return(Json(new ReturnResult() { Success = false, Message = "非法操作" })); } string username = _Request["username"].ObjToStr(); if (username == "admin") { return(Json(new ReturnResult() { Success = false, Message = "没有权限" })); } Guid userId = UserOperate.GetUserIdByUserName(username); UserInfo userInfo = UserOperate.GetUserInfo(userId); if (userInfo == null) { return(Json(new ReturnResult() { Success = false, Message = "用户不存在" })); } userInfo.ClientBrowserWidth = currUser.ClientBrowserWidth; userInfo.ClientBrowserHeight = currUser.ClientBrowserHeight; CacheUserData(userInfo); //缓存cookie return(Json(new ReturnResult() { Success = true, Message = string.Empty })); }
/// <summary> /// 应用程序认证请求 /// </summary> /// <param name="sender">发送对象</param> /// <param name="e">事件参数</param> public void Application_AuthenticateRequest(object sender, EventArgs e) { HttpApplication app = (HttpApplication)sender; string username = string.Empty; if (app.Context.User != null && app.Context.User.Identity != null) { username = app.Context.User.Identity.Name; } int w = 0; int h = 0; if (app.Context.Request["nfm"].ObjToInt() == 1) { username = app.Context.Request["un"].ObjToStr(); //请求中自带的用户名 w = app.Context.Request["w"].ObjToInt(); h = app.Context.Request["h"].ObjToInt(); } if (!string.IsNullOrEmpty(username)) { UserInfo tempUserInfo = UserInfo.GetCurretnUser(app.Context); if (tempUserInfo == null || tempUserInfo.UserId == Guid.Empty || tempUserInfo.UserName.ToLower() != username.ToLower()) { Guid userId = UserOperate.GetUserIdByUserName(username); UserInfo userInfo = UserOperate.GetUserInfo(userId); if (w > 0 && h > 0) { userInfo.ClientBrowserWidth = w; userInfo.ClientBrowserHeight = h; } //缓存用户扩展信息 UserInfo.CacheUserExtendInfo(userInfo.UserName, userInfo.ExtendUserObject); //保存票据 FormsPrincipal.Login(userInfo.UserName, userInfo, UserInfo.ACCOUNT_EXPIRATION_TIME, app.Context); } FormsPrincipal.TrySetUserInfo(app.Context); } else { FormsPrincipal.TrySetUserInfo(app.Context); } }
/// <summary> /// 修改密码 /// </summary> /// <returns></returns> public JsonResult ChangePwd() { if (_Request == null) { _Request = Request; } SetRequest(_Request); UserInfo currUser = GetCurrentUser(_Request); if (currUser == null) { return(Json(new ReturnResult() { Success = false, Message = "您未登录系统或登录时间过长,请重新登录系统后再修改密码!" })); } string errMsg = string.Empty; string oldPwd = _Request.QueryEx("oldPwd").ObjToStr(); string newPwd = _Request.QueryEx("newPwd").ObjToStr(); UserInfo tempUserInfo = UserOperate.GetUserInfo(currUser.UserName, oldPwd, out errMsg); if (tempUserInfo == null) { return(Json(new ReturnResult() { Success = false, Message = "您当前登录密码输入不正确,请重新输入!" })); } bool rs = UserOperate.ModifyPassword(currUser.UserId, newPwd, out errMsg); if (rs) { CommonOperate.ExecuteUserOperateHandleMethod("AfterChangePwd", new object[] { currUser.UserName, oldPwd, newPwd }); } return(Json(new ReturnResult() { Success = rs, Message = errMsg })); }
public JsonResult UserLogin(string username, string userpwd, string valcode) { if (string.IsNullOrEmpty(username)) { return(Json(new LoginReturnResult() { Success = false, Message = "用户名不能为空", IsShowCode = false })); } if (_Request == null) { _Request = Request; } if (_Response == null) { _Response = Response; } string errMsg = string.Empty; //获取用户信息 string tempUserName = GetUserName(username); UserInfo userInfo = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg); if (!string.IsNullOrEmpty(errMsg)) { return(Json(new LoginReturnResult() { Success = false, Message = errMsg, IsShowCode = false })); } CacheUserData(userInfo); //缓存cookie //执行登录成功后的操作 CommonOperate.ExecuteUserOperateHandleMethod("AfterLoginSuccess", new object[] { _Request, _Response, username, userpwd, UserInfo.ACCOUNT_EXPIRATION_TIME }); return(Json(new LoginReturnResult() { Success = true, Message = string.Empty, Url = string.Empty })); }
public ActionResult UserLogin(string username, string userpwd, string valcode) { if (_Request == null) { _Request = Request; } if (_Response == null) { _Response = Response; } if (_Session == null) { _Session = Session; } string errMsg = string.Empty; ViewBag.IsShowValidateCode = "false"; bool isNoCode = _Request["isNoCode"].ObjToBool(); //是否不需要验证码 if (!isNoCode && _Session[LOGINERROR].ObjToInt() >= 2) { bool validatecode = false; if (_TempData.ContainsKey(SecurityController.VALIDATECODE)) { string code = _TempData[SecurityController.VALIDATECODE].ToString(); validatecode = valcode.ToLower() == code.ToLower(); } if (!validatecode) { return(Json(new LoginReturnResult() { Success = false, Message = "验证码错误!", IsShowCode = true })); } } //获取用户信息 string tempUserName = GetUserName(username); UserInfo userInfo = UserOperate.GetUserInfo(tempUserName, userpwd, out errMsg); if (!string.IsNullOrEmpty(errMsg)) { var isShowCode = false; _Session[LOGINERROR] = _Session[LOGINERROR] == null ? 0 : _Session[LOGINERROR].ObjToInt() + 1; if (!isNoCode && _Session[LOGINERROR].ObjToInt() >= 2) { isShowCode = true; } return(Json(new LoginReturnResult() { Success = false, Message = errMsg, IsShowCode = isShowCode })); } CacheUserData(userInfo); //缓存cookie //执行登录成功后的操作 CommonOperate.ExecuteUserOperateHandleMethod("AfterLoginSuccess", new object[] { _Session, _Request, _Response, username, userpwd, UserInfo.ACCOUNT_EXPIRATION_TIME }); return(Json(new LoginReturnResult() { Success = true, Message = string.Empty, Url = HttpUtility.UrlEncode(string.Empty) })); }