1/*  Part of SWISH
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2017, VU University Amsterdam
    7			 CWI Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(config_user_profile, []).   37:- use_module(library(settings)).   38:- use_module(library(broadcast)).   39:- use_module(library(user_profile)).   40:- use_module(library(profile/backend/profile_prolog), []).   41
   42:- use_module(swish(lib/plugin/profile)).   43
   44:- set_setting(user_profile:backend, impl_profile_prolog).   45:- initialization profile_open_db([]).

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

*/

   61:- multifile
   62    user_profile:attribute/3,
   63    user_profile:attribute_mapping/3.
 user_profile:attribute(?Name, ?Type, ?Options) is nondet
Declare profile properties.
   70user_profile:attribute(name,                string,           []).
   71user_profile:attribute(given_name,          string,           []).
   72user_profile:attribute(family_name,         string,           []).
   73user_profile:attribute(nick_name,           string,           []).
   74user_profile:attribute(email,               email,            []).
   75user_profile:attribute(email_verified,      boolean,          [access(ro)]).
   76user_profile:attribute(email_notifications, oneof([immediate,daily,never]),
   77                                                           [default(immediate)]).
   78user_profile:attribute(avatar,              url(http),        []).
   79user_profile:attribute(home_page,           url(http),        []).
   80user_profile:attribute(last_login,          time_stamp('%+'), [access(ro)]).
   81user_profile:attribute(last_peer,           string,           [access(ro)]).
   82user_profile:attribute(identity_provider,   atom,             [access(ro)]).
   83user_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.
   91user_profile:attribute_mapping(external_identity, _,     sub).
   92user_profile:attribute_mapping(avatar,            _,     picture).
   93user_profile:attribute_mapping(nick_name,         local, user).
   94user_profile:attribute_mapping(external_identity, local, user).
   95user_profile:attribute_mapping(Attr,              _,     Attr).
   96
   97		 /*******************************
   98		 *         DEPENDENCIES		*
   99		 *******************************/
  100
  101:- listen(user_profile(modified(User, Name, _Old, New)),
  102          propagate_profile_change(User, Name, New)).  103
  104propagate_profile_change(User, email, _) :-
  105    !,
  106    set_profile(User, email_verified=false).
  107propagate_profile_change(_, _, _)