Login Example

The Smartsite Login macro allows for signing in and out using the underlying ASP.NET Membership Provider Model. It is completely independent of the actual provider used, and it doesn't output an HTML form. Instead, it passes your logon data to the Membership layer and gives you a maximum of flexibility in how you implement user interface and logon behavior.

Smartsite SXML CopyCode image Copy Code
<!--//
    Complete handling of logging on and off
-->
<se:if expression="user.isanonymous()">
    <se:then>        
        <!--//
            No user currently signed in: show logon form
        -->
        <se:placeholder.addjavascriptinclude url="/assets/behavior/classes/loginform.js" priority="-1"/>
    
        <!--//
            Show the login form. 
        -->    
        <div id="LoginPane" class="LinkPopup" title="Login">            
            <form class="LoginForm CoolForm" action="{request.location()}" method="post">
                
                <label for="txtUserName">Gebruikersnaam</label>
                <input class="textbox Required" title="User name" name="txtUserName" id="txtUserName"/><br />
                
                <label for="txtPassword">Wachtwoord</label>
                <input class="textbox Required" title="Password" type="password" name="txtPassword" id="txtPassword"/><br />
                
                <label for="chkRM">Gegevens onthouden</label>
                <input class="checkbox" title="Remember Me" type="checkbox" name="chkRM" id="chkRM"/>
                
                <br />
                <input class="LogOnButton" type="submit" value="Inloggen"/>
                
            </form>    
         </div>
         
         <!--//
             Handle the login data if provided by the user.
         -->
         
         <se:login
                namefield="txtUserName"
                passwordfield="txtPassword"
                remembermefield="chkRM"
             >
             
             <se:parameters>
                 <se:parameter name="resultformat">
                    <!--//
                        The ResultFormat is used on login success. Logon failures can be handled in the Error property.
                    -->
                    <se:placeholder.addjavascriptonload>
                        document.getElementById('LoginPane').innerHTML = "Logon successful! Wait while you are transferred to your destination page...";
                        
                        var moveToDestination = function(){
                            document.location.replace("{sys.iif(request.query.exists('ReturnUrl'), request.query(returnurl), channel.link())}");
                        };
                        
                        setTimeout(moveToDestination, 100);
                        
                    </se:placeholder.addjavascriptonload>
                    
                </se:parameter>
                <se:parameter name="error">
                    <!--//
                        When a logon fails, show an error.
                    -->
                    <h4 class="error">Error logging on: {this.error.message()}</h4>
                </se:parameter>
             </se:parameters>
             </se:login>
        
    </se:then>
    <se:else>
        <!--// 
            Offer the user a way to log off...
        -->
        <se:if expression="request.query.exists(undologon)">
            <se:then>
                {login.undo()} <!--// sign out the user and refresh the current page -->
            </se:then>
            <se:else>
                <!--// Show a link to sign out -->
                <a href="{url.setparameter(request.location(), 'undologon', '1')}" title="Log off as '{user.fullname()}'">Log off {user.fullname()}</a>
            </se:else>
        </se:if>
    </se:else>
</se:if>