From 4aeedb5a2ea455c503721de29a35e8a3c1fa0a9d Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 31 Dec 2015 19:59:08 +0100 Subject: feature #392, authentication keys, album notification * On album notification (for a group), sends one distinct email for each user with a new authentication key. * When someone clicks the link with auth= in URL, if the user is not already connected, Piwigo will automatically connect the user. --- include/functions_mail.inc.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'include/functions_mail.inc.php') diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index ed1081713..529f2da0d 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -514,6 +514,8 @@ SELECT DISTINCT language // get subset of users in this group for a specific language $query = ' SELECT + ui.user_id, + ui.status, u.'.$conf['user_fields']['username'].' AS name, u.'.$conf['user_fields']['email'].' AS email FROM '.USER_GROUP_TABLE.' AS ug @@ -534,13 +536,27 @@ SELECT switch_lang_to($language); - $return&= pwg_mail(null, - array_merge( - $args, - array('Bcc' => $users) - ), - $tpl - ); + foreach ($users as $u) + { + $authkey = create_user_auth_key($u['user_id'], $u['status']); + + $user_tpl = $tpl; + + if ($authkey !== false) + { + $user_tpl['assign']['LINK'] = add_url_params($tpl['assign']['LINK'], array('auth' => $authkey['auth_key'])); + + if (isset($user_tpl['assign']['IMG']['link'])) + { + $user_tpl['assign']['IMG']['link'] = add_url_params( + $user_tpl['assign']['IMG']['link'], + array('auth' => $authkey['auth_key']) + ); + } + } + + $return &= pwg_mail($u['email'], $args, $user_tpl); + } switch_lang_back(); } -- cgit v1.2.3 From 67e142f33197af955e179a1ad09b990ac80b6698 Mon Sep 17 00:00:00 2001 From: plegall Date: Mon, 4 Jan 2016 19:54:40 +0100 Subject: feature #392, add authentication key in NBM mails There are many links in NBM (Notification By Mail, see screen [Administration > Users > Notification]). I had to change several functions to take this authentication key into account. --- include/functions_mail.inc.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/functions_mail.inc.php') diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index 529f2da0d..01a65091b 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -579,6 +579,7 @@ SELECT * o theme: theme to use [default value $conf_mail['mail_theme']] * o mail_title: main title of the mail [default value $conf['gallery_title']] * o mail_subtitle: subtitle of the mail [default value subject] + * o auth_key: authentication key to add on footer link [default value null] * @param array $tpl - use these options to define a custom content template file * o filename * o dirname (optional) @@ -725,9 +726,15 @@ function pwg_mail($to, $args=array(), $tpl=array()) $template->set_filename('mail_header', 'header.tpl'); $template->set_filename('mail_footer', 'footer.tpl'); + $add_url_params = array(); + if (!empty($args['auth_key'])) + { + $add_url_params['auth'] = $args['auth_key']; + } + $template->assign( array( - 'GALLERY_URL' => get_gallery_home_url(), + 'GALLERY_URL' => add_url_params(get_gallery_home_url(), $add_url_params), 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '', -- cgit v1.2.3 From c42f15dfa816912a1b09ec2a71e5ed0b39ff0d86 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 6 Jan 2016 14:29:32 +0100 Subject: add auth_key in mail footer for pwg_mail_group --- include/functions_mail.inc.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include/functions_mail.inc.php') diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index 01a65091b..cf982bcf3 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -555,7 +555,13 @@ SELECT } } - $return &= pwg_mail($u['email'], $args, $user_tpl); + $user_args = $args; + if ($authkey !== false) + { + $user_args['auth_key'] = $authkey['auth_key']; + } + + $return &= pwg_mail($u['email'], $user_args, $user_tpl); } switch_lang_back(); -- cgit v1.2.3 From 426e10e235689211fc52ee0077dce32ea3124bd6 Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 6 Jan 2016 14:30:05 +0100 Subject: feature #392, bug fixed on footer link Use auth_key in mail cache key to avoid using the auth key of the first user. --- include/functions_mail.inc.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/functions_mail.inc.php') diff --git a/include/functions_mail.inc.php b/include/functions_mail.inc.php index cf982bcf3..67be16c15 100644 --- a/include/functions_mail.inc.php +++ b/include/functions_mail.inc.php @@ -718,6 +718,10 @@ function pwg_mail($to, $args=array(), $tpl=array()) { // key compose of indexes witch allow to cache mail data $cache_key = $content_type.'-'.$lang_info['code']; + if (!empty($args['auth_key'])) + { + $cache_key.= '-'.$args['auth_key']; + } if (!isset($conf_mail[$cache_key])) { -- cgit v1.2.3