I am building module to register customers and after registration i need to redirect the user to home page (default). I cant see a way as in Orchard everything works as content items.
Some of my code from Controller is given below
$ if (!ModelState.IsValid)
return new ShapeResult(this, _services.New.Checkout_Signup(Signup: signup));
var customer = _customerService.CreateCustomer(signup.Email, signup.Password);
customer.FirstName = signup.FirstName;
customer.LastName = signup.LastName;
customer.Title = signup.Title;
_authenticationService.SignIn(customer.User, true);
return Redirect("~/Home Page URL here...");
In Orchard, the home page has an empty string for its alias. It's possible to look up the RouteValueDictionary of an alias by calling the IAliasService.Get() method. Once you have this, you can simply pass it to RedirectToRoute().
So for the home page:
var homepage = _aliasService.Get(String.Empty);
return RedirectToRoute(homepage);
You can see Orchard using this mechanism to check the home page in the AutoroutePartDriver.cs file lines 66 - 72 in version 1.7.2.
Related
We got the need to display a blog posts page that display X posts - first post is displayed as a header and the rest are in 2 columns. The page has a show more button at the bottom that fetches the next page posts using ajax and adding them at the bottom.
Is it possible to get X+1 items for the subsequent pages?
Any hint, even in code are welcome since we use a sourced version of orchard installation.
So before cluttering the comments above this is my proposed solution.
I think there was a slight misunderstanding about changing the controller action which I'd like to clarify (I hope I understood everything correctly now):
Orchard.Blogs | BlogController | Item Action
public ActionResult Item(int blogId, PagerParameters pagerParameters) {
// This is all original code
Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
var blogPart = _blogService.Get(blogId, VersionOptions.Published).As<BlogPart>();
if (blogPart == null)
return HttpNotFound();
if (!_services.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, blogPart, T("Cannot view content"))) {
return new HttpUnauthorizedResult();
}
// This is the actual change:
// Use the pagerParameters provided, otherwise fall back to the blog settings
pager.PageSize = pagerParameters.PageSize.HasValue ? pager.PageSize : blogPart.PostsPerPage;
// This is all original code again
_feedManager.Register(blogPart, _services.ContentManager.GetItemMetadata(blogPart).DisplayText);
var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize) // Your new page size will be used
.Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
dynamic blog = _services.ContentManager.BuildDisplay(blogPart);
var list = Shape.List();
list.AddRange(blogPosts);
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
var totalItemCount = _blogPostService.PostCount(blogPart);
blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after");
return new ShapeResult(this, blog);
}
So the change is very subtle, but this way I would configure the blogs default pageSize to 7 items and for every subsequent Ajax-Request I'd provide a "pageSize"-Parameter with the desired size.
I am using Code first method instead of record method. I have login page from which i am moving to next page that is home page.
public HomePage SubmitClick(string userName, string Password)
{
HtmlEdit txtUsername = new HtmlEdit(_browserWindow);
txtUsername.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "txt_empid");
txtUsername.Text = userName;
HtmlEdit txtPassword = new HtmlEdit(_browserWindow);
txtPassword.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "txt_password");
txtPassword.Text = Password;
HtmlInputButton btnSubmit = new HtmlInputButton(_browserWindow);
btnSubmit.SearchProperties.Add(HtmlInputButton.PropertyNames.Id, "btn_submit");
Mouse.Click(btnSubmit);
return new HomePage(_browserWindow);
}
Redirecting is working fine. My question is how to identify if the open page is valid or not.
What i am planning is to check for some controls like button and hyperlinks if they exist then page is valid. Is it a good method.
First give _browserwindow.WaitForControlReady() it will wait till the browserwindow completely loads the page.
Once the page is loaded use Assert to check for the title of the page whether it is the same as expected.
_browserwindow.WaitForControlReady();
WinTabPage nextPage = new WinTabPage(_browserwindow);
Assert.AreEqual("Home Page", nextPage.Name);
Compare the URL of the next Page.If its the URL thats required then the test case passes.
Uri url = BrowserwindowObj.Uri;
This gives the URL of the current browser Page.
I have a situation where my client wants to have SEO friendly URLs for their documents and for these URLs to flow down to the client documents. Here is an example setup:
Root
Groups
Group1 (custom url=/groups/ma/salem/group1)
Page1
Page2
Group2 (custom url=/groups/ma/boston/group2)
Page2
Page4
etc.
The would like Page1, Page2, Page3, Page4 to inherit it's parent's custom url and be:
/groups/ma/salem/group1/page1
/groups/ma/salem/group1/page2
/groups/ma/boston/group2/page2
/groups/ma/boston/group2/page3
When I set the Custom URL path it only affects that document and the child documents stay the same:
/groups/group1/page1
/groups/group1/page2
/groups/group2/page2
/groups/group2/page3
Can this be achieved in Kentico without modifying the tree structure to contain the URL parts?
Is there a way to override the ResolveURL() function so i can return the SEO friendly URL?
I'm using Kentico 8.1
Creating those document in the tree would be definitely the easiest and safest solution, but taken you want to avoid this I see two other options.
1) Create URL rewriting rules to simulate this tree hierarchy
2) Catch document insert before event and set the custom URL path according your needs.
Code could look something like this:
DocumentEvents.Insert.Before += DocumentInsert_Before;
private static void DocumentInsert_Before(object sender, DocumentEventArgs e)
{
TreeNode node = e.Node;
if (node.NodeAliasPath.StartsWith("/groups/group1")) {
string safeNodeName = TreePathUtils.GetSafeDocumentName(node.DocumentName, CMSContext.CurrentSiteName);
string customPath = "/groups/ma/salem/group1/" + safeNodeName;
// Handle multiple dashes
customPath = TreePathUtils.GetSafeUrlPath(path, CMSContext.CurrentSiteName, true);
node.DocumentUrlPath = customPath;
}
}
I used search portlet in my portal. And when i click on the search result always it redirects to result's public page. E.g: I searched for a site through site name. And the result comes. When i click on the result it redirect always redirect me to site's public page, even i am the member of the site.
I want when if user is the member of the site, it must be redirected to the site's private page.
You can hook the search portlet. In the main_search_result_form.jsp you can change the URL to your private page.
Make changes in the below lines.
viewFullContentURL = _getViewFullContentURL(request, themeDisplay, PortletKeys.ASSET_PUBLISHER, document);
viewFullContentURL.setParameter("struts_action", "/asset_publisher/view_content");
if (Validator.isNotNull(returnToFullPageURL)) {
viewFullContentURL.setParameter("returnToFullPageURL", returnToFullPageURL);
}
viewFullContentURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId()));
viewFullContentURL.setParameter("type", assetRendererFactory.getType());
if (Validator.isNotNull(assetRenderer.getUrlTitle())) {
if ((assetRenderer.getGroupId() > 0) && (assetRenderer.getGroupId() != scopeGroupId)) {
viewFullContentURL.setParameter("groupId", String.valueOf(assetRenderer.getGroupId()));
}
viewFullContentURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
}
I'm very new with orchard.
To learn orchard module development, I followed the documentation and tried to create a commerce module.
The module consists of product part and product type which has product part.
During enable module, it will create admin and home menu for this module, "Commerce" and "Shop" respectively.
My questions are
How do I make this module to be home page during enable module. In other word, I want Index method of
the module's HomeController handle home url?
How do I get Shop menu in front end to be after home menu or register this module to home menu?
I am attaching source code, please download it from the following link
download source code
To take over the home page the standard Orchard way is to implement IHomePageProvider.
You can, when creating a page as part of migrations.cs in a module, tell the Autoroute part to set your created page's alias as the homepage:
//create a page page
var homepage = _contentManager.Create("Page");
homepage.As<TitlePart>().Title = "My Home";
_contentManager.Publish(homepage);
var homePageArp = homepage.As<AutoroutePart>();
homePageArp.DisplayAlias = String.Empty;
_autorouteService.PublishAlias(homePageArp);
This assumes you're going from a clean instance of Orchard without any prior homepages; if you have an existing homepage, you'll have to regenerate those pages' Aliases as part of your module too. This is how it's done as part of the AutoroutePartHandler in the Orchard.Autoroute project (inside the Publish Alias method):
// regenerate the alias for the previous home page
var currentHomePages = _orchardServices.ContentManager.Query<AutoroutePart, AutoroutePartRecord>().Where(x => x.DisplayAlias == "").List();
foreach (var current in currentHomePages) {
if (current != null) {
current.CustomPattern = String.Empty; // force the regeneration
current.DisplayAlias = _autorouteService.Value.GenerateAlias(current);
}
_autorouteService.Value.PublishAlias(current);
}
_autorouteService.Value.PublishAlias(part);
If you dig through the driver and handler for the autoroute project, you'll learn a lot about the internals; when you tick that "set as homepage" box in the Admin UI, it sets the Path to "/" and then that gets picked up, triggers the old homepage re-wire, clears the "/" path to String.Empty and then publishes that blank alias, giving you a new homepage.
(this is valid as of Orchard 1.6)
If your module is to be used by others, then it is better to make a widget which can be added to any layer (the homepage layer for example). That way each user can decide where your module comes into play.
If you are using this module for yourself only, then you can just override the default routes (standard mvc functionallity).
Look at my ExtendedRegistration module (Routes.cs) to see how it's done.
Here I am overriding the standard Account/Register URL. There should be nothing preventing you from overriding the default HomeController.
public class Routes : IRouteProvider
{
public void GetRoutes(ICollection<RouteDescriptor> routes)
{
foreach (var routeDescriptor in GetRoutes())
{
routes.Add(routeDescriptor);
}
}
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new RouteDescriptor {
Priority = 19,
Route = new Route(
"Users/Account/Register",
new RouteValueDictionary {
{"area", "itWORKS.ExtendedRegistration"},
{"controller", "Account"},
{"action", "Register"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "itWORKS.ExtendedRegistration"}
},
new MvcRouteHandler())
}
};
}
}