Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int categoryID  = Convert.ToInt32(Page.RouteData.Values["id"]);
            var currentUser = _authenticationService.GetAuthenticatedUser();

            loadCategory(categoryID);
            loadTopics(categoryID);
            loadFollowers(categoryID, currentUser);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = _authenticationService.GetAuthenticatedUser();

            if (user == null)
            {
                Response.Redirect($"~/login?ReturnUrl={Server.UrlEncode(Request.RawUrl)}");
            }
            currentUser.ImageUrl = user.PhotoUrl;
            loadCategories();
        }
Exemplo n.º 3
0
        private void getUser(string userName)
        {
            var user        = _userService.GetUserByUsername(userName);
            var currentUser = _authenticationService.GetAuthenticatedUser();

            if (currentUser == null)
            {
                Response.Redirect($"/login?ReturnUrl={Request.RawUrl}");
            }

            if (currentUser.Id != user.ID)
            {
                btnEdit.Style["display"] = "none";
            }

            var userDetails = _userService.GetUserDetails(user.ID);

            profilePicture.ImageUrl = userDetails.Avatar;
            username.Text           = userDetails.Username;
            fullname.Text           = userDetails.Fullname;
            gender.Text             = userDetails.Gender.ToString();
            age.Text      = TimePeriod.GetAge(userDetails.Birthdate).ToString();
            bio.Text      = userDetails.Bio;
            topics.Text   = userDetails.NumTopics.ToString();
            comments.Text = userDetails.NumComments.ToString();
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var currentUser = _authenticationService.GetAuthenticatedUser();

            if (currentUser == null)
            {
                redirectToLogin(Request.RawUrl);
            }

            int topicID = Convert.ToInt32(Page.RouteData.Values["id"]);

            loadTopic(topicID, currentUser.Id);
        }
Exemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var authenticatedUser = _authenticationService.GetAuthenticatedUser();

                if (authenticatedUser != null)
                {
                    linkProfile.HRef    = $"~/users/{authenticatedUser.Username}";
                    profilePic.ImageUrl = authenticatedUser.PhotoUrl;
                    panelAnonymous.Attributes.Add("style", "display:none");
                    ViewState["userRole"] = authenticatedUser.Role;
                }
                else
                {
                    panelAuthorized.Attributes.Add("style", "display:none");
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="httpContext">http上下文</param>
        /// <returns>验证是否通过</returns>
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            var user = FormsAuthenticationService.GetAuthenticatedUser();

            if (user == null)
            {
                return(false);
            }

            return(true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();

            if (currentUser == null)
            {
                Response.Redirect($"~/login?ReturnUrl={Server.UrlEncode(Request.RawUrl)}");
            }
            if (!IsPostBack)
            {
                fillData(currentUser.Id);
            }
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var authenticatedUser = _authenticationService.GetAuthenticatedUser();
                if (authenticatedUser == null)
                {
                    redirectToLogin(Request.RawUrl);
                }

                if (authenticatedUser.Role != "Admin")
                {
                    Response.Redirect("/accessdenied");
                }
            }
        }
        /// <summary>
        /// 执行操作(调用方法特性后由框架调用)
        /// </summary>
        /// <param name="filterContext">过滤上下文</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //方法名称
            var actionName = filterContext.ActionDescriptor.ActionName;
            //控制器
            var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            Dictionary <String, String> parmsObj = new Dictionary <String, String>();

            foreach (var item in parameterNameList.Split(',', '|'))
            {
                var valueProviderResult = filterContext.Controller.ValueProvider.GetValue(item);

                if (valueProviderResult != null && !parmsObj.ContainsKey(item))
                {
                    parmsObj.Add(item, valueProviderResult.AttemptedValue);
                }
            }

            var ticketUser = FormsAuthenticationService.GetAuthenticatedUser();

            try
            {
                String responseDataStr = JsonConvert.SerializeObject(filterContext.Result);
                if (responseDataStr == null)
                {
                    responseDataStr = String.Empty;
                }

                DataAccessBLL.Insert(new UserOperationLog
                {
                    UserID          = ticketUser?.UserID ?? 0,
                    UserAccount     = ticketUser == null ? "未知用户" : ticketUser.UserAccount,
                    OperationMothod = $"{controllerName}.{actionName}",
                    OperationName   = operationExplain,
                    OperationData   = JsonConvert.SerializeObject(parmsObj),
                    ReturnData      = responseDataStr,
                    Crdate          = DateTime.Now
                });
            }
            catch (Exception ex)
            {
                // 记录错误日志
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 在过程请求授权时调用
        /// </summary>
        /// <param name="filterContext">过滤上下文</param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            var user = FormsAuthenticationService.GetAuthenticatedUser();

            if (user == null)
            {
                return;
            }

            String action     = filterContext.ActionDescriptor.ActionName;
            String controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            // 需要获取管理员账号,思路为1.管理员账号和名字相同不允许修改2.初始化获取管理员账号然后来做对比
            if (user.UserAccount.ToLower() != "admin")
            {
                //所有菜单
                var menusDic = MenuProvider.GetMenuDic();
                //当前访问的菜单
                var menusList = new List <MenuItem>();

                //登录用户都可以访问该页面
                if (controller == "Login" && action == "Index")
                {
                    return;
                }

                // 根据控制器筛选
                foreach (var item in menusDic)
                {
                    if (item.Value.Controller == controller)
                    {
                        menusList.Add(item.Value);
                    }
                }

                // 为零就是没找到与控制器相匹配的菜单
                if (menusList.Count == 0)
                {
                    filterContext.Result = new ContentResult()
                    {
                        Content = "此账号没有该权限"
                    };

                    // 需要写入日志
                }
                else
                {
                    // 获取用户的菜单
                    var menuPerList = user.MenuId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    // 判断用户的菜单是否包含访问的菜单 ,如果不包含则提示无权限
                    if (menusList.Where(p => !menuPerList.Contains(p.ID)).ToList().Count > 0)
                    {
                        filterContext.Result = new ContentResult()
                        {
                            Content = "此账号没有该权限."
                        };
                        // 需要写入日志

                        return;
                    }
                }
            }
        }
Exemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            int topicID     = Convert.ToInt32(Page.RouteData.Values["id"]);
            var currentUser = _authenticationService.GetAuthenticatedUser();

            loadTopic(topicID, currentUser);
            loadComments(topicID, currentUser);
        }