protected override void OnAuthorization(AuthorizationContext filterContext) { ViewBag.MyCivetNo = CUtil.CStr(UserInfo.BaseInfo.civetno).ToLower(); //当前用户的香信号 string controller = this.RouteData.Values["controller"].ToString().ToLower(); string action = this.RouteData.Values["action"].ToString().ToLower(); if (controller != "Home".ToLower()) //需要验证的页面 { if (ViewBag.MyCivetNo == "") { OAuth oauth = new OAuth(CivetHelper.AppID); string id = CUtil.CStr(this.RouteData.Values["ID"]); string QueryString = HtmlUtil.DealQuery(Request.QueryString.ToString(), "code"); string redirect_url = "http://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/Login-" + controller + "/" + action + (id != "" ? "/" + id : "") + (QueryString != "" ? "?" + QueryString : ""); string msg = ""; if (ViewBag.MyCivetNo != "") { msg = "无权操作"; } filterContext.Result = Content(Util.JsUrlTo(oauth.GenerateOAuthUrl(redirect_url), msg)); return; } } base.OnAuthorization(filterContext); }
/// <summary> /// Logins the specified signature. /// </summary> /// <param name="Signature">The signature.</param> /// <param name="ToController">To controller.</param> /// <param name="ToAction">To action.</param> /// <param name="id">The identifier.</param> /// <returns>ActionResult.</returns> public ActionResult Login(string Signature, string ToController, string ToAction, string id) { try { OAuth oauth = new OAuth(CivetHelper.AppID); OAuth.UserInfo uInfo = oauth.FastGetUserInfo(Request); //判斷用戶權限並給UserInfo賦值(存入Session) if (uInfo == null) { return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无账号信息") }))); } #region 添加管理员信息 if (uInfo != null) { if (!string.IsNullOrEmpty(uInfo.civetno)) { MongoCollection <ModUApiManager> uapimanager = mongoh.GetDb().GetCollection <ModUApiManager>("uapi_managers"); ModUApiManager modeuap = uapimanager.Find(Query.And( Query.EQ("_id", new BsonString(uInfo.civetno.ToUpper())), Query.EQ("is_disabled", new BsonBoolean(false)) )).FirstOrDefault(); if (modeuap != null) { if (modeuap.last_login_time < DateTime.Now.AddMinutes(-2)) { uapimanager.Update((Query.EQ("_id", new BsonString(uInfo.civetno.ToUpper()))), Update.Set("last_login_time", DateTime.Now)); } UtilComm.UApi_Manager = modeuap; //if (!modeuap.is_disabled) //{ // return Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无权限") })); //} } else { return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "无账号信息") }))); } Managelog(uInfo.civetno.ToUpper()); } } #endregion base.UserInfo = new ModUserInfo { BaseInfo = uInfo }; string url = string.IsNullOrEmpty(id) ? Url.Action(ToAction, ToController) : Url.Action(ToAction, ToController, new { id = id }); string QueryString = HtmlUtil.DealQuery(Request.QueryString.ToString(), "code", "id"); if (QueryString != "") { url += "?" + QueryString; } //完善登錄操作 return(Redirect(url)); } catch (Exception) { return(Redirect(Url.Action("AlertInfo", "Home", new { ErrMsg = LUtil.Lang(HttpContext, "数据读取异常") }))); } }