Login Dialog

<xp:this.resources>
	<xp:dojoModule name="dijit.Dialog"></xp:dojoModule>
</xp:this.resources>

<xp:link escape="true" id="banner_btn_login"
	styleClass="loginLink" text="Anmelden">
	<xp:this.rendered>
		<![CDATA[#{javascript:
			var strLoginURL:String;
			var strLogoutURL:String;
			var contextPath = facesContext.getExternalContext().getRequest().getContextPath();
			var requestURI = facesContext.getExternalContext().getRequest().getRequestURI();

			strLoginURL = contextPath + "?login&redirectto=" + requestURI;
			strLogoutURL = contextPath + "?logout&redirectto=" + contextPath;
			return (@UserName() == "Anonymous")?true:false;}]]>
	</xp:this.rendered>
	<xp:eventHandler event="onclick"
		submit="false">
		<xp:this.script><![CDATA[javascript:dijit.byId("#{id:showLoginDialog}").show();]]></xp:this.script>
	</xp:eventHandler>
</xp:link>
<xp:link escape="true" id="banner_btn_logout" styleClass="loginLink"
	value="#{javascript:return strLogoutURL}" text="Abmelden">
	<xp:this.rendered>
		<![CDATA[#{javascript:
			return (@UserName() == "Anonymous")?false:true;}]]>
	</xp:this.rendered>
</xp:link>

<xp:div dojoType="dijit.Dialog" id="showLoginDialog"
	style="overflow:auto;" title="Anmelden">
	<xp:this.dojoAttributes>
		<xp:dojoAttribute name="href"
			value="#{javascript:strLoginURL}" />
	</xp:this.dojoAttributes>
</xp:div>





Simply embedd this code somewhere in your XPage to have your login screen put into a dojo dialog.
I always put it into a link list on top of the screen like in OneUI or in a menu or something.

For anonymous users, the login link will be displayed and for any authorized user the logout link will be displayed.
Looks a bit more beautiful and more modern than a new screen with the login mask showing up. Of course this is only helpful if the application allows unauthorized users to open at least the start page.

I recommend using a customized login mask, defined in domcfg.nsf, in this dialog.

http://mnicklisch.wordpress.com/2012/04/18/xsnippet-easy-menu-login-dialog/

XPages
Matthias Nicklisch
April 18, 2012 4:18 PM
Rating
689

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...