Ejemplo n.º 1
0
        public void Init(IHome View, bool IsPostBack)
        {
            _view = View;
            List <VisibilityLevel> _listVisibilityLevel = new List <VisibilityLevel>();

            _listVisibilityLevel = _privacyService.GetListVisibilityLevel();
            if (_userSession.LoggedIn == true)
            {
                IProfileRepository _profileRepository = new ProfileRepository();
                Profile            profile            = _profileRepository.GetProfileByAccountID(_userSession.CurrentUser.AccountID);
                if (profile == null)
                {
                    _redirector.Redirect("~/Profiles/ManageProfile.aspx");
                }
                else
                {
                    _view.LoadStatusControl(_listVisibilityLevel, true);
                    account = _userSession.CurrentUser;
                    if (!IsPostBack)
                    {
                        _view.LoadStatus(GetStatusToShow(account));
                    }
                }
            }
            else
            {
                account = null;
                _redirector.GoToAccountLoginPage();
            }
            _view.DisplayCurrentAccount(account);
        }
Ejemplo n.º 2
0
        public void Login(string username, string password, bool rememberMe)
        {
            string message;

            if (_accountService.Login(username, password, rememberMe, out message))
            {
                _redirector.Redirect("~/Homes/home.aspx?UserName="******"~/Homes/home.aspx?UserName=" + username);
                }
            }
            _view.DisplayMessage(message);
        }
Ejemplo n.º 3
0
        public static void RedirectPage(IMetaData metaData, ISource source, IWebHandler handler,
                                        OutputData outputData, IRedirector redirector)
        {
            MetaDataUtil.SetMetaData(redirector, handler.Style, metaData);
            string url = redirector.Redirect(source, handler, outputData);

            TkDebug.AssertNotNullOrEmpty(url,
                                         "Redirector.Redirect函数返回的Url为空,不能重定向该地址", redirector);
            url = AppUtil.ResolveUrl(url);

            handler.Response.Redirect(url, false);
        }
Ejemplo n.º 4
0
        void Application_PostResolveRequestCache(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;

            string[] extensionsToExclude = { ".axd", ".jpg", ".gif", ".png", ".xml", ".config", ".css", ".js", ".htm", ".html" };
            foreach (string s in extensionsToExclude)
            {
                if (application.Request.PhysicalPath.ToLower().Contains(s))
                {
                    return;
                }
            }

            if (!System.IO.File.Exists(application.Request.PhysicalPath))
            {
                if (application.Request.PhysicalPath.ToLower().Contains("blogs"))
                {
                    string[] arr          = application.Request.PhysicalPath.ToLower().Split('\\');
                    string   blogPageName = arr[arr.Length - 1];
                    string   blogUserName = arr[arr.Length - 2];
                    blogPageName = blogPageName.Replace(".aspx", "");

                    if (blogPageName.ToLower() != "profileimage" && blogUserName.ToLower() != "profileavatar")
                    {
                        if (blogPageName == "default")
                        {
                            return;
                        }

                        Account accountBlog = _accountRepository.GetAccountByUsername(blogUserName);

                        if (accountBlog == null)
                        {
                            return;
                        }

                        Blog blog = _blogRepository.GetBlogByPageName(blogPageName, accountBlog.AccountID);

                        context.RewritePath("~/blogs/ViewPost.aspx?BlogID=" + blog.BlogID.ToString());
                    }
                    else
                    {
                        return;
                    }
                }

                else if (application.Request.PhysicalPath.ToLower().Contains("groups") && _webContext.GroupID == 0)
                {
                    string[] arr           = application.Request.PhysicalPath.ToLower().Split('\\');
                    string   groupPageName = arr[arr.Length - 1];
                    groupPageName = groupPageName.Replace(".aspx", "");
                    Group group = _groupRepository.GetGroupByPageName(groupPageName);
                    context.RewritePath("/groups/viewgroup.aspx?GroupID=" + group.GroupID.ToString());
                }
                else if (application.Request.PhysicalPath.ToLower().Contains("mygroups") && application.Request.PhysicalPath.ToLower().Contains("groups"))
                {
                    context.RewritePath("/groups/mygroups.aspx");
                }

                else if (application.Request.PhysicalPath.ToLower().Contains("forums"))
                {
                    string[] arr              = application.Request.PhysicalPath.ToLower().Split('\\');
                    int      forumsPosition   = 0;
                    int      itemsAfterForums = 0;
                    string   categoryPageName = "";
                    string   forumPageName    = "";
                    string   postPageName     = "";

                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i].ToLower() == "forums")
                        {
                            forumsPosition = i;
                            break;
                        }
                    }

                    itemsAfterForums = (arr.Length - 1) - forumsPosition;

                    if (itemsAfterForums == 2)
                    {
                        categoryPageName = arr[arr.Length - 2];
                        forumPageName    = arr[arr.Length - 1];
                        forumPageName    = forumPageName.Replace(".aspx", "");
                        BoardForum forum = _forumRepository.GetForumByPageName(forumPageName);
                        context.RewritePath("/forums/ViewForum.aspx?ForumID=" + forum.ForumID.ToString() +
                                            "&CategoryPageName=" + categoryPageName + "&ForumPageName=" + forumPageName, true);
                    }
                    else if (itemsAfterForums == 3)
                    {
                        categoryPageName = arr[arr.Length - 3];
                        forumPageName    = arr[arr.Length - 2];
                        postPageName     = arr[arr.Length - 1];
                        postPageName     = postPageName.Replace(".aspx", "");
                        BoardPost post = _postRepository.GetPostByPageName(postPageName);
                        context.RewritePath("/forums/ViewPost.aspx?PostID=" + post.PostID.ToString(), true);
                    }
                }
                else
                {
                    HttpResponse Response = context.Response;
                    HttpRequest  Request  = context.Request;
                    String       Username = Request.Path.Replace("/", "");
                    //
                    Account account = _accountRepository.GetAccountByUsername(Username);
                    _redirector = new Redirector();
                    if (account != null)
                    {
                        _redirector.Redirect("~/Profiles/UserProfile2.aspx?AccountID=" + account.AccountID.ToString());
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        void Application_PostResolveRequestCache(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            string[] extensionsToExclude = { ".axd", ".jpg", ".gif", ".png", ".xml", ".config", ".css", ".js", ".htm", ".html" };
            foreach (string s in extensionsToExclude)
            {
                if (application.Request.PhysicalPath.ToLower().Contains(s))
                    return;
            }

            if (!System.IO.File.Exists(application.Request.PhysicalPath))
            {
                String executionPath = application.Request.CurrentExecutionFilePath.ToLower().Trim('/', ' ');
                string[] arr = executionPath.Split('/');
                switch (arr[0])
                {
                    case "blogs":
                        XuLyBlogs(context, arr);
                        break;
                    case "groups":
                        XuLyGroup(context, arr);
                        break;
                    case "mygroups":
                        XuLyMyGroups(context, arr);
                        break;
                    case "forums":
                        XuLyForums(context, arr);
                        break;
                    default:
                        HttpResponse Response = context.Response;
                        HttpRequest Request = context.Request;
                        String Username = Request.Path.Replace("/", "");
                        //
                        Account account = _accountRepository.GetAccountByUsername(Username);
                        _redirector = new Redirector();
                        if (account != null)
                            _redirector.Redirect("~/Profiles/UserProfile2.aspx?AccountID=" + account.AccountID.ToString());
                        else
                            return;
                        break;
                }
            }
        }
Ejemplo n.º 6
0
 protected void thaydoi_Click(object sender, EventArgs e)
 {
     _redirector.Redirect("~/Accounts/EditAccount.aspx");
 }
Ejemplo n.º 7
0
 public void EditButton_Click(object sender, EventArgs e)
 {
     _redirector = new Redirector();
     _redirector.Redirect("~/Admins/Manage.aspx");
 }
Ejemplo n.º 8
0
 protected void lbtnChangeAvatar_Click(object sender, EventArgs e)
 {
     _redirector.Redirect("~/Profiles/UploadAvatar.aspx");
 }
Ejemplo n.º 9
0
 public void GotoUpdateAvatar()
 {
     _redirector.Redirect("~/Profiles/UpLoadAvatar.aspx");
 }
Ejemplo n.º 10
0
 protected void lbViewMembers_Click(object sender, EventArgs e)
 {
     _redirector.Redirect("~/Groups/ViewManageMember.aspx?GroupID=" + _webContext.GroupID);
 }
Ejemplo n.º 11
0
        public void Save(BoardPost post)
        {
            //is new thread
            if (_webContext.LoggedIn)
            {
                post.ReplyByAccountID = _webContext.AccountID;
                post.ReplyByUsername  = _webContext.CurrentUser.UserName;
                if (_webContext.PostID > 0)
                {
                    BoardPost postToReplyToo = _postRepository.GetPostByID(_webContext.PostID);
                    if (postToReplyToo.IsThread)
                    {
                        post.ThreadID = postToReplyToo.PostID;
                    }
                    else
                    {
                        //if post.ThreadID = postToReplyToo.ThreadID thì ở thread show tất cả bình luận.
                        post.ThreadID = postToReplyToo.PostID;
                    }
                    post.ForumID = postToReplyToo.ForumID;
                }
                else
                if (_webContext.ForumID > 0)
                {
                    post.ForumID  = _webContext.ForumID;
                    post.IsThread = _webContext.IsThread;
                    if (!_postRepository.CheckPostPageNameIsUnique(post.PageName))
                    {
                        _view.SetErrorMessage("The page name you are trying to use is already in use!");
                        return;
                    }
                }
                post.CreateDate = DateTime.Now;
                post.UpdateDate = DateTime.Now;
                post.AccountID  = _webContext.CurrentUser.AccountID;
                post.Username   = _webContext.CurrentUser.UserName;
                post.ReplyCount = 0;
                post.ViewCount  = 0;
                if (post.PageName != null)
                {
                    post.PageName = post.PageName.Replace(" ", "-");
                }
                else
                {
                    post.PageName = post.Name;
                    post.PageName = post.PageName.Replace(" ", "-");
                }

                post.PostID = _postRepository.SavePost(post);

                BoardForum forum = _forumRepository.GetForumByID(post.ForumID);
                forum.LastPostByAccountID = post.AccountID;
                forum.LastPostByUsername  = post.Username;
                _forumRepository.SaveForum(forum);
                BoardCategory category = _categoryRepository.GetCategoryByCategoryID(forum.CategoryID);
                category.LastPostByAccountID = post.AccountID;
                category.LastPostByUsername  = post.Username;
                _categoryRepository.SaveCategory(category);
                BoardPost thread;
                if (post.IsThread)
                {
                    thread = _postRepository.GetPostByID(post.PostID);
                }
                else
                {
                    thread = _postRepository.GetPostByID((long)post.ThreadID);
                }

                //is this forum part of a group?
                Group group = _groupRepository.GetGroupByForumID(forum.ForumID);

                //add an alert to the filter
                if (post.IsThread)
                {
                    //is this a group forum?
                    if (group != null)
                    {
                        _alertService.AddNewBoardThreadAlert(category, forum, thread, group);
                    }
                    else
                    {
                        _alertService.AddNewBoardThreadAlert(category, forum, thread);
                    }
                }
                else
                {
                    //is this a group forum?
                    if (group != null)
                    {
                        _alertService.AddNewBoardPostAlert(category, forum, post, thread, group);
                    }
                    else
                    {
                        _alertService.AddNewBoardPostAlert(category, forum, post, thread);
                    }
                }
                //_redirector.GoToForumsViewPost(forum.PageName, category.PageName, thread.PageName);
                if (_webContext.IsThread == false)
                {
                    _redirector.Redirect("~/Groups/ViewGroupForumPost.aspx?PostID=" + _webContext.PostID + "&GroupID=" + _webContext.GroupID);
                }
                else
                {
                    _redirector.Redirect("~/Groups/ViewGroup.aspx?GroupID=" + _webContext.GroupID);
                }
            }
            else
            {
                _redirector.GoToAccountLoginPage();
            }
        }
Ejemplo n.º 12
0
        private void AcceptConnect(object obj)
        {
            string ID = "[" + new Random().Next(1000, 1999).ToString() + "] ";

            try
            {
                HttpListenerContext context = (HttpListenerContext)obj;

                string requestString = context.Request.RawUrl;
                Debug2.WriteLine(ID + "Got request for " + requestString);

                var result = redirector.Redirect(context);

                if (result.RequestHandled)
                {
                    return;
                }

                //get response
                HttpWebRequest request = null;
                if (result.HandledRequest == null)
                {
                    request = (HttpWebRequest)WebRequest.Create(context.Request.RawUrl);
                    foreach (string key in context.Request.Headers.Keys)
                    {
                        try
                        {
                            if (new List <string>
                            {
                                "host",
                                "content-length",
                                "expires",
                                "cache-control",
                                "last-modified",
                                "if-modified-since",
                                "etag",
                                "if-none-match"
                            }.Contains(key.ToLower()))
                            {
                                continue;                                 //Disable cache
                            }
                            request.Headers.Add(key, context.Request.Headers[key]);
                        }
                        catch { }
                    }
                }
                else
                {
                    request = result.HandledRequest;
                }

                request.Proxy     = AcPlayConfiguration.Config.WebProxy;
                request.KeepAlive = false;

                Debug2.WriteLine(ID + "Got back response from " + request.RequestUri);


                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    foreach (string key in response.Headers)
                    {
                        try
                        {
                            context.Response.AppendHeader(key, response.Headers[key]);
                        }
                        catch { }
                    }
                    using (Stream receiveStream = response.GetResponseStream())
                    {
                        HttpListenerResponse responseOut = context.Response;

                        // Need to get the length of the response before it can be forwarded on
                        //responseOut.ContentLength64 = response.ContentLength;
                        int bytesCopied = CopyStream(receiveStream, responseOut.OutputStream);
                        responseOut.OutputStream.Close();
                        Debug2.WriteLine(ID + "Copied " + bytesCopied.ToString() + " bytes");
                    }
                }
            }
            catch (WebException e)
            {
                Debug2.WriteLine(ID + "\nWeb Exception raised!");
                Debug2.WriteLine(ID + "Message: " + e.Message);
                Debug2.WriteLine(ID + "Status: " + e.Status.ToString() + "\r\n");
            }
            catch (Exception e)
            {
                Debug2.WriteLine(ID + "\nMain Exception raised!");
                Debug2.WriteLine(ID + "Source : " + e.Source);
                Debug2.WriteLine(ID + "Message : " + e.Message + "\r\n");
            }
        }
Ejemplo n.º 13
0
        void Application_PostResolveRequestCache(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            string[] extensionsToExclude = { ".axd", ".jpg", ".gif", ".png", ".xml", ".config", ".css", ".js", ".htm", ".html" };
            foreach (string s in extensionsToExclude)
            {
                if (application.Request.PhysicalPath.ToLower().Contains(s))
                    return;
            }

            if (!System.IO.File.Exists(application.Request.PhysicalPath))
            {
                if (application.Request.PhysicalPath.ToLower().Contains("blogs"))
                {
                    string[] arr = application.Request.PhysicalPath.ToLower().Split('\\');
                    string blogPageName = arr[arr.Length - 1];
                    string blogUserName = arr[arr.Length - 2];
                    blogPageName = blogPageName.Replace(".aspx", "");

                    if (blogPageName.ToLower() != "profileimage" && blogUserName.ToLower() != "profileavatar")
                    {
                        if (blogPageName == "default")
                            return;

                        Account accountBlog = _accountRepository.GetAccountByUsername(blogUserName);

                        if (accountBlog == null)
                            return;

                        Blog blog = _blogRepository.GetBlogByPageName(blogPageName, accountBlog.AccountID);

                        context.RewritePath("~/blogs/ViewPost.aspx?BlogID=" + blog.BlogID.ToString());
                    }
                    else
                    {
                        return;
                    }
                }

                else if (application.Request.PhysicalPath.ToLower().Contains("groups") && _webContext.GroupID == 0)
                {
                    string[] arr = application.Request.PhysicalPath.ToLower().Split('\\');
                    string groupPageName = arr[arr.Length - 1];
                    groupPageName = groupPageName.Replace(".aspx", "");
                    Group group = _groupRepository.GetGroupByPageName(groupPageName);
                    context.RewritePath("/groups/viewgroup.aspx?GroupID=" + group.GroupID.ToString());
                }
                else if (application.Request.PhysicalPath.ToLower().Contains("mygroups") && application.Request.PhysicalPath.ToLower().Contains("groups"))
                {

                    context.RewritePath("/groups/mygroups.aspx");
                }

                else if (application.Request.PhysicalPath.ToLower().Contains("forums"))
                {
                    string[] arr = application.Request.PhysicalPath.ToLower().Split('\\');
                    int forumsPosition = 0;
                    int itemsAfterForums = 0;
                    string categoryPageName = "";
                    string forumPageName = "";
                    string postPageName = "";

                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i].ToLower() == "forums")
                        {
                            forumsPosition = i;
                            break;
                        }
                    }

                    itemsAfterForums = (arr.Length - 1) - forumsPosition;

                    if (itemsAfterForums == 2)
                    {
                        categoryPageName = arr[arr.Length - 2];
                        forumPageName = arr[arr.Length - 1];
                        forumPageName = forumPageName.Replace(".aspx", "");
                        BoardForum forum = _forumRepository.GetForumByPageName(forumPageName);
                        context.RewritePath("/forums/ViewForum.aspx?ForumID=" + forum.ForumID.ToString() +
                                            "&CategoryPageName=" + categoryPageName + "&ForumPageName=" + forumPageName, true);
                    }
                    else if (itemsAfterForums == 3)
                    {
                        categoryPageName = arr[arr.Length - 3];
                        forumPageName = arr[arr.Length - 2];
                        postPageName = arr[arr.Length - 1];
                        postPageName = postPageName.Replace(".aspx", "");
                        BoardPost post = _postRepository.GetPostByPageName(postPageName);
                        context.RewritePath("/forums/ViewPost.aspx?PostID=" + post.PostID.ToString(), true);
                    }
                }
                else
                {
                    HttpResponse Response = context.Response;
                    HttpRequest Request = context.Request;
                    String Username = Request.Path.Replace("/", "");
                    //
                    Account account = _accountRepository.GetAccountByUsername(Username);
                    _redirector = new Redirector();
                    if (account != null)
                        _redirector.Redirect("~/Profiles/UserProfile2.aspx?AccountID=" + account.AccountID.ToString());
                    else
                        return;
                }

            }
        }
Ejemplo n.º 14
0
 protected void lbt_DangNhap_Click(object sender, EventArgs e)
 {
     _redirector.Redirect("~/Account/Login.aspx");
 }