How to build a custom main page for identified users

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.3
  • Enterprise
  • Community
  • Planned

Overview

You may want to set custom main page for identified users on your site in order to be able to customize the visibility of different pages of your site. By editing the original code-base of Sense/Net it is easy to add this kind of functionality.

Steps

1. Customize login-page

Login page needs to be set as the main-page of the site for unidentified users (visitors). To achieve this customise your login-page: on the login page of your site go to Actions/Set permissions and on both group of „Visitors” and „Everyone” set the highest allowed permision to „Open”

Set permission on login-page

2. Setup your site's accessibility

Look up the page (apps)/This/Browse under your site, and set „Visitors” and „Everyone” groups’ highest allowed permission to „See”. Act the same way with all other contents you want to set like your site. With this setting unidentified users will not have access to these pages.

Set permission on your site's pages


3. Redirect identified users to custom main page

If the users are logged in as identified users, they must be redirected to the specified main-page that is set. To achieve this at first you need to detect the current user-profile and get the specific path. Create a new custom rule in Login Extender. The original „LoggedIn” method needs to be overridden as it is shown below:

public class MyLoginExtender : LoginExtender
    {
        public override void LoggedIn(LoginInfo info)
        {
            using (new SystemAccount())
            {
                var user = (User)User.Load(info.UserName);
 
                if (!user.IsProfileExist())
                    user.CreateProfile();
 
                var profilePath = user.GetProfilePath();
                if (Node.Exists(profilePath))
                    HttpContext.Current.Response.Redirect(profilePath);
            }
        }      
    }

This method redirects the user to its own profile page after login.

4. Redirect to main pages according to group-memberships

After the identified user is logged in, she will be redirected to the custom main page that is set by the user-group: you need to override the LoggedIn method again in Login Extender with the following sniplet:

public class MyLoginExtender : LoginExtender
    {
        public override void LoggedIn(LoginInfo info)
        {           
            using (new SystemAccount())
            {
                var user = (User)User.Load(info.UserName);
 
                var identifiedUserHomePagePath = "/workspaces";
                var adminUserHomePagePath = "/features";
 
                var identifiedUsers = Node.Load<Group>("/Root/IMS/BuiltIn/Portal/IdentifiedUsers");
                var adminUsers = Node.Load<Group>("/Root/IMS/BuiltIn/Portal/Administrators");
 
                if (user.IsInGroup(adminUsers))
                    HttpContext.Current.Response.Redirect(adminUserHomePagePath);
                else if (user.IsInGroup(identifiedUsers))
                    HttpContext.Current.Response.Redirect(identifiedUserHomePagePath);
            }
        }
    }

Related links