Observing the User Experience: A Practitioners Guide to User Research

As we discussed earlier in this chapter, one of the benefits of Passport is the ability to give your users a consistent and familiar user interface to use. You ll notice that all Passport-enabled sites use the following Sign In button (note that at the time of this writing, this is the current image):

If the user clicks this button, the Passport Login user interface displays. If the user has authenticated successfully, this button becomes a Sign Out button:

The CPassportRequestHandlerT class that you re building in this chapter will expose this functionality as a stencil tag. Remember from earlier in this book that stencil tags are used in SRF files to insert dynamic content into the stream of data that will be sent to the client.

You ll create a stencil tag to insert the Sign In or Sign Out button that Passport provides. By implementing a stencil tag in CPassportHandlerT , any ATL Server application that you build using this request handler class will be able to insert a Passport Sign In or Sign Out button by simply including the following stencil tag:

Let s take a look at the code necessary to implement this stencil tag. The first step is to add a replacement map to your CPassportHandlerT request handler class:

BEGIN_REPLACEMENT_METHOD_MAP(THandler) REPLACEMENT_METHOD_ENTRY("Passport_LogoTag", OnLogoTag) END_REPLACEMENT_METHOD_MAP()

As you ve probably seen in previous chapters, this replacement map simply associates the stencil tag with the OnLogoTag method. The code for the OnLogoTag method is shown in Listing 21-4.

Listing 21.4: The OnLogoTag Method

1 HTTP_CODE OnLogoTag() 2 { 3 BSTR logoTag(NULL); 4 5 if (FAILED(m_passportManager->LogoTag(m_returnURL, 6 m_timeWindow, 7 m_forceLogin, 8 m_coBrandArgs, 9 m_langId, 10 m_usingHTTPS, 11 m_namespace, 12 m_kpp, 13 m_useSecureAuth, 14 &logoTag))) 15 { 16 m_HttpResponse << "ERROR - could not get LogoTag"; 17 return HTTP_S_FALSE; 18 } 19 20 m_HttpResponse << logoTag; 21 ::SysFreeString(logoTag); 22 23 return HTTP_SUCCESS; 24 }

 

The IPassportManager2::LogoTag method takes several parameters that you should look at individually. All of the input parameters are optional; if they aren t specified, they will be taken from the Passport Manager registry settings. These registry settings are set using the Passport Manager Administrative tool included with the SDK.

Let s have a look at the code for OnLogoTag line-by-line :

As you can see, there are numerous parameters to the LogoTag method; the CPassportHandlerT class that you re building will leave these parameters unspecified. That means that their values will be taken from the Passport Manager registry settings. You can configure these settings using the Passport Manager Administrative tool included with the Passport SDK.

With the stencil tag, an ATL Server application can easily add a Passport Sign In button. You should consult the latest Passport SDK documentation for guidelines as to where this button should appear in your application.

The next step in this scenario, covered in the next section, is to determine whether or not a user is authenticated. You need to know this to decide if you should show content specific to that user.

IsAuthenticated

ATL Server stencils implement basic logic constructs. You can take advantage of this to create a stencil tag that you can branch on, depending on whether or not the user is authenticated. You ll need to do this in order to display user-specific content.

Let s add a stencil tag to CPassportHandlerT called . This stencil tag will return a boolean value, so it can be used in a stencil as follows :

Thanks for signing in! Please sign in!

This stencil tag lets you conveniently divide the generic content from the user-specific content in your pages.

Adding this stencil tag is very similar to what you had to do for . You need to expand your replacement map as follows:

BEGIN_REPLACEMENT_METHOD_MAP(THandler) REPLACEMENT_METHOD_ENTRY("Passport_LogoTag", OnLogoTag) REPLACEMENT_METHOD_ENTRY("Passport_IsAuthenticated", OnIsAuthenticated) END_REPLACEMENT_METHOD_MAP()

This will associate the tag with the OnIsAuthenticated method. Listing 21-5 shows how to implement this method.

Listing 21.5: Authenticating a Passport Login Request

1 HTTP_CODE OnIsAuthenticated() 2 { 3 VARIANT_BOOL isAuthenticated(VARIANT_FALSE); 4 if (FAILED(m_passportManager->IsAuthenticated(m_timeWindow, 5 m_forceLogin, 6 m_useSecureAuth, 7 &isAuthenticated))) 8 { 9 return HTTP_S_FALSE; 10 } 11 12 return isAuthenticated == VARIANT_TRUE ? HTTP_SUCCESS : HTTP_S_FALSE; 13 }

 

This code is simple enough that we don t look at it line-by-line. The first three parameters are optional and serve the same purpose as in the IPassportManager2::LogoTag method. The last parameter is an output parameter that indicates whether or not the user has been authenticated. You ll return a mapping of this boolean value to the boolean values ( HTTP_S_FALSE , HTTP_SUCCESS ) that ATL Server uses in its stencil files.

Now you ve seen how to provide a login user interface for your users to authenticate themselves as well as a way to determine if they ve successfully done so. The only step remaining in this scenario is to display user-specific content.

Категории