View source with formatted comments or as raw
    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(swish).   38:- use_module(library(settings)).   39:- use_module(library(broadcast)).   40:- use_module(library(user_profile)).   41:- use_module(library(profile/backend/profile_prolog), []).   42
   43:- use_module(library(swish/plugin/profile)).   44
   45:- set_setting(user_profile:backend, impl_profile_prolog).   46:- initialization profile_open_db([]).   47
   48/** <module> User profile configuration
   49
   50Configure  maintenance  of  user  profiles.  This  config  file  may  be
   51optionally enabled if one  or   more,  notably federated, authentication
   52modules are loaded. It maintains a database of identified users.
   53
   54The user profile infra structure depends on the pack _profile_, which is
   55linked to SWISH as a git submodule.  To use profiles, run
   56
   57    ```
   58    git submodule update --init pack/profile
   59    ```
   60*/
   61
   62:- multifile
   63    user_profile:attribute/3,
   64    user_profile:attribute_mapping/3.   65
   66
   67%!  user_profile:attribute(?Name, ?Type, ?Options) is nondet.
   68%
   69%   Declare profile properties.
   70
   71user_profile:attribute(name,                string,           []).
   72user_profile:attribute(given_name,          string,           []).
   73user_profile:attribute(family_name,         string,           []).
   74user_profile:attribute(nick_name,           string,           []).
   75user_profile:attribute(email,               email,            []).
   76user_profile:attribute(email_verified,      boolean,          [access(ro)]).
   77user_profile:attribute(email_notifications, oneof([immediate,daily,never]),
   78                                                           [default(immediate)]).
   79user_profile:attribute(avatar,              url(http),        []).
   80user_profile:attribute(home_page,           url(http),        []).
   81user_profile:attribute(last_login,          time_stamp('%+'), [access(ro)]).
   82user_profile:attribute(last_peer,           string,           [access(ro)]).
   83user_profile:attribute(identity_provider,   atom,             [access(ro)]).
   84user_profile:attribute(external_identity,   string,           [hidden(true)]).
   85
   86%!  user_profile:attribute_mapping(+ProfileAttr, +IDProvider, -IDProviderAttr)
   87%
   88%   Provide a mapping from profile attributed (e.g., oauth2 _scopes_) to
   89%   our profile attributes. This is  used   to  fill the initial profile
   90%   after a user was identified by IDProvider.
   91
   92user_profile:attribute_mapping(external_identity, _,     sub).
   93user_profile:attribute_mapping(avatar,            _,     picture).
   94user_profile:attribute_mapping(nick_name,         local, user).
   95user_profile:attribute_mapping(external_identity, local, user).
   96user_profile:attribute_mapping(Attr,              _,     Attr).
   97
   98		 /*******************************
   99		 *         DEPENDENCIES		*
  100		 *******************************/
  101
  102:- listen(user_profile(modified(User, Name, _Old, New)),
  103          propagate_profile_change(User, Name, New)).  104
  105propagate_profile_change(User, email, _) :-
  106    !,
  107    set_profile(User, email_verified=false).
  108propagate_profile_change(_, _, _)