30
31:- module(cp_swish_authenticate,
32 [
33 ]). 34:- use_module(library(pengines), []). 35:- use_module(library(broadcast)). 36:- use_module(user(user_db)).
55:- multifile
56 swish_config:reply_logged_in/1,
57 swish_config:reply_logged_out/1,
58 swish_config:authenticate/2,
59 swish_config:user_info/3. 60
61swish_config:authenticate(_Request, User) :-
62 logged_on(User).
63
64swish_config:user_info(_Request, local, Info) :-
65 logged_on(User),
66 cp_user_info(User, Info).
67
68cp_user_info(User, Info) :-
69 findall(Name-Value, cp_user_property(User, Name, Value), Pairs),
70 dict_pairs(Info, u, Pairs).
71
72cp_user_property(User, user, User).
73cp_user_property(User, name, RealName) :-
74 user_property(User, realname(RealName)).
75cp_user_property(User, email, Email) :-
76 user_property(User, email(Email)).
77cp_user_property(User, group, Group) :-
78 user_property(User, allow(Allow)),
79 ( memberchk(admin(_), Allow)
80 -> Group = admin
81 ; memberchk(write(_,_), Allow)
82 -> Group = writer
83 ; Group = reader
84 ).
85
86:- listen(identity_property(Identity, Property),
87 cp_identity_property(Identity, Property)). 88
89cp_identity_property(Identity, Property) :-
90 _{user:User, identity_provider:local} :< Identity,
91 Property =.. [Name,Value],
92 cp_user_property(User, Name, Value).
93
94
95 98
99:- listen(cliopatria(login(User, _Session)),
100 cp_logged_in(User)). 101:- listen(cliopatria(logout(User)),
102 cp_logged_out(User)). 103
104cp_logged_in(User) :-
105 cp_user_info(User, Info),
106 IdInfo = Info.put(_{identity_provider:local, external_identity:User}),
107 swish_config:reply_logged_in([user_info(IdInfo), reply(none)]).
108
109cp_logged_out(_User) :-
110 swish_config:reply_logged_out([reply(none)])
SWISH login management
This module provides basic login and password management facilities for SWISH. You can create an authenticated SWISH server by
As a result, trying to create the first pengine (e.g., using Run!), the server will challenge the user. The logged in user is available through pengine_user/1. */