-include_lib ("nitrogen_core/include/wf.hrl").

main() -> #template { file="./templates/demos46.html" }.

title() -> "Security".

headline() -> "Security".

left() -> 
        Nitrogen has convenience methods for storing user information
        and roles. See <code>wf:user/N</code>, and <code>wf:role/N</code>.

        In addition, Nitrogen provides methods to validate that the
        user has access to a page, redirect to a login page, and then
        redirect back to the original page.

        In this demo, only authenticated users can access the
        restricted page. If you are currently an anonymous user, you
        will be prompted for a username and password.

right() -> 
    CurrentUser = case wf:user() of
        undefined -> "(Anonymous)";
        Other -> Other
        #span { text="Current User: " },
        #span { style="font-weight: bold;", text=CurrentUser }, 
        #link { show_if=(wf:user() /= undefined), text="Logout", postback=logout },
        #link { text="Access a Restricted Page", url="/demos/security/restricted" }

event(logout) ->