Exemplo n.º 1
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if ((RouteData.Values["Catalog"]?.ToString() ?? string.Empty) == "Catalog")
            {
                var user = (SiteMaster.CurrentUser());
                if (user == null)
                {
                    return;
                }
                _messages            = LogicCollection.PostLogic.GetMediaPostsByUser(user);
                SearchBox.Visible    = false;
                SearchButton.Visible = false;
                CreatePost.Visible   = false;
                Title = "Catalogus";

                warning.Visible = !_messages.Any();
            }
            else
            {
                var searchQuery = Request.QueryString["q"];

                if (searchQuery == null)
                {
                    _messages = LogicCollection.PostLogic.GetAllMainPosts();
                }
                else
                {
                    _messages      = LogicCollection.PostLogic.SearchPostsByHashtag(searchQuery);
                    SearchBox.Text = searchQuery;
                }
            }
        }
Exemplo n.º 2
0
 protected void Page_Init(object sender, EventArgs e)
 {
     if (Context.User.Identity.IsAuthenticated && !SiteMaster.CurrentUser().Admin)
     {
         Response.Redirect("~", true);
     }
 }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!SiteMaster.CurrentUser().Admin)
     {
         // If not admin NOT AUTHORIZED
         Response.Redirect("Login.aspx");
     }
 }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = SiteMaster.CurrentUser();

            if (user != null)
            {
                lblNotLoggedIn.Visible = true;
                lblNotLoggedIn.Text    = "Je bent al ingelogd.";
                loginForm.Visible      = false;
            }
        }
Exemplo n.º 5
0
        public static string ReportPost(int postId)
        {
            var context = HttpContext.Current;

            if (context == null || !context.User.Identity.IsAuthenticated)
            {
                return("Not authorized");
            }
            var user   = SiteMaster.CurrentUser();
            var result = LogicCollection.PostLogic.ReportPost(user, postId);

            return(HttpContext.Current != null && result
                ? "succeeded"
                : "Not authorized");
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CurEvent = LogicCollection.EventLogic.GetByID(2);

            StartDate.TodaysDate = CurEvent.StartDate;
            EndDate.TodaysDate   = CurEvent.StartDate;

            var user = SiteMaster.CurrentUser();

            if (user != null)
            {
                lblLoggedIn.Visible  = true;
                lblLoggedIn.Text     = "Je bent al ingelogd.";
                fromRegister.Visible = false;
            }
        }
Exemplo n.º 7
0
        public void LoadUsers()
        {
            if (SiteMaster.CurrentUser() == null)
            {
                Response.Redirect("Login.aspx");
            }

            drpUsers.Items.Clear();
            foreach (var user in LogicCollection.UserLogic.AllUsers)
            {
                if (user.ID == SiteMaster.CurrentUser().ID)
                {
                    continue;
                }
                var item =
                    new ListItem($@"ID: {user.ID} - {user.Username} - {(user.Admin ? "Admininistrator" : "User")}",
                                 user.ID.ToString());
                drpUsers.Items.Add(item);
            }
        }
Exemplo n.º 8
0
        public static string DeletePost(int postId)
        {
            var context = HttpContext.Current;

            if (context == null || !context.User.Identity.IsAuthenticated)
            {
                return("false");
            }

            var user = SiteMaster.CurrentUser();
            var post = LogicCollection.PostLogic.GetPostById(postId);

            if (user != null && post != null && (post.UserID == user.ID || user.Admin))
            {
                return(LogicCollection.PostLogic.DeletePost(post)
                    ? "true"
                    : "false");
            }

            return("false");
        }
Exemplo n.º 9
0
        protected void btnPost_Click(object sender, EventArgs e)
        {
            var user = SiteMaster.CurrentUser();

            if (user == null)
            {
                return;
            }

            var newMessage = LogicCollection.PostLogic.AddPost(
                new Message(0, user.ID, DateTime.Now, txtTitle.Text, txtMessage.Text)
                );

            try
            {
                if (FileUpload.HasFile)
                {
                    var file         = FileUpload.PostedFile;
                    var trailingPath = Path.GetFileName(file.FileName);
                    var fullPath     = Path.Combine(HostingEnvironment.MapPath("/Files/"), trailingPath);

                    FileUpload.SaveAs(fullPath);

                    LogicCollection.PostLogic.AddFileContribution(
                        new FileContribution(
                            0, user.ID, DateTime.Now, 1,
                            "/Files/" + file.FileName,
                            FileUpload.PostedFile.ContentLength
                            ),
                        newMessage.ID
                        );
                }
            }
            catch (Exception ex)
            {
                Logger.Write(ex.Message);
            }

            Page.Response.Redirect(Request.Url.AbsoluteUri);
        }
Exemplo n.º 10
0
        public static string AddReply(int postId, string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return("false");
            }

            var context = HttpContext.Current;

            if (context == null || !context.User.Identity.IsAuthenticated)
            {
                return("Not authorized");
            }
            var user   = SiteMaster.CurrentUser();
            var result = LogicCollection.PostLogic.AddReply(user, postId, message);

            if (result == 0)
            {
                return("false");
            }
            return(DisplayReply(user, new Message(result, user.ID, DateTime.Now, "", message)));
        }
Exemplo n.º 11
0
        private void OnPreRender(object sender, EventArgs eventArgs)
        {
            Username.InnerText = LogicCollection.UserLogic.GetById(Post.UserID).Username;

            delete.Attributes.Add("value", Post.ID.ToString());
            like.Attributes.Add("value", Post.ID.ToString());
            report.Attributes.Add("value", Post.ID.ToString());

            // Only the owners of the main posts an admins are allowed to remove posts
            var user = SiteMaster.CurrentUser();

            delete.Visible = (Post.UserID == user.ID || user.Admin);

            var likes = LogicCollection.PostLogic.GetLikesByPost(Post);

            if (IsPostBack)
            {
                like.Visible   = false;
                report.Visible = false;
            }

            // Adds the amount of likes to the posts, if any
            if (likes.Any())
            {
                like.InnerHtml += "<span> " + likes.Count + "</span>";
            }
            else
            {
                like.InnerHtml += "<span></span>";
            }

            if (likes.Any(x => x == user.ID))
            {
                like.Attributes.Add("class", like.Attributes["class"] + " liked");
            }

            // Changes the button depending on whether or not the current user has reported it
            var reports = LogicCollection.PostLogic.GetReportsByPost(Post);

            if (reports.Any(x => x == user.ID))
            {
                report.Attributes.Add("class", like.Attributes["class"] + " reported");
                report.InnerHtml += "<span>Gerapporteerd</span>";
            }
            else
            {
                report.InnerHtml += "<span>Rapporteren</span>";
            }

            // Regular expression that extracts every hashtag
            var regex = new Regex(@"#(?<content>[^/\s]+)", RegexOptions.IgnoreCase);
            var list  = regex.Matches(Post.Content).Cast <Match>().Select(m => m.Value).ToList();

            // Wrapping every hashtag with a hyperlink tag to search for it
            foreach (var match in list)
            {
                Post.Content = Post.Content.Replace(match, $@"<a href='/Timeline?q={match.Replace("#", "")}'>{match}</a>");
            }

            if (Post.File == null)
            {
                return;
            }

            File = Post.File;
            postThumbnail.ImageUrl = File.Filepath;
        }
Exemplo n.º 12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     _currentUser = SiteMaster.CurrentUser();
 }