swish/commit
Add profile and notification infrastructure.
author | Jan Wielemaker |
---|---|
Sun May 14 13:49:52 2017 +0200 | |
committer | Jan Wielemaker |
Tue May 23 12:00:43 2017 +0200 | |
commit | c073ce2d51e03925e23770de5daf4afd51049e32 |
tree | 056550c2bde7e294f48c9828a353da0201e3ae28 |
parent | df00901d80227f7c54237fe555b7804b4f0e9140 |
Diff style: patch stat
diff --git a/Makefile b/Makefile index 5d1cff8..bd23146 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ FONTDIR=web/bower_components/bootstrap/dist/fonts PACKDIR=lib/swish/pack -PACKS=profile +PACKS=profile smtp DIRS=lib/swish lib/swish/render lib/swish/plugin $(PACKDIR) \ web/icons web/help client $(FONTDIR) \ web/bower_components/codemirror/mode/htmlmixed \ @@ -15,13 +15,14 @@ SWISHLIB=storage.pl page.pl help.pl examples.pl config.pl gitty.pl \ include.pl swish_csv.pl logging.pl trace.pl markdown.pl \ gitty_driver_files.pl gitty_driver_bdb.pl gitty_tools.pl \ swish_debug.pl profiles.pl procps.pl download.pl r_swish.pl \ - patch.pl chat.pl authenticate.pl pep.pl avatar.pl \ + patch.pl chat.pl authenticate.pl pep.pl avatar.pl bootstrap.pl \ noble_avatar.pl chatstore.pl paths.pl messages.pl \ rgb.txt RENDER=table.pl graphviz.pl c3.pl codes.pl swish.pl chess.pl sudoku.pl svgtree.pl -PLUGIN=email.pl +PLUGIN=email.pl profile.pl notify.pl login.pl PACKFILES0=profile/pack.pl profile/prolog/user_profile.pl \ - profile/prolog/profile/backend/profile_prolog.pl + profile/prolog/profile/backend/profile_prolog.pl \ + smtp/pack.pl smtp/prolog/smtp.pl PACKFILES=$(addprefix $(PACKDIR)/, $(PACKFILES0)) LIBS= $(addprefix lib/swish/, $(SWISHLIB)) \ $(addprefix lib/swish/render/, $(RENDER)) \ diff --git a/config-available/DEFAULTS b/config-available/DEFAULTS index 6113abb..6337a82 100644 --- a/config-available/DEFAULTS +++ b/config-available/DEFAULTS @@ -1 +1,3 @@ config(swish, link). +config(email, copy). +config(user_profile, link). diff --git a/config-available/email.pl b/config-available/email.pl new file mode 100644 index 0000000..b1c59dc --- /dev/null +++ b/config-available/email.pl @@ -0,0 +1,79 @@ +/* Part of SWISH + + Author: Jan Wielemaker + E-mail: J.Wielemaker@cs.vu.nl + WWW: http://www.swi-prolog.org + Copyright (C): 2014-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_email, + [ email_test/1 % +To + ]). +:- use_module(swish). +:- use_module(library(settings)). +:- use_module(library(debug)). +:- use_module((library(swish/plugin/email))). + +/** <module> Configure email + +This module configures the email client to send confirmation messages +and notifications. +*/ + +% EDIT: Configure email client. See library(smtp) for details. Next, run +% email_test(MyMailAddress) to verify that the setup is correct. Watch +% your spam box if Prolog reports no problems but you do not receive a +% message. +:- set_setting_default(smtp:host, '****'). +:- set_setting_default(smtp:port, ****). +:- set_setting_default(smtp:security, ****). +:- set_setting_default(smtp:from, '****'). +:- set_setting_default(smtp:user, '****'). +:- set_setting_default(smtp:password, "****"). +%:- set_setting_default(smtp:auth_method, default). +%:- set_setting_default(smtp:hostname, ''). + +%! email_test(+To) +% +% Test basic setup of the email client. + +email_test(To) :- + setup_call_cleanup( + debug(smtp), + smtp_send_mail(To, + send_message, + [ subject('SWISH email test'), + mailed_by(true) + ]), + nodebug(smtp)). + +send_message(Out) :- + format(Out, 'This is a test message from the swish email client.\n', []). + diff --git a/config-available/swish.pl b/config-available/swish.pl index 4837bbf..e67d72f 100644 --- a/config-available/swish.pl +++ b/config-available/swish.pl @@ -21,6 +21,10 @@ user:file_search_path(example, examples). % Load the authentication hook. When loaded, ClioPatria users with admin % rights can use SWISH without sandboxing security :- use_module(library(swish/cp_authenticate)). +% Enable user profile management +:- use_module(library(swish/plugin/profile)). +% Enable notifications +:- use_module(library(swish/plugin/notify)). % Enable logging of SWISH queries and sources if HTTP logging is enabled :- use_module(library(swish/logging)). % Make side-effect-free RDF predicates safe diff --git a/config-available/user_profile.pl b/config-available/user_profile.pl new file mode 100644 index 0000000..400bd2e --- /dev/null +++ b/config-available/user_profile.pl @@ -0,0 +1,108 @@ +/* Part of SWISH + + Author: Jan Wielemaker + E-mail: J.Wielemaker@cs.vu.nl + 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(swish). +:- use_module(library(settings)). +:- use_module(library(broadcast)). +:- use_module(library(user_profile)). +:- use_module(library(profile/backend/profile_prolog), []). + +:- use_module(library(swish/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), []). +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(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(_, _, _).