1:- module(identity, [
    2	  logged_in_as//3,
    3	  logout_uri/2,
    4	  login_uri/2
    5	  ]).

non-visual predicates for managing identity

Use this module in preference to directly calling the provider identity management

*/

   13:- use_module(weblog(identity/stormpath/stormpath)).   14:- use_module(library(http/http_dispatch)).   15
   16logged_in_as(Generator, Name, Role) -->
   17	{
   18	    logged_in_as(Generator, Name, Role)
   19        },
   20	[].
   21
   22logged_in_as(Generator, Name, Role) :-
   23        call(Generator, provider(stormpath)),
   24	stormpath:logged_in_as(Generator, Name, Role).
   25
   26default_login_uri('/login').
   27default_logout_uri('/logout').
   28
   29login_uri(Generator, URI) :-
   30       call(Generator, login_uri(URI)),
   31       ensure_handler_exists(login, URI).
   32login_uri(_, URI) :-
   33	default_login_uri(URI),
   34	ensure_handler_exists(login, URI).
   35
   36logout_uri(Generator, URI) :-
   37       call(Generator, logout_uri(URI)),
   38       ensure_handler_exists(logout, URI).
   39logout_uri(_, URI) :-
   40	default_logout_uri(URI),
   41	ensure_handler_exists(logout, URI).
   42
   43
   44ensure_handler_exists(login, _) :- !.
   45ensure_handler_exists(login, URI) :-
   46	http_handler(URI, login_handler , []).
   47
   48login_handler(Request) :-
   49	reply_html_page(weblog_login,
   50			title('Log in'),
   51			\login_form
   52		       )