NotesIn9: 049 XPages: Login and Logout

In this show I take a look at how to use the Login and Logout node of the Extension Libraries Application Layout Control. It should be noted that currently there’s a bug in the extension library where the logout piece doesn’t actually work. So I demonstrate how to get around that until it gets fixed.

Some code from the show:

Setting the “Can Logout” ability:
sessionScope.put(“extlib.user.canlogout”, true)

A link for the manual logout node:

href = facesContext.getExternalContext().getRequest().getContextPath() + “?Logout&redirectTo=” + facesContext.getExternalContext().getRequest().getContextPath()

Control rendering on the manual logout node:

var uName = session.getEffectiveUserName();
if(uName == “Anonymous”) {
return false;
}

else {
return true;
}

Play
  • Martin Meijer

    Thank you David, this helped me a lot. You posted it at the same time I was searching for this solution. What a timing!

  • David Leedy

    Very glad it was helpful to you Martin.

  • http://www.facebook.com/bruceelgort Bruce Elgort

    GREAT video David. You may want to fix this line:

    rendered = var uName = session.getEffectiveUserName();

    In this blog entry. It should be (for the rendered property):

    var uName = session.getEffectiveUserName();

  • David Leedy

     Thanks Bruce.  I correct the post.  I think I messed that up in the video as well.  doh!  :)

  • Boris Paukovic

    Great post! Helped me a lot!

  • Patrick Kwinten

    Used it today so thank you for the example!

  • http://notesin9.com David Leedy

    Cool. Glad it was helpful!

  • Andrew Mccann

    Hi

    I get a:

    JavaScript syntax error in property ‘href’: Lexical error at line 1, column 74. Encountered: “u201c” (8220), after : “”

    When I add the href to the manual logout node:

    href = facesContext.getExternalContext().getRequest().getContextPath() +
    “?Logout&redirectTo=” +
    facesContext.getExternalContext().getRequest().getContextPath()

    Any idea why?

    Many thanks

    Andrew

  • David Leedy

     I suspect the problem is the quotation marks.  They’re the “fancy version”.  either delete them and re add them manually or copy the code to a pure text editor like notepad – something that doesn’t allow rich text and then copy the code from there and paste back into your editor.

  • Andrew Mccann

     Excellent! Thanks so much, it is as you say the quotation marks! I used single quotes and all is now fine. This was also an issue for me in the (uName == “Anonymous”) part, which after changing to single quotes this worked too. I notice that in your demo video of this you use double quotes! No fair! So thanks again and it was the obscure error message that clouded my sight on this, loving your work and all the best!

  • David Leedy

    You can use double quotes… just type them into the editor directly.  don’t past in from a blog or word process that uses the fancy curly quotes.

    the key in that error message is “u201c”
    http://www.fileformat.info/info/unicode/char/201c/index.htm

    Notice the difference between that and this:
    http://www.fileformat.info/info/unicode/char/0022/index.htm

    Glad you like the show!  appreciate it!!

  • Andrew Mccann

     Thanks again! Really helpful and yes I should pay more attention to the error codes :-)

  • DonMottolo

    Tip:  since you’re using the Extension Library, the userBean is very convenient for getting the user’s credentials and returning the common name portion.  For example:      userBean.commonName != “Anonymous”