Login Helpers

Last Updated 3/5/2015
With the login helpers you can create a custom portals

Building a Portal

A portal, or an area of the website you log into is build by creating a layout containing the Login helper and applying that layout to the pages to be secured within the portal. We are going to build a basic portal with a layout, a login page, a login helper page (for lost passwords and new users) and a link to a data form to update the user's profile.
Our Portal will consist of:
  • Layout - Customer Portal
  • Portal Landing page -  /customerportal
  • Customer Portal Help page -  /customerportalhelp
  • Profile page - list the customer profile and link to update form
  • Update Profile form - a data form for the current user to update their profile

Layout

Here is what our final layout code will look like.

Lets look at the different parts that make up the layout. First we will look at the function block at the top of the layout


First we declare the Engine Record _user. _user will hold the information about our logged in user



InitialIzePage()
We override the InitializePage() function to call the LoginAs, Login, Logout and check for the _user. Here is a break down of each.

BRT.LoginAs

LoginAs allows users logged into the BrickRiver Console to log in as any of the contacts in the view used for the portal.

BRT.LoginAs() has a single parameter: viewId.  The viewId is the view of contacts you are using for your portal. In our example the Organizations contacts will be using this portal.

You must specify the login link in the XML for the view

To access the portal using the LoginAs feature go to the record in the view the contact is located in and from the action menu select the action link you created.


BRT.Logout()

We check if the user is logging out by checking the query string. If they are logging out we call BRT.Logout to log them out of the portal and then redirect them.

BRT.UserRecord()
If the user is not logging out then we call BRT.UserRecord to set _user

BRT.UserRecord thas the following parameters:
  • viewId - the Id of the contact view that has the contacts that can log into the portal
  • fields - a list of fields from the user record you want to get while checking the user
  • condition - add a condition to filter the users that can log in
  • savedFilters - use a SavedFilter from the view to filter the users accessing the portal
PageData[]
Set PageData[] to pass information from the layout to the pages in the portal

InitializeBase()
In the InitializePage function we need to call the InitializeBase() function.


Now the rest of the layout. Out layout is inheriting the Root layout for the site so we do not have to include the html, head and body tags; just the content of the layout. The content of the layout is broken into three parts:

1 If the layout is opened in the page editor render the body of the page
 We call BRT.RenderContenct.IsDesign to check if the page is in the page designer.


2 Display the login form if the user is not logged in and display the login help if the user is on the login help page
 

A Check if _user is null.  If _user is null we want to display the login form or the login help

B Check if the user is on the login help page by checking the friendly. If they are on the login help page call the LoginHelp helper

@BRT.LoginHelp() is used to display the login help form so a new user can create a username an password or an existing user can change their password. BRT.LoginHelp accepts the following parameters:
  • viewId - the Id of the contact view that has the contacts that can log into the portal
  • condition - add a condition to filter the users that can log in
  • savedFilters - use a SavedFilter from the view to filter the users accessing the portal
C Display the login form. 

@BRT.LoginForm() displays the login form. BRT LoginFrom accepts the following parameters:
  • viewId - the Id of the contact view that has the contacts that can log into the portal
  • condition - add a condition to filter the users that can log in
  • savedFilters - use a SavedFilter from the view to filter the users accessing the portal
  • template - a razor template for the form. In your template you will need to include for the template you can use the Username, KeepLoggedIn and Invalid properties of the item. 
3 Display the page content
In our template we want a side nav that will include all the pages in the portal.  We use @BRT.SiteMenu to create the menu. Then we add a logout link so that our user can logout on any of the portal pages.

At the top of our page we display the name of our organization using the @PageData["Name'] 
When you are done, publish the layout. 

Portal Landing Page

In the Site create the portal landing page. We are creating the page with the friendly name customerportal. If you use a different friendly be sure to change the layout to reflect your friendly. (line 8 in our example)

Add the Customer Portal layout the landing page.  That's all you need to do!  You can add any content you want to the page

Customer Portal Help Page

Add the Customer Portal Help page as a child page to the Customer Portal page. Give it a friendly name of customerportalhelp.  If you choose a different friendly change line 30.  In the page properties check the Hide from menus box so the page won't show up on our menu. Add the Customer Portal layout to the page and publish the page

Profile Page

Create a Profile page under the Portal Landing page. Select the Customer Portal Layout and save the page. We are going to add a link to the Update Profile form from this page once we create the Data Form.

Update Profile Form
Create a new data form.  Admins can create data forms from the Admin menu. For this data form we want the Organization to update their mailing address, username and password.  See the data forms article and creating a view for a data form for more information on data forms.

After creating the Profile data form get the DataLink helper code at the bottom of the data form page.

Paste the code into the source of the Profile page.

Now we want to change the BRT.DataLink helper we just pasted into the page to link to our existing profile so we can edit the profile rather than create a new one.  In the BRT.DataLink helper we want to add the recordId parameter and set it to  PageData["MyId"] that we set in the layout.

Additional Pages

You can add any additional pages you want to the portal.  Just keep in mind 2 things.  First, make sure you add the portal layout to the page. Second, if you want the page to link off of the portal menu make sure it is a child of the portal landing page.

Want to learn more?

Call 800-924-5220 or

Free trial