public JsonResult MasterLogin(string username, string password, string wxToken = null) { bool wxLogin = !string.IsNullOrWhiteSpace(wxToken); bool hasInput = !string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password); if (!wxLogin && !hasInput) { return(ApiModel(message: "用户名和密码不能为空")); } Account account = null; C_UserInfo userInfo = null; if (wxLogin) { //微信授权登陆 wxToken = HttpUtility.UrlDecode(wxToken); int userId; int.TryParse(DESEncryptTools.DESDecrypt(wxToken), out userId); userInfo = C_UserInfoBLL.SingleModel.GetModel(userId); account = AccountBLL.SingleModel.GetAccountByUnionId(userInfo.UnionId); } string loginToken = string.Empty; string authToken = string.Empty; if (account != null) { //登陆已绑定微信的账号 authToken = DESEncryptTools.DESEncrypt(account.Id.ToString()); loginToken = Utils.BuildCookie(account.Id, account.UpdateTime); } else if (hasInput) { bool success = false; //用账号密码登录账号 account = AccountBLL.SingleModel.LoginUserWhole(username, password); if (account == null) { return(ApiModel(message: "用户名或密码错误")); } if (userInfo != null) { account.UnionId = userInfo.UnionId; success = AccountBLL.SingleModel.Update(account, "UnionId"); } if (userInfo != null && account != null && !success) { return(ApiModel(message: "账号绑定微信失败")); } authToken = DESEncryptTools.DESEncrypt(account.Id.ToString()); loginToken = Utils.BuildCookie(account.Id, account.UpdateTime); } else { return(ApiModel(isok: true, message: "微信账号未绑定账号,请输入账号密码", data: "NewUser")); } return(ApiModel(isok: true, message: "登陆成功", data: new { loginToken, authToken })); }
/// <summary> /// 最高管理权限 /// </summary> /// <param name="account"></param> /// <returns></returns> public static bool IsMasterAuth(Account account) { string masterAuth = CookieHelper.GetCookie("masterAuth"); string authToken = DESEncryptTools.DESDecrypt(masterAuth); return(authToken == account.Id.ToString()); }
public static Guid GetBuildCookieId(string cookieName) { string cookie = CookieHelper.GetCookie(cookieName); if (string.IsNullOrEmpty(cookie)) { return(Guid.Empty); } if (!string.IsNullOrEmpty(cookie)) { cookie = DESEncryptTools.DESDecrypt(cookie); } Guid cookieId = Guid.Empty; if (!string.IsNullOrEmpty(cookie)) { List <string> kv = cookie.SplitStr(@"\r\n"); if (kv.Count == 2 && !string.IsNullOrEmpty(kv[0]) && !string.IsNullOrEmpty(kv[1])) { Guid.TryParse(kv[0], out cookieId); } } return(cookieId); }
private DishStore GetStoreByAuth(AuthorizationContext filterContext) { int manageStoreId = 0; string loginToken = CookieHelper.GetCookie("dzDishAdmin"); if (!int.TryParse(DESEncryptTools.DESDecrypt(loginToken), out manageStoreId) || manageStoreId <= 0) { return(null); } return(DishStoreBLL.SingleModel.GetModel(manageStoreId)); }
/// <summary> /// 子帐号权限 /// </summary> /// <returns></returns> public static AuthRole GetAdminAuth() { string adminAuth = CookieHelper.GetCookie("adminAuth"); string adminAuthToken = DESEncryptTools.DESDecrypt(adminAuth); int roleId = 0; if (int.TryParse(adminAuthToken, out roleId) && roleId > 0) { return(AuthRoleBLL.SingleModel.GetModel(roleId)); } return(null); }
public override void OnAuthorization(AuthorizationContext filterContext) { //TODO 开发阶段屏蔽登陆验证 //return; if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)) { return; } int storeId = Context.GetRequestInt("storeId", 0); if (storeId > 0) { string cookieSoreId = CookieHelper.GetCookie("dzPinAdmin"); //如果没有找到登陆cookie if (string.IsNullOrEmpty(cookieSoreId)) { filterContext.Result = new RedirectResult("/PinAdmin/main/login"); return; } int storeid = 0; int.TryParse(DESEncryptTools.DESDecrypt(cookieSoreId), out storeid); //如果登陆cookie无法解密 if (storeid <= 0) { filterContext.Result = new RedirectResult("/PinAdmin/main/login"); return; } //只能进对应的管理后台 if (storeid != storeId) { filterContext.Result = new RedirectResult("/PinAdmin/main/login"); return; } PinStore pinStore = PinStoreBLL.SingleModel.GetModel(storeid); //如果门店不存在 if (pinStore == null) { filterContext.Result = new RedirectResult("/PinAdmin/main/login"); return; } filterContext.RouteData.Values["pinStore"] = pinStore; } else { filterContext.Result = new RedirectResult("/PinAdmin/main/login"); return; } }
public static bool IsPinAdmin() { int storeId = Context.GetRequestInt("storeId", 0); string cookieStoreId = CookieHelper.GetCookie("dzPinAdmin"); if (storeId == 0 || string.IsNullOrWhiteSpace(cookieStoreId)) { return(false); } int decrypStoreId = 0; int.TryParse(DESEncryptTools.DESDecrypt(cookieStoreId), out decrypStoreId); return(storeId > 0 && decrypStoreId == storeId); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { //if (WebSiteConfig.Environment != "dev") //{ // return; //} #region 登陆校验 int appId = Utility.IO.Context.GetRequestInt("appId", 0); if (appId == 0) { appId = Utility.IO.Context.GetRequestInt("aid", 0); } string encryAccountId = Core.MiniApp.Utils.GetBuildCookieId("dz_UserCookieNew").ToString(); Guid accountId = Guid.Empty; if (!Guid.TryParse(encryAccountId, out accountId)) { filterContext.Result = new RedirectResult($"/SubAccount/Login?appId={appId}"); return; } Account account = AccountBLL.SingleModel.GetModel(accountId); if (account == null) { filterContext.Result = new RedirectResult($"/SubAccount/Login?appId={appId}"); return; } XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, account.Id.ToString()); if (xcx == null) { filterContext.Result = new RedirectResult($"/SubAccount/Login?appId={appId}"); return; } #endregion int pageType = XcxAppAccountRelationBLL.SingleModel.GetXcxTemplateType(xcx.Id); string masterAuth = CookieHelper.GetCookie("masterAuth"); string authToken = DESEncryptTools.DESDecrypt(masterAuth); if (authToken == account.Id.ToString()) { //最高管理权限 filterContext.ActionParameters["authInfo"] = AuthRoleBLL.SingleModel.GetMasterAuth(pageType: pageType, authName: account.LoginId, accessUrl: filterContext.HttpContext.Request.Url.ToString()); return; } string adminAuth = CookieHelper.GetCookie("adminAuth"); string adminAuthToken = DESEncryptTools.DESDecrypt(adminAuth); int roleId = 0; if (int.TryParse(adminAuthToken, out roleId) && roleId > 0) { AuthInfo authInfo = AuthRoleBLL.SingleModel.GetAuthMenuByRole(pageType: pageType, roleId: roleId, accessUrl: filterContext.HttpContext.Request.Url.ToString()); authInfo.AuthName = account.LoginId; //子帐号权限 filterContext.ActionParameters["authInfo"] = authInfo; return; } filterContext.Result = new RedirectResult($"/SubAccount/Login?appId={appId}"); //base.OnActionExecuting(filterContext); }
public override void OnAuthorization(AuthorizationContext filterContext) { if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)) { return; } int appId = Utility.IO.Context.GetRequestInt("appId", 0); if (appId == 0) { appId = Utility.IO.Context.GetRequestInt("aid", 0); } Guid _accountid = Core.MiniApp.Utils.GetBuildCookieId("dz_UserCookieNew"); if (appId == 0 || _accountid == Guid.Empty) { filterContext.Result = new RedirectResult("/base/PageError?type=1"); return; } //用户是否存在 Account accountModel = AccountBLL.SingleModel.GetModel(_accountid); if (accountModel == null) { filterContext.Result = new RedirectResult("/base/PageError?type=2"); return; } #region 验证用户权限 //用户是否开通了这个模板 XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, accountModel.Id.ToString()); if (xcx == null) { filterContext.Result = new RedirectResult("/base/PageError?type=5"); return; } filterContext.RouteData.Values["xcx"] = xcx; var templatemodel = XcxTemplateBLL.SingleModel.GetModel(xcx.TId); if (templatemodel != null) { if (templatemodel.Type == (int)TmpType.智慧餐厅) { int storeId = Utility.IO.Context.GetRequestInt("storeId", 0); //如果这个用户是门店管理员 if (storeId > 0) { string cookieSoreId = CookieHelper.GetCookie("dzDishAdmin"); //如果没有找到登陆cookie if (string.IsNullOrEmpty(cookieSoreId)) { filterContext.Result = new RedirectResult("/DishAdmin/main/login"); return; } int storeid = 0; int.TryParse(DESEncryptTools.DESDecrypt(cookieSoreId), out storeid); //如果登陆cookie无法解密 if (storeid <= 0) { filterContext.Result = new RedirectResult("/DishAdmin/main/login"); return; } DishStore dishStore = DishStoreBLL.SingleModel.GetModel(storeid); //如果门店不存在 if (dishStore == null) { filterContext.Result = new RedirectResult("/DishAdmin/main/login"); return; } filterContext.RouteData.Values["dishStore"] = dishStore; } } } #endregion }