using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebForm.Common { public class Tools { /// /// 包含文件 /// public static string IncludeFiles { get { return string.Format(@" " , BaseUrl, RoadFlow.Utility.Config.Theme); } } public static string BaseUrl { get { return ""; } } public static bool CheckLogin(out string msg) { msg = ""; object session = System.Web.HttpContext.Current.Session[RoadFlow.Utility.Keys.SessionKeys.UserID.ToString()]; Guid uid; if (session == null || !session.ToString().IsGuid(out uid) || uid == Guid.Empty) { return false; } //#if DEBUG return true; //正式使用时请注释掉这一行 //#endif string uniqueIDSessionKey = RoadFlow.Utility.Keys.SessionKeys.UserUniqueID.ToString(); var user = new RoadFlow.Platform.OnlineUsers().Get(uid); if (user == null) { return false; } else if (System.Web.HttpContext.Current.Session[uniqueIDSessionKey] == null) { return false; } else if (string.Compare(System.Web.HttpContext.Current.Session[uniqueIDSessionKey].ToString(), user.UniqueID.ToString(), true) != 0) { msg = string.Format("您的帐号在{0}登录,您被迫下线!", user.IP); return false; } return true; } public static bool CheckLogin(bool redirect = true) { string msg; if (!CheckLogin(out msg)) { if (!redirect) { System.Web.HttpContext.Current.Response.Write("登录验证失败!"); System.Web.HttpContext.Current.Response.End(); return false; } else { System.Web.HttpContext.Current.Response.Write(""); System.Web.HttpContext.Current.Response.End(); return false; } } return true; } /// /// 检查应用程序权限 /// /// /// public static bool CheckApp(out string msg, string appid = "") { msg = ""; appid = appid.IsNullOrEmpty() ? System.Web.HttpContext.Current.Request.QueryString["appid"] : appid; Guid appGuid; if (!appid.IsGuid(out appGuid)) { return false; } var app = new RoadFlow.Platform.RoleApp().GetFromCache(appid); if (app != null) { var roles = RoadFlow.Platform.Users.CurrentUserRoles; if (roles.Contains(app["RoleID"].ToString().ToGuid())) { return true; } else { msg = ""; } } else { var userID = RoadFlow.Platform.Users.CurrentUserID; if (userID.IsEmptyGuid()) { msg = ""; return false; } var userApp = new RoadFlow.Platform.UsersApp().GetUserDataRows(userID); foreach (System.Data.DataRow dr in userApp) { if (dr["ID"].ToString().ToGuid() == appGuid) { return true; } } } return false; } /// /// 检查访问地址 /// /// /// public static bool CheckReferrer(bool isEnd = true) { bool IsUri = HttpContext.Current.Request.UrlReferrer != null && HttpContext.Current.Request.Url.Host.Equals(HttpContext.Current.Request.UrlReferrer.Host, StringComparison.CurrentCultureIgnoreCase); if (!IsUri && isEnd) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write("访问地址错误!"); HttpContext.Current.Response.End(); } return IsUri; } } }