We used my_profile.jsp to log in users. The content of the page depends on whether or not the user is logged in, based on the transient property of the /atg/userprofiling/Profile servlet bean.

Note: The “. . .” markers in the following code sample indicate a place where code has been removed to clarify the sample.

<dsp:importbean bean="/atg/userprofiling/Profile"/>
. . .
<dsp:droplet name="/atg/dynamo/droplet/Switch">
  <dsp:param bean="Profile.transient" name="value"/>
  <dsp:oparam name="true">
    <dsp:include page="LoginFragment.jsp" flush="true"></dsp:include>
  </dsp:oparam>
  <dsp:oparam name="false">
    <dsp:include page="ProfileFragment.jsp" flush="true"></dsp:include>
  </dsp:oparam>
</dsp:droplet>

If the transient property is true, the user is not logged in, andLoginFragment.jsp is displayed, inviting him to do so:

The following is the portion of LoginFragment.jsp that we used to generate the login form.

<dsp:form action="my_profile.jsp" method="post">
<!-- If there is a problem with the login, return to this page to
     display error msgs -->
<dsp:input bean="B2CProfileFormHandler.loginErrorURL"
           beanvalue="/OriginatingRequest.requestURI" type="hidden"/>
<!-- always display empty username/login fields to our visitor -->
<dsp:input bean="B2CProfileFormHandler.extractDefaultValuesFromProfile"
           type="hidden" value="false"/>
    <table>
       <tr>
          <td>Username</td><td><dsp:input bean="B2CProfileFormHandler.value.login"
                                          size="10" type="text"/></td>
       </tr>
       <tr>
       <td>Password</td><td><dsp:input bean="B2CProfileFormHandler.value.password"
                                       size="10" type="password"/></td>
       </tr>
    </table>
  <p>
<dsp:input bean="B2CProfileFormHandler.login" type="submit" value="Log in"/>
</dsp:form>

We created a new component located at /atg/userprofiling/B2CProfileFormHandler. (See the Working withForms and Form Handlers chapter in the ATG Programming Guide for more information on ProfileFormHandler. This component is an instance of the atg.projects.b2cstore.B2CProfileFormHandler class, which extends theatg.commerce.profile.CommerceProfileFormHandler, a subclass ofatg.userprofiling.ProfileFormHandler. (Most often, a web application would just keep the location of the form handler for the profile in the original location /atg/userprofiling/ProfileFormHandler because it is easy to find. You can move a component to any location but it is easiest to keep the standard components in the standard places for easier site maintenance.)

The login process itself is not customized; the login form associates its input tags with the value property of the handler, and the Log in button invokes thehandleLogin() method to log in the user.

Clicking on the Log in button always brings the user back to my_profile.jsp. If the login attempt is unsuccessful, error messages are displayed in LoginFragment.jsp; otherwise,ProfileFragment.jsp is displayed.

If the user is not registered, he is invited to do so with a Become a member link to register.jsp.

 
loading table of contents...