Example #1
0
        public void PostForm_RedirectUrlIsPreserved()
        {
            string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex);
            var    redirectQuery    = "?RedirectUrl=myRedirectUrl";

            this.pageOperations = new PagesOperations();

            try
            {
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(LoginFormController).FullName;
                var loginFormController = new LoginFormController();
                mvcProxy.Settings = new ControllerSettings(loginFormController);

                this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex);

                SecurityManager.Logout();
                var responseContent = PageInvoker.ExecuteWebRequest(loginFormPageUrl + redirectQuery);

                var expectedActionUrl = this.urlNamePrefix + this.pageIndex + redirectQuery;
                Assert.IsTrue(responseContent.Contains(string.Format("action=\"{0}\"", expectedActionUrl)), "The action URL no longer contains redirect URL");
            }
            finally
            {
                SecurityManager.Logout();
                SitefinityTestUtilities.ServerOperations.Users().AuthenticateAdminUser();
                this.pageOperations.DeletePages();
            }
        }
Example #2
0
        public MainForm(
            MainFormController mainFormController,
            LoginFormController loginFormController,
            CourseFormController courseFormController,
            UserFormController userFormController)
        {
            _mainFormController   = mainFormController;
            _loginFormController  = loginFormController;
            _courseFormController = courseFormController;
            _userFormController   = userFormController;

            InitializeComponent();
            populateCoursesListBox();
        }
Example #3
0
        public void PostForm_LoginRedirectPageId()
        {
            string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex);

            this.pageOperations = new PagesOperations();
            var userId = ClaimsManager.GetCurrentUserId();
            var user   = UserManager.GetManager().GetUser(userId);

            try
            {
                ////Create simple page with a content block to redirect on it
                var mvcProxyContentBlock = new MvcControllerProxy();
                mvcProxyContentBlock.ControllerName = typeof(ContentBlockController).FullName;
                var contentBlockController = new ContentBlockController();
                contentBlockController.Content = this.searchValueFirst;
                mvcProxyContentBlock.Settings  = new ControllerSettings(contentBlockController);
                Guid contentBlockPageID = this.pageOperations.CreatePageWithControl(
                    mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockFirstPage);

                ////Create page with login form and set LoginRedirectPageId to the newly created page above
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(LoginFormController).FullName;
                var loginFormController = new LoginFormController();
                loginFormController.Model.LoginRedirectPageId = contentBlockPageID;
                mvcProxy.Settings = new ControllerSettings(loginFormController);
                this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex);

                SecurityManager.Logout();

                ////create new user to Authenticate against newly created login form
                SitefinityTestUtilities.ServerOperations.Users().CreateUser(this.userName, this.password, "*****@*****.**", "test", "test", true, "AuthenticateUser", "IdentityHasClaimTypes", SecurityConstants.AppRoles.FrontendUsers);

                string postString      = "UserName="******"&Password="******"The request was not redirected to the proper page set in LoginRedirectPageId!");
            }
            finally
            {
                using (new AuthenticateUserRegion(user))
                {
                    this.pageOperations.DeletePages();
                }

                SecurityManager.Logout();
                SitefinityTestUtilities.ServerOperations.Users().DeleteUsers(new[] { this.userName });
            }
        }
Example #4
0
        public void PostForm_LogOnLogOff()
        {
            string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex);

            this.pageOperations = new PagesOperations();
            var userId = ClaimsManager.GetCurrentUserId();
            var user   = UserManager.GetManager().GetUser(userId);

            try
            {
                ////Create page with login form and set LoginRedirectPageId to the newly created page above
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(LoginFormController).FullName;
                var loginFormController = new LoginFormController();
                mvcProxy.Settings = new ControllerSettings(loginFormController);
                this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex);

                SecurityManager.Logout();

                ////create new user to Authenticate against newly created login form
                SitefinityTestUtilities.ServerOperations.Users().CreateUser(this.userName, this.password, "*****@*****.**", "test", "test", true, "AuthenticateUser", "IdentityHasClaimTypes", SecurityConstants.AppRoles.FrontendUsers);

                string postString = "UserName="******"&Password="******"You are already logged in"), "The user was not logged in properly on the login form!");

                    string logOutUrl = "http://localhost/Sitefinity/SignOut?sts_signout=true&redirect_uri=http://localhost/" + this.urlNamePrefix + this.pageIndex;
                    responseContent = PageInvoker.ExecuteWebRequest(logOutUrl, false);
                    Assert.IsFalse(responseContent.Contains("You are already logged in"), "User was not logget out!");
                }
            }
            finally
            {
                using (new AuthenticateUserRegion(user))
                {
                    this.pageOperations.DeletePages();
                }

                SecurityManager.Logout();
                SitefinityTestUtilities.ServerOperations.Users().DeleteUsers(new[] { this.userName });
            }
        }
Example #5
0
        public void PostForm_RedirectUrlIsPreserved()
        {
            string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex);
            var    redirectURL      = "http://localhost/";
            var    redirectQuery    = "?RedirectUrl=";
            var    fullQueryString  = redirectQuery + redirectURL;

            this.pageOperations = new PagesOperations();

            var userId = ClaimsManager.GetCurrentUserId();
            var user   = UserManager.GetManager().GetUser(userId);

            try
            {
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(LoginFormController).FullName;
                var loginFormController = new LoginFormController();
                mvcProxy.Settings = new ControllerSettings(loginFormController);

                this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex);

                SecurityManager.Logout();
                var responseContent = PageInvoker.ExecuteWebRequest(loginFormPageUrl + fullQueryString);

                int startPosition = responseContent.IndexOf(this.actionSearchString, StringComparison.OrdinalIgnoreCase) + this.actionSearchString.Length;
                Assert.IsTrue(startPosition > 0, "The page is not containing a form with action!");

                int    endPosition = responseContent.IndexOf(' ', startPosition);
                string actionValue = responseContent.Substring(startPosition, endPosition - startPosition);
                string searchValue = redirectQuery + HttpUtility.UrlEncode(redirectURL);

                Assert.IsTrue(actionValue.Contains(searchValue), "The action URL no longer contains ReturnUrl");
            }
            finally
            {
                using (new AuthenticateUserRegion(user))
                {
                    this.pageOperations.DeletePages();
                }
            }
        }
Example #6
0
        public LoginForm()
        {
            try
            {
                InitializeComponent();

                Controller = new LoginFormController(this);

                this.Load += (s, e) => Controller.InitializeForm();
                this.FormClosing += (s, e) => { if (validateLogin) e.Cancel = !Controller.ValidateLogIn(); };
                this.btnAccept.Click += (s, e) => validateLogin = true;
                this.btnCancel.Click += (s, e) => validateLogin = false;
                //this.txtUsername.TextChanged += (s, e) => Controller.CheckUser();

                //this.txtPassword.DataBindings.Add(new Binding("Enabled", Controller, "UserExists"));

            }
            catch (Exception ex)
            {
                ex.ShowMessageBox();
            }
        }
Example #7
0
        static void Main()
        {
            var nhService = new NHibernateService();

            var userRepository      = new UserRepository(nhService);
            var courseRepository    = new CourseRepository(nhService);
            var componentRepository = new ComponentRepository(nhService);
            var scoreRepository     = new ScoreRepository(nhService);

            var loginService   = new LoginService(userRepository);
            var userServices   = new UserServices(userRepository);
            var courseServices = new CourseServices(courseRepository, userRepository, componentRepository);

            var mainFormController   = new MainFormController(userServices, courseServices);
            var loginFormController  = new LoginFormController(mainFormController, loginService);
            var courseFormController = new CourseFormController(courseServices, userServices);
            var userFormController   = new UserFormController(userServices, courseServices);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var loginForm = new LoginForm(loginFormController);

            var mainForm = new MainForm(
                mainFormController,
                loginFormController,
                courseFormController,
                userFormController);

            Application.Run(loginForm);
            var loginResult = loginForm.LoginResult;

            if (loginResult)
            {
                Application.Run(mainForm);
            }
        }
Example #8
0
 public LoginForm()
 {
     _controller = new LoginFormController(this);
 }
Example #9
0
        public void PostForm_LoginRedirectFromQueryString()
        {
            string loginFormPageUrl = UrlPath.ResolveAbsoluteUrl("~/" + this.urlNamePrefix + this.pageIndex);

            this.pageOperations = new PagesOperations();
            var userId = ClaimsManager.GetCurrentUserId();
            var user   = UserManager.GetManager().GetUser(userId);

            try
            {
                var mvcProxyContentBlock = new MvcControllerProxy();
                mvcProxyContentBlock.ControllerName = typeof(ContentBlockController).FullName;

                ////Create first simple page with a content block to redirect on it
                var contentBlockController = new ContentBlockController();
                contentBlockController.Content = this.searchValueFirst;
                mvcProxyContentBlock.Settings  = new ControllerSettings(contentBlockController);
                this.pageOperations.CreatePageWithControl(
                    mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockFirstPage);

                ////Create second simple page with a content block to redirect on it
                var contentBlockControllerSecond = new ContentBlockController();
                contentBlockControllerSecond.Content = this.searchValueSecond;
                mvcProxyContentBlock.Settings        = new ControllerSettings(contentBlockControllerSecond);
                this.pageOperations.CreatePageWithControl(
                    mvcProxyContentBlock, this.pageNamePrefixContentBlockPage, this.pageTitlePrefixContentBlockPage, this.urlNamePrefixContentBlockPage, this.pageIndexContentBlockSecondPage);

                ////Create page with login form
                var mvcProxy = new MvcControllerProxy();
                mvcProxy.ControllerName = typeof(LoginFormController).FullName;
                var loginFormController = new LoginFormController();
                mvcProxy.Settings = new ControllerSettings(loginFormController);
                this.pageOperations.CreatePageWithControl(mvcProxy, this.pageNamePrefix, this.pageTitlePrefix, this.urlNamePrefix, this.pageIndex);

                SecurityManager.Logout();

                ////create new user to Authenticate against newly created login form
                SitefinityTestUtilities.ServerOperations.Users().CreateUser(this.userName, this.password, "*****@*****.**", "test", "test", true, "AuthenticateUser", "IdentityHasClaimTypes", SecurityConstants.AppRoles.FrontendUsers);

                ////There is few ways to redirect to another page
                ////First method is to combine realm param with redirect_uri param to get the full redirect url
                ////Example: ?realm=http://localhost:8086/&redirect_uri=/Sitefinity/Dashboard
                ////Second method is to use only realm or redirect_uri param to get the full redirect url
                ////Example: ?redirect_uri=http://localhost:8086/Sitefinity/Dashboard
                ////Third method is to get ReturnUrl param
                ////Example: ?ReturnUrl=http://localhost:8086/Sitefinity/Dashboard

                string postString = "UserName="******"&Password="******"?redirect_uri=" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage + "&realm=http://localhost/"
                                      + "&ReturnUrl=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockSecondPage;

                    responseContent = PageInvoker.ExecuteWebRequest(testURL1, false);
                    responseContent = PageInvoker.PostWebRequest(testURL1, postString, false);

                    Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!");
                }

                using (PageInvokerRegion region = new PageInvokerRegion())
                {
                    string testURL2 = loginFormPageUrl + "?realm=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage;
                    responseContent = PageInvoker.ExecuteWebRequest(testURL2, false);
                    responseContent = PageInvoker.PostWebRequest(testURL2, postString, false);

                    Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!");
                }

                using (PageInvokerRegion region = new PageInvokerRegion())
                {
                    string testURL3 = loginFormPageUrl + "?redirect_uri=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockFirstPage;
                    responseContent = PageInvoker.ExecuteWebRequest(testURL3, false);
                    responseContent = PageInvoker.PostWebRequest(testURL3, postString, false);

                    Assert.IsTrue(responseContent.Contains(this.searchValueFirst), "The request was not redirected to the proper page set in request url!");
                }

                using (PageInvokerRegion region = new PageInvokerRegion())
                {
                    string testURL4 = loginFormPageUrl + "?ReturnUrl=http://localhost/" + this.urlNamePrefixContentBlockPage + this.pageIndexContentBlockSecondPage;
                    responseContent = PageInvoker.ExecuteWebRequest(testURL4, false);
                    responseContent = PageInvoker.PostWebRequest(testURL4, postString, false);

                    Assert.IsTrue(responseContent.Contains(this.searchValueSecond), "The request was not redirected to the proper page set in request url!");
                }
            }
            finally
            {
                using (new AuthenticateUserRegion(user))
                {
                    this.pageOperations.DeletePages();
                }

                SecurityManager.Logout();
                SitefinityTestUtilities.ServerOperations.Users().DeleteUsers(new[] { this.userName });
            }
        }
Example #10
0
 public LoginForm(LoginFormController controller)
 {
     _controller = controller;
     InitializeComponent();
 }