Using CPassportHandlerT


Let s take a look at how you can use your new request handler class to build a simple implementation of this chapter s scenario.

CPassportHandlerT can basically be used like the default CRequestHandlerT class that Visual Studio uses when generating a new ATL Server project. Here s the definition for your ATL Server application class:

 #pragma once  #include "passporthandlert.h"  class CatlspassportHandler :      public CPassportHandlerT<CatlspassportHandler>  {  public:      HTTP_CODE ValidateAndExchange()      {          return HTTP_SUCCESS;      }  };  BEGIN_HANDLER_MAP()      HANDLER_ENTRY("Default", CatlspassportHandler)  END_HANDLER_MAP() 

As you can see, the only change you ve made is to use the CPassportHandlerT class. Because you re just building a simple example, most of the work will be in the SRF file, as shown in Listing 21-8.

Listing 21.8: Using a Passport-Enabled Request Handler in SRF
start example
 1 {{handler atlspassport.dll/Default}}  2 <html>  3    <head>  4    </head>  5    {{Passport_LogoTag}}  6    <br>  7    {{if Passport_IsAuthenticated}} Great, you've signed in!  8    <br>  9    Here's what we know about you:  10    <table border="1">  11        <tr>  12           <td>memberName</td>  13            <td>{{Passport_GetProfile(memberName)}}</td>  14        </tr>  15        <tr>  16            <td>memberIdLow</td>  17            <td>{{Passport_GetProfile(memberIdLow)}}</td>  18        </tr>  19        <tr>  20            <td>memberIdHigh</td>  21            <td>{{Passport_GetProfile(memberIdHigh)}}</td>  22        </tr>  23        <tr>  24            <td>profileVersion</td>  25            <td>{{Passport_GetProfile(profileVersion)}}</td>  26        </tr>  27        <tr>  28            <td>country</td>  29            <td>{{Passport_GetProfile(country)}}</td>  30        </tr>  31        <tr>  32            <td>memberName</td>  33            <td>{{Passport_GetProfile(memberName)}}</td>  34        </tr>  35        <tr>  36            <td>postalCode</td>  37            <td>{{Passport_GetProfile(postalCode)}}</td>  38        </tr>  39        <tr>  40            <td>region</td>  41            <td>{{Passport_GetProfile(region)}}</td>  42        </tr>  43        <tr>  44            <td>city</td>  45            <td>{{Passport_GetProfile(city)}}</td>  46        </tr>  47        <tr>  48            <td>lang_preference</td>  49            <td>{{Passport_GetProfile(lang_preference)}}</td>  50        </tr>  51        <tr>  52            <td>bday_precision</td>  53            <td>{{Passport_GetProfile(bday_precision)}}</td>  54        </tr>  55        <tr>  56            <td>{{Passport_GetProfile(birthdate)}}</td>  57        </tr>  58        <tr>  59            <td>gender</td>  60            <td>{{Passport_GetProfile(gender)}}</td>  61        </tr>  62        <tr>  63            <td>preferredEmail</td>  64            <td>{{Passport_GetProfile(preferredEmail)}}</td>  65        </tr>  66        <tr>  67           <td>nickname</td>  68            <td>{{Passport_GetProfile(nickname)}}</td>  69        </tr>  70        <tr>  71            <td>wallet</td>  72            <td>{{Passport_GetProfile(wallet)}}</td>  73        </tr>  74        <tr>  75            <td>directory</td>  76            <td>{{Passport_GetProfile(directory)}}</td>  77        </tr>  78        <tr>  79            <td>flags</td>  80            <td>{{Passport_GetProfile(flags)}}</td>  81        </tr>  82    </table>  83    {{else}}  84            Why don't you sign in?  85 {{endif}}  86 </html> 
end example
 

Let s take a look at this SRF code line-by-line :

  • Line 1: This is the usual SRF tag to associate this SRF file with the ATL Server request handler in the DLL.

  • Line 5: This tag will be replaced by the Sign In or Sign Out button image that Passport provides, depending on whether or not the user has been authenticated with Passport.

  • Line 7: This is where you can take advantage of the branching properties in SRF. Recall that you implemented {{Passport_IsAuthenticated}} to return a boolean value (actually an SRF interpretation of a boolean value). If the user has been authenticated with Passport, you ll display profile information about that user. Otherwise, you ll display a message prompting the user to sign in (line 84).

  • Lines 13 through 80: This block of SRF code will be executed if the user has been authenticated with Passport. In this block, you re making calls to your {{Passport_GetProfile}} tag. This tag will return information about the authenticated user. If you re using the test or beta Passport environment (you most likely are), then you ll get to see only dummy profile values. Once your site has been registered as an official Passport site, you can configure Passport Manager to use the production environment, which has actual profile values.




ATL Server. High Performance C++ on. NET
Observing the User Experience: A Practitioners Guide to User Research
ISBN: B006Z372QQ
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net