public object DownFileData(int Restype, long SeqID, string ColumnName) { if (userLoginManager.LoginUser == null || userLoginManager.LoginUser.UserID < 1) return new { Rcode = -2, Rdata = "未登录" }; string userIP = null; string tablename, serviceno, orderno; int costtype; decimal m_price, m_discount; int status = BaseBLL.GetFullPathResourceCheckCost(Restype, SeqID, userLoginManager.LoginUser.UserID, userLoginManager.LoginUser.Customerid, userIP, out tablename, out costtype, out m_price, out m_discount, out serviceno, out orderno, out errmsg); if (status == -1) return new { Rcode = -1, Rmsg = errmsg }; if (status == 0) return new { Rcode = -3, Rmsg = "此资源需要付费才能下载,现在去付费", Rdata = orderno }; BookInfo bookinfo = ResourcesBLL.GetFilePath(tablename, SeqID, 0, ColumnName, out errmsg); if (!string.IsNullOrEmpty(errmsg) || bookinfo == null) return new { Rcode = -1, Rmsg = "获取资源数据错误" + errmsg }; if (string.IsNullOrEmpty(bookinfo.BookPath)) { return new { Rcode = -1, Rmsg = "资源文件路径不存在" }; } string pdffile = string.Format("{0}{1}", GlobalParameters.RootFilePath, bookinfo.BookPath).Replace("//", "/").Replace("/", "\\"); if (!File.Exists(pdffile)) { return new { Rcode = -1, Rmsg = "资源文件不存在" }; } string filecode = StrFormatClass.Encrypt(bookinfo.BookPath + DateTime.Now.ToString("yyyyMMddHHmmss"), ref errmsg); return new { Rcode = 1, Rdata = filecode }; }
public object DownFile(string filecode) { if (string.IsNullOrEmpty(filecode)) { HttpContext.Current.Response.Write("参数错误"); HttpContext.Current.Response.End(); return null; } string filepath = StrFormatClass.Decrypt(filecode, ref errmsg); if (!string.IsNullOrEmpty(errmsg) || string.IsNullOrEmpty(filepath) || filepath.Length <= 14) { HttpContext.Current.Response.Write("参数解析错误"); HttpContext.Current.Response.End(); return null; } filepath = filepath.Substring(0, filepath.Length - 14); string filename = Models.GlobalParameters.RootFilePath + filepath; if (!File.Exists(filename)) { HttpContext.Current.Response.Write("文件不存在"); HttpContext.Current.Response.End(); return null; } string fname = Path.GetFileName(filename); //文件名 string str = "attachment;filename=" + fname; //把文件头输出,此文件头激活文件下载框 HttpContext.Current.Response.AppendHeader("Content-Disposition", str);//http报头文件 HttpContext.Current.Response.ContentType = "application/octet-stream"; HttpContext.Current.Response.WriteFile(filename); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); return null; }
public bool WriteCookie(UserInfoViewModel userInfoVM, ref string errmsg) { string userData = JsonConvert.SerializeObject(userInfoVM); if (string.IsNullOrEmpty(userData)) { errmsg = "序列化错误"; return(false); } string encTicket = StrFormatClass.Encrypt(userData, ref errmsg); if (string.IsNullOrEmpty(encTicket) || !string.IsNullOrEmpty(errmsg)) { return(false); } HttpCookie cookie = new HttpCookie("CIRSUser", encTicket) { HttpOnly = true, Secure = FormsAuthentication.RequireSSL, Domain = FormsAuthentication.CookieDomain, Path = FormsAuthentication.FormsCookiePath, Expires = DateTime.Today.AddDays(1) }; HttpContext.Current.Response.Cookies.Add(cookie); return(true); }
public UserInfoViewModel Readcookie(ref string errmsg) { HttpCookie cookie = HttpContext.Current.Request.Cookies["CIRSUser"]; if (cookie == null || string.IsNullOrEmpty(cookie.Value)) { errmsg = "未登录"; return(null); } string decTicket = StrFormatClass.Decrypt(cookie.Value, ref errmsg); if (string.IsNullOrEmpty(decTicket) || !string.IsNullOrEmpty(errmsg)) { errmsg = "解密用户认证数据错误"; return(null); } UserInfoViewModel userData; try { userData = JsonConvert.DeserializeObject <UserInfoViewModel>(decTicket); } catch { errmsg = "反序列化错误"; userData = null; } return(userData); }
public object UserReg(base_user_extend userinfo) { string errmsg = null; if (userinfo.yzmcode == null || userinfo.yzmcode.Length != 6) { return(new { Rcode = -1, Rmsg = "注册失败:请填写验证码" }); } base_identifycode identifycode = BLL.BaseBLL.GetIdentifyCodeInfo(userinfo.phone, userinfo.email, userinfo.yzmcode, out errmsg); if (identifycode == null) { return new { Rcode = 0, Rmsg = "验证码错误" } } ; else if (DateTime.Now > identifycode.endtime) { return new { Rcode = 0, Rmsg = "验证码超时,请重新获取验证码" } } ; userinfo.passwd = StrFormatClass.MD5ToDepth(userinfo.passwd); userinfo.usertype = 1; userinfo.userlevel = 1; userinfo.sourcetype = 1; userinfo.customerid = 0; userinfo.status = 1; userinfo.grade = 0; userinfo.period = 0; userinfo.classname = "."; userinfo.school = "."; int userid = userLoginManager.UserReg(userinfo, out errmsg); if (userid > 0) { base_userlogs log = new base_userlogs() { logtype = 21, // 21 注册; 22 登录; restype = "0", rescode = userid.ToString(), logcontent = string.Format("注册用户{0}", userinfo.username), creator = 0, createdtime = DateTime.Now }; BLL.BaseBLL.WriteUserLog(log, out errmsg);//记录注册日志 return(new { Rcode = 1, Rdata = userid }); } else if (!string.IsNullOrEmpty(errmsg)) { return(new { Rcode = -1, Rmsg = "注册失败:" + errmsg }); } else { return(new { Rcode = 0, Rmsg = "注册失败" }); } }
public object PutUserPwd(string pwd) { string errmsg = null; if (userLoginManager.LoginUser == null || userLoginManager.LoginUser.UserID < 1) { return new { Rcode = 0, Rmsg = "未登录" } } ; int userid = userLoginManager.LoginUser.UserID; pwd = StrFormatClass.MD5ToDepth(pwd); bool success = BLL.UserLoginManager.PutUserPwd(userid, pwd, out errmsg); if (!success || !string.IsNullOrEmpty(errmsg)) { return new { Rcode = -1, Rmsg = "修改失败" } } ; return(new { Rcode = 1, Rmsg = "修改失败" }); }
public object GetUserPwd(string pwd) { string errmsg = null; if (userLoginManager.LoginUser == null || userLoginManager.LoginUser.UserID < 1) { return new { Rcode = 0, Rmsg = "未登录" } } ; int userid = userLoginManager.LoginUser.UserID; pwd = StrFormatClass.MD5ToDepth(pwd); base_users info = BLL.UserLoginManager.GetUserPwd(userid, pwd, out errmsg); if (info == null || !string.IsNullOrEmpty(errmsg)) { return new { Rcode = -1, Rmsg = "获取数据错误" } } ; return(new { Rcode = 1 }); }
public object UserLogin(UserLoginViewModel user) { if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Password)) { return(new { Rcode = 0, Rmsg = "请输入完整的用户名密码" }); } string errmsg = null; user.Password = StrFormatClass.MD5ToDepth(user.Password); UserInfoViewModel userInfo = userLoginManager.UserLogin(user.UserName, user.Password, null, out errmsg); if (!string.IsNullOrEmpty(errmsg)) { return new { Rcode = -1, Rmsg = "登录错误" + errmsg } } ; else if (userInfo == null || userInfo.UserID < 1) { return new { Rcode = 0, Rmsg = "用户名或密码错误" } } ; else { base_userlogs log = new base_userlogs() { logtype = 22, restype = "0", rescode = userInfo.UserID.ToString(), logcontent = string.Format("登录用户{0}", user.UserName), creator = 0, createdtime = DateTime.Now }; BLL.BaseBLL.WriteUserLog(log, out errmsg);//记录登录日志 return(new { Rcode = 1, Rdata = userInfo }); } }
public object UserFindPasswd(base_users userinfo) { string errmsg = null; if (userinfo.yzmcode == null || userinfo.yzmcode.Length != 6) { return(new { Rcode = -1, Rmsg = "找回密码失败:请填写验证码" }); } base_identifycode identifycode = BLL.BaseBLL.GetIdentifyCodeInfo(userinfo.phone, userinfo.email, userinfo.yzmcode, out errmsg); if (identifycode == null) { return new { Rcode = 0, Rmsg = "验证码错误" } } ; else if (DateTime.Now > identifycode.endtime) { return new { Rcode = 0, Rmsg = "验证码超时,请重新获取验证码" } } ; userinfo.passwd = StrFormatClass.MD5ToDepth(userinfo.passwd); bool issuc = userLoginManager.UserFindPasswd(userinfo, out errmsg); if (!string.IsNullOrEmpty(errmsg)) { return(new { Rcode = -1, Rmsg = "找回密码失败:" + errmsg }); } if (issuc) { return(new { Rcode = 1, Rmsg = "ok" }); } else { return(new { Rcode = 0, Rmsg = "找回密码失败" }); } }