The standard login block that is included will do the trick *sometimes* but in case you wanted to offer something a bit more custom/unique, here is some code that can help you along the way:


<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<div>
<g:evaluate>
var logoutAction = "/logout.do";
var backtrack_path = "";
var tran = GlideTransaction.get();
if (tran.isVirtual())
backtrack_path = "../";
var pageLink = new GlideCMSPageLink().getPageLink(current_page.getID()).substring(3);
var documentKey = RP.getParameterValue('sysparm_document_key');
if (documentKey)
pageLink += '?sysparm_document_key=' + documentKey;
var pageLinkNotEncoded = pageLink;
pageLink = GlideStringUtil.urlEncode(pageLink);
</g:evaluate>
<j:if test="${gs.getSession().isLoggedIn()}">
<g:evaluate var="jvar_logout_url">
var defaultPageLink = "";
var siteGR = new GlideRecord("content_site");
if (siteGR.get(current_page.getSiteID())) {
var defaultPageId = siteGR.getValue("default_page");
if (defaultPageId)
defaultPageLink = new GlideCMSPageLink().getPageLink(defaultPageId).substring(3);
}
defaultPageLink;
</g:evaluate>
<form name="logoutPage" action="${logoutAction}">
<j:if test="${jvar_logout_url!=''}">
<input type="hidden" name="sysparm_goto_url" value="logout_redirect.do?sysparm_url=${jvar_logout_url}"/>
</j:if>
<div>
<j:if test="${!gs.getUser().isXML()}">
<a href="profile.do" title="${gs.getMessage('My Profile')}" aria-label="${gs.getMessage('My Profile')}">${SNC.GlideHTMLSanitizer.sanitize(gs.getUserDisplayName())}</a>$[SP]$[SP]|$[SP]
</j:if>
<j:if test="${gs.getUser().isXML()}">
${SNC.GlideHTMLSanitizer.sanitize(gs.getUserDisplayName())}$[SP]$[SP]|$[SP]
</j:if>
<a class="cms_header_login_link" onclick="logoutPage.submit()" title="${gs.getMessage('Logout')}" aria-label="${gs.getMessage('Logout')}" tabindex="0"> ${gs.getMessage('Logout')}</a>$[SP]$[SP]
<img src="translink.pngx" class="compImg"/>
</div>
</form>
</j:if>
<j:if test="${!gs.getSession().isLoggedIn()}">
<j:set var="jvar_login_highlight" value="" />
<g:evaluate var="jvar_login_failed" expression="RP.getParameterValue('sysparm_login_failed')" />
<j:if test="${jvar_login_failed=='true'}">
<j:set var="jvar_login_highlight" value="cms_login_failed_inputs" />
<script>
setTimeout(signInFailed,10);
function signInFailed() {
var userName = gel("user_name");
var y = userName.offsetTop + userName.offsetHeight;
var x = grabOffsetLeft(userName);
var div = cel("div");
div.id = "login_failed";
div.style.position = "absolute";
div.style.top = y;
div.style.left = x;
div.className = "cms_login_failed_message";
div.innerHTML = "${gs.getMessage('Login failed. Try again.')}";
document.body.appendChild(div);
userName.focus();
setTimeout(signInFailedHide,5000);
}
function signInFailedHide() {
var div = gel("login_failed");
if (div)
rel(div);
}
</script>
</j:if>
<form name="loginPage" id="loginPage" action="login.do" method="post" target="login_iframe">
<!– we're going to use the sysparm_goto_url to send the login to a page (cms_login_redirect) that is NOT
in the path of the CMS site. That way, the cookies get set up using the path of the instance instead of
the path of the CMS site. This makes the logout function work as expected. When
the login fails, the sysparm_login_url parameter is used to redirect back to the
same page with some parameters that cause the failure message to be displayed.
–>
<input type="hidden" name="sysparm_login_url"
value="cms_login_fail_redirect.html?v=${gs.getProperty('glide.builddate')}${AMP}sysparm_flush_messages=true${AMP}sysparm_goto_url=../${pageLink}%26sysparm_login_failed=true" />
<input type="hidden" name="sysparm_goto_url" value="${backtrack_path}cms_login_redirect.do?v=${gs.getProperty('glide.builddate')}${AMP}sysparm_goto_url=${pageLinkNotEncoded}" />
<input type="hidden" name="sysparm_flush_messages" value="true" />
<input type="hidden" name="sys_action" value="sysverb_login" />
<j:switch on="${gs.getProperty('glide.ui.forgetme')}">
<j:case value="true">
<j:set var="jvar_remember_me" value="false" />
</j:case>
<j:default>
<j:set var="jvar_remember_me" value="true" />
</j:default>
</j:switch>
<input type="hidden" id="remember_me" name="remember_me" value="${jvar_remember_me}" />
<span id="sign_in_block">
${gs.getMessage('User name')}:<input type="text" id="user_name" name="user_name"
value="" autocomplete="off" class="${jvar_login_highlight}"/>$[SP]$[SP]${gs.getMessage('Password')}:<input
type="password" id="user_password" name="user_password" class="${jvar_login_highlight}"/>
<button class="cms_header_login_button" type="submit"> ${gs.getMessage('Login')} </button>
</span>
</form>
<iframe name="login_iframe" src="blank.do" style="display:none" />
</j:if>
</div>
</j:jelly>

Author

With over a decade of experience, I have managed online marketing for a wide range of industries including biotech, high-tech, financial, higher education, non-profit, manufacturing, hardware providers, and startups. My specialty is helping business make the right turn with their online efforts focusing on lead generation and analytics.

Leave a Reply