forked from SWI-Prolog/swish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_profile.pl
108 lines (87 loc) · 4.49 KB
/
user_profile.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Part of SWISH
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (C): 2017, VU University Amsterdam
CWI Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module(config_user_profile, []).
:- use_module(library(settings)).
:- use_module(library(broadcast)).
:- use_module(library(user_profile)).
:- use_module(library(profile/backend/profile_prolog), []).
:- use_module(swish(lib/plugin/profile)).
:- set_setting(user_profile:backend, impl_profile_prolog).
:- initialization profile_open_db([]).
/** <module> User profile configuration
Configure maintenance of user profiles. This config file may be
optionally enabled if one or more, notably federated, authentication
modules are loaded. It maintains a database of identified users.
The user profile infra structure depends on the pack _profile_, which is
linked to SWISH as a git submodule. To use profiles, run
```
git submodule update --init pack/profile
```
*/
:- multifile
user_profile:attribute/3,
user_profile:attribute_mapping/3.
%! user_profile:attribute(?Name, ?Type, ?Options) is nondet.
%
% Declare profile properties.
user_profile:attribute(name, string, []).
user_profile:attribute(given_name, string, []).
user_profile:attribute(family_name, string, []).
user_profile:attribute(nick_name, string, []).
user_profile:attribute(email, email, []).
user_profile:attribute(email_verified, boolean, [access(ro)]).
user_profile:attribute(email_notifications, oneof([immediate,daily,never]),
[default(immediate)]).
user_profile:attribute(avatar, url(http), [hidden(true)]).
user_profile:attribute(home_page, url(http), []).
user_profile:attribute(last_login, time_stamp('%+'), [access(ro)]).
user_profile:attribute(last_peer, string, [access(ro)]).
user_profile:attribute(identity_provider, atom, [access(ro)]).
user_profile:attribute(external_identity, string, [hidden(true)]).
%! user_profile:attribute_mapping(+ProfileAttr, +IDProvider, -IDProviderAttr)
%
% Provide a mapping from profile attributed (e.g., oauth2 _scopes_) to
% our profile attributes. This is used to fill the initial profile
% after a user was identified by IDProvider.
user_profile:attribute_mapping(external_identity, _, sub).
user_profile:attribute_mapping(external_identity, _, user_id). % Stack Exchange
user_profile:attribute_mapping(avatar, _, picture).
user_profile:attribute_mapping(nick_name, local, user).
user_profile:attribute_mapping(external_identity, local, user).
user_profile:attribute_mapping(Attr, _, Attr).
/*******************************
* DEPENDENCIES *
*******************************/
:- listen(user_profile(modified(User, Name, _Old, New)),
propagate_profile_change(User, Name, New)).
propagate_profile_change(User, email, _) :-
!,
set_profile(User, email_verified=false).
propagate_profile_change(_, _, _).