예제 #1
0
        public ActionResult Hash(Guid?faqId, Guid?categoryId, Guid?subcategoryId, string keywords)
        {
            // Faq.

            if (faqId != null)
            {
                var faq = _faqsQuery.GetFaq(faqId.Value);
                if (faq != null)
                {
                    var url = faq.GenerateUrl(_faqsQuery.GetCategories()).AsNonReadOnly();
                    if (!string.IsNullOrEmpty(keywords))
                    {
                        url.QueryString["keywords"] = keywords;
                    }
                    return(RedirectToUrl(url));
                }
            }

            // Subcategory.

            if (subcategoryId != null)
            {
                var subcategory = _faqsQuery.GetSubcategory(subcategoryId.Value);
                if (subcategory != null)
                {
                    return(RedirectToUrl(subcategory.GenerateUrl()));
                }
            }

            // Search.

            if (!string.IsNullOrEmpty(keywords))
            {
                return(RedirectToRoute(FaqsRoutes.Search, new { categoryId, keywords }));
            }

            // If nothing then redirect to the faqs page.

            return(RedirectToRoute(FaqsRoutes.Faqs));
        }
예제 #2
0
        public ActionResult LogIn(Login loginModel, [Bind(Include = "RememberMe")] CheckBoxValue rememberMe)
        {
            var profile = _linkedInQuery.GetProfile(CurrentAnonymousUser.Id);

            if (profile == null)
            {
                return(RedirectToRoute(HomeRoutes.Home));
            }

            try
            {
                loginModel            = loginModel ?? new Login();
                loginModel.RememberMe = rememberMe != null && rememberMe.IsChecked;
                var result = _accountsManager.LogIn(HttpContext, loginModel);

                // Go to the next page.

                switch (result.Status)
                {
                case AuthenticationStatus.Disabled:

                    // If they are disabled, simply redirect them.

                    var faq = _faqsQuery.GetFaq(DisableFaqId);
                    return(RedirectToUrl(faq.GenerateUrl(_faqsQuery.GetCategories())));

                case AuthenticationStatus.Failed:
                    throw new AuthenticationFailedException();

                case AuthenticationStatus.Deactivated:

                    // Activate them.

                    _userAccountsCommand.ActivateUserAccount(result.User, result.User.Id);
                    break;
                }

                // The user has been authenticated so associate them with the LinkedIn profile.

                profile.UserId = result.User.Id;
                _linkedInCommand.UpdateProfile(profile);

                return(RedirectToReturnUrl());
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View("Account", GetAccountModel(loginModel, profile)));
        }
예제 #3
0
파일: FaqTests.cs 프로젝트: formist/LinkMe
        public void TestFaqs()
        {
            var categories   = _faqsQuery.GetCategories();
            var subcategory1 = categories.Single(c => c.Name == "Candidates").Subcategories.Single(s => s.Name == "About LinkMe");
            var subcategory2 = categories.Single(c => c.Name == "Employers").Subcategories.Single(s => s.Name == "Folders and notes");

            // GetFaqs()

            var faqs = _faqsQuery.GetFaqs();

            Assert.AreEqual(173, faqs.Count);

            var faq1 = (from f in faqs where f.Title == Title1 select f).Single();
            var faq2 = (from f in faqs where f.Title == Title2 select f).Single();

            AssertFaq(Title1, Text1, subcategory1, faq1);
            AssertFaq(Title2, Text2, subcategory2, faq2);

            // GetFaq(id)

            AssertFaq(Title1, Text1, subcategory1, _faqsQuery.GetFaq(faq1.Id));
            AssertFaq(Title2, Text2, subcategory2, _faqsQuery.GetFaq(faq2.Id));
            Assert.IsNull(_faqsQuery.GetFaq(Guid.NewGuid()));

            // GetFaqs(ids)

            faqs = _faqsQuery.GetFaqs(new[] { faq1.Id });
            Assert.AreEqual(1, faqs.Count);
            AssertFaq(Title1, Text1, subcategory1, faqs[0]);

            faqs = _faqsQuery.GetFaqs(new[] { faq1.Id, faq2.Id });
            Assert.AreEqual(2, faqs.Count);
            AssertFaq(Title1, Text1, subcategory1, (from f in faqs where f.Id == faq1.Id select f).Single());
            AssertFaq(Title2, Text2, subcategory2, (from f in faqs where f.Id == faq2.Id select f).Single());

            Assert.AreEqual(0, _faqsQuery.GetFaqs(new[] { Guid.NewGuid() }).Count);
        }
예제 #4
0
        protected override ResourceContent GetContent(Guid id, object cache)
        {
            // Look for the resource item.

            var article = _resourcesQuery.GetArticle(id);

            if (article != null)
            {
                return new ResourceContent {
                           Resource = article, Views = _resourcesQuery.GetViewingCount(id)
                }
            }
            ;

            var video = _resourcesQuery.GetVideo(id);

            if (video != null)
            {
                return new ResourceContent {
                           Resource = video, Views = _resourcesQuery.GetViewingCount(id)
                }
            }
            ;

            var qna = _resourcesQuery.GetQnA(id);

            if (qna != null)
            {
                return new ResourceContent {
                           Resource = qna, Views = _resourcesQuery.GetViewingCount(id)
                }
            }
            ;

            var faq = _faqsQuery.GetFaq(id);

            if (faq != null)
            {
                return new ResourceContent {
                           Resource = faq, Views = 0
                }
            }
            ;

            return(null);
        }
예제 #5
0
        protected ActionResult TryLogIn(Login login, CheckBoxValue rememberMe, Func <AuthenticationResult, ReadOnlyUrl> getReturnUrl, Func <IErrorHandler> createErrorHandler)
        {
            try
            {
                login            = login ?? new Login();
                login.RememberMe = rememberMe != null && rememberMe.IsChecked;
                var result = _accountsManager.LogIn(HttpContext, login);

                // Go to the next page.

                switch (result.Status)
                {
                case AuthenticationStatus.AuthenticatedMustChangePassword:
                    return(RedirectToRoute(AccountsRoutes.MustChangePassword, new RouteValueDictionary(new Dictionary <string, object> {
                        { Apps.Asp.Constants.ReturnUrlParameter, getReturnUrl(result) ?? HttpContext.GetReturnUrl() }
                    })));

                case AuthenticationStatus.Disabled:

                    var faq = _faqsQuery.GetFaq(DisableFaqId);
                    return(RedirectToUrl(faq.GenerateUrl(_faqsQuery.GetCategories())));

                case AuthenticationStatus.Deactivated:
                    return(GetDeactivatedResult(result, getReturnUrl));

                case AuthenticationStatus.Failed:
                    throw new AuthenticationFailedException();

                default:
                    return(GetAuthenticatedResult(result, getReturnUrl));
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, createErrorHandler());
            }

            return(null);
        }
예제 #6
0
        private static void OnLoginDisabled()
        {
            var faq = _faqsQuery.GetFaq(DisableFaqId);

            NavigationManager.Redirect(faq.GenerateUrl(_faqsQuery.GetCategories()));
        }