public ReturnValue editPassword(string oldPassword, string password) { return(UserClass.editPassword(id, oldPassword, password, this)); }
public static ReturnValue login(double userId, int hour) { string ip = Tools.IPToNumber("127.0.0.1").ToString();// Tools.IPToNumber(M5.PageContext.Current.Request.UserHostAddress).ToString(); ReturnValue err = new ReturnValue(); UserInfo info = UserClass.get(userId); /*if (!info.ipAccess(M5.PageContext.Current.Request.UserHostAddress)) * { * err.errNo = -1; * err.errMsg = "您的ip不能登陆"; * return err; * }*/ err.errNo = 0; //添加登陆信息 //添加登陆日志 string sessionId = (M5.PageContext.Current.Request.Cookies["M5_SessionId"] == null) ? "" : M5.PageContext.Current.Request.Cookies["M5_SessionId"]; if (sessionId == "") { sessionId = Tools.GetId(); M5.PageContext.Current.Response.Cookies.Append("M5_SessionId", sessionId); } Sql.ExecuteNonQuery("update m_admin set loginDateTime=loginDateTime where id=@id", new MySqlParameter[] { new MySqlParameter("id", userId), new MySqlParameter("loginDateTime", DateTime.Now), }); Sql.ExecuteNonQuery("delete from logininfo where logindate<@logindate or sessionId=@sessionId", new MySqlParameter[] { new MySqlParameter("sessionId", sessionId), new MySqlParameter("logindate", DateTime.Now.AddHours(-1)), }); //删除超时用户及重登陆用户 Sql.ExecuteNonQuery("insert logininfo (sessionId,ip,logindate,userid)values(@sessionId,@ip,@logindate,@userId)", new MySqlParameter[] { new MySqlParameter("sessionId", sessionId), new MySqlParameter("ip", ip), new MySqlParameter("userId", userId), new MySqlParameter("logindate", DateTime.Now), }); err.userData = info; if (info.classId == 0) { M5.PageContext.Current.Response.Cookies.Append("M5_Login", "true"); } else { M5.PageContext.Current.Response.Cookies.Append("M5_Login", ""); } M5.PageContext.Current.Response.Cookies.Append("u_name", HttpUtility.UrlEncode(info.username)); M5.PageContext.Current.Response.Cookies.Append("u_id", info.id.ToString()); /*HttpCookie cook = new HttpCookie("u_name"); * if (hour > 0) cook.Expires = System.DateTime.Now.AddHours(hour); * cook.Value = HttpUtility.UrlEncode(info.username); * PageContext.Current.Response.Cookies.Add(cook); * cook = new HttpCookie("u_id"); * if (hour > 0) cook.Expires = System.DateTime.Now.AddHours(hour); * cook.Value = info.id.ToString(); * PageContext.Current.Response.Cookies.Add(cook);*/ //PageContext.Current.Response.Cookies["u_name"].Value = HttpUtility.UrlEncode(info.username); //PageContext.Current.Response.Cookies["u_id"].Value = info.id.ToString(); Tools.writeLog("login", info.username + "登陆成功"); return(err); }