Issue 12097: Notify for each new user registration

This commit is contained in:
Michael 2022-11-03 19:59:33 +00:00
parent 12a352f441
commit 0f9e2b6da4
6 changed files with 317 additions and 248 deletions

View File

@ -98,6 +98,7 @@ class Site extends BaseAdmin
$enable_multi_reg = !empty($_POST['enable_multi_reg']); $enable_multi_reg = !empty($_POST['enable_multi_reg']);
$enable_openid = !empty($_POST['enable_openid']); $enable_openid = !empty($_POST['enable_openid']);
$enable_regfullname = !empty($_POST['enable_regfullname']); $enable_regfullname = !empty($_POST['enable_regfullname']);
$register_notification = !empty($_POST['register_notification']);
$community_page_style = (!empty($_POST['community_page_style']) ? intval(trim($_POST['community_page_style'])) : 0); $community_page_style = (!empty($_POST['community_page_style']) ? intval(trim($_POST['community_page_style'])) : 0);
$max_author_posts_community_page = (!empty($_POST['max_author_posts_community_page']) ? intval(trim($_POST['max_author_posts_community_page'])) : 0); $max_author_posts_community_page = (!empty($_POST['max_author_posts_community_page']) ? intval(trim($_POST['max_author_posts_community_page'])) : 0);
@ -266,6 +267,7 @@ class Site extends BaseAdmin
DI::config()->set('system', 'block_extended_register', !$enable_multi_reg); DI::config()->set('system', 'block_extended_register', !$enable_multi_reg);
DI::config()->set('system', 'no_openid' , !$enable_openid); DI::config()->set('system', 'no_openid' , !$enable_openid);
DI::config()->set('system', 'no_regfullname' , !$enable_regfullname); DI::config()->set('system', 'no_regfullname' , !$enable_regfullname);
DI::config()->set('system', 'register_notification' , $register_notification);
DI::config()->set('system', 'community_page_style' , $community_page_style); DI::config()->set('system', 'community_page_style' , $community_page_style);
DI::config()->set('system', 'max_author_posts_community_page', $max_author_posts_community_page); DI::config()->set('system', 'max_author_posts_community_page', $max_author_posts_community_page);
DI::config()->set('system', 'verifyssl' , $verifyssl); DI::config()->set('system', 'verifyssl' , $verifyssl);
@ -492,6 +494,7 @@ class Site extends BaseAdmin
'$enable_multi_reg' => ['enable_multi_reg', DI::l10n()->t('Enable multiple registrations'), !DI::config()->get('system', 'block_extended_register'), DI::l10n()->t('Enable users to register additional accounts for use as pages.')], '$enable_multi_reg' => ['enable_multi_reg', DI::l10n()->t('Enable multiple registrations'), !DI::config()->get('system', 'block_extended_register'), DI::l10n()->t('Enable users to register additional accounts for use as pages.')],
'$enable_openid' => ['enable_openid', DI::l10n()->t('Enable OpenID'), !DI::config()->get('system', 'no_openid'), DI::l10n()->t('Enable OpenID support for registration and logins.')], '$enable_openid' => ['enable_openid', DI::l10n()->t('Enable OpenID'), !DI::config()->get('system', 'no_openid'), DI::l10n()->t('Enable OpenID support for registration and logins.')],
'$enable_regfullname' => ['enable_regfullname', DI::l10n()->t('Enable Fullname check'), !DI::config()->get('system', 'no_regfullname'), DI::l10n()->t('Enable check to only allow users to register with a space between the first name and the last name in their full name.')], '$enable_regfullname' => ['enable_regfullname', DI::l10n()->t('Enable Fullname check'), !DI::config()->get('system', 'no_regfullname'), DI::l10n()->t('Enable check to only allow users to register with a space between the first name and the last name in their full name.')],
'$register_notification' => ['register_notification', DI::l10n()->t('Notify admin on new registration'), DI::config()->get('system', 'register_notification'), DI::l10n()->t('If enabled and the system is set to an open registration, a notification for each new registration is sent to the admin.')],
'$community_page_style' => ['community_page_style', DI::l10n()->t('Community pages for visitors'), DI::config()->get('system', 'community_page_style'), DI::l10n()->t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices], '$community_page_style' => ['community_page_style', DI::l10n()->t('Community pages for visitors'), DI::config()->get('system', 'community_page_style'), DI::l10n()->t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices],
'$max_author_posts_community_page' => ['max_author_posts_community_page', DI::l10n()->t('Posts per user on community page'), DI::config()->get('system', 'max_author_posts_community_page'), DI::l10n()->t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')], '$max_author_posts_community_page' => ['max_author_posts_community_page', DI::l10n()->t('Posts per user on community page'), DI::config()->get('system', 'max_author_posts_community_page'), DI::l10n()->t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')],
'$mail_able' => function_exists('imap_open'), '$mail_able' => function_exists('imap_open'),

View File

@ -333,6 +333,10 @@ class Register extends BaseModule
if ($res) { if ($res) {
DI::sysmsg()->addInfo(DI::l10n()->t('Registration successful. Please check your email for further instructions.')); DI::sysmsg()->addInfo(DI::l10n()->t('Registration successful. Please check your email for further instructions.'));
$this->sendNotification($user, 'SYSTEM_REGISTER_NEW');
if (DI::config()->get('system', 'register_notification')) {
$this->sendNotification($user, 'SYSTEM_REGISTER_NEW');
}
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} else { } else {
DI::sysmsg()->addNotice( DI::sysmsg()->addNotice(
@ -343,6 +347,9 @@ class Register extends BaseModule
} }
} else { } else {
DI::sysmsg()->addInfo(DI::l10n()->t('Registration successful.')); DI::sysmsg()->addInfo(DI::l10n()->t('Registration successful.'));
if (DI::config()->get('system', 'register_notification')) {
$this->sendNotification($user, 'SYSTEM_REGISTER_NEW');
}
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }
} elseif (intval(DI::config()->get('config', 'register_policy')) === self::APPROVE) { } elseif (intval(DI::config()->get('config', 'register_policy')) === self::APPROVE) {
@ -367,29 +374,8 @@ class Register extends BaseModule
DI::pConfig()->set($user['uid'], 'system', 'invites_remaining', $num_invites); DI::pConfig()->set($user['uid'], 'system', 'invites_remaining', $num_invites);
} }
// send email to admins // send notification to the admin
$admins_stmt = DBA::select( $this->sendNotification($user, 'SYSTEM_REGISTER_REQUEST');
'user',
['uid', 'language', 'email'],
['email' => explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')))]
);
// send notification to admins
while ($admin = DBA::fetch($admins_stmt)) {
DI::notify()->createFromArray([
'type' => Model\Notification\Type::SYSTEM,
'event' => 'SYSTEM_REGISTER_REQUEST',
'uid' => $admin['uid'],
'link' => DI::baseUrl()->get(true) . '/admin/users/',
'source_name' => $user['username'],
'source_mail' => $user['email'],
'source_nick' => $user['nickname'],
'source_link' => DI::baseUrl()->get(true) . '/admin/users/',
'source_photo' => User::getAvatarUrl($user, Proxy::SIZE_THUMB),
'show_in_notification_page' => false
]);
}
DBA::close($admins_stmt);
// send notification to the user, that the registration is pending // send notification to the user, that the registration is pending
Model\User::sendRegisterPendingEmail( Model\User::sendRegisterPendingEmail(
@ -405,4 +391,31 @@ class Register extends BaseModule
return; return;
} }
private function sendNotification(array $user, string $event)
{
// send email to admins
$admins_stmt = DBA::select(
'user',
['uid', 'language', 'email'],
['email' => explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')))]
);
// send notification to admins
while ($admin = DBA::fetch($admins_stmt)) {
DI::notify()->createFromArray([
'type' => Model\Notification\Type::SYSTEM,
'event' => $event,
'uid' => $admin['uid'],
'link' => DI::baseUrl()->get(true) . '/admin/users/',
'source_name' => $user['username'],
'source_mail' => $user['email'],
'source_nick' => $user['nickname'],
'source_link' => DI::baseUrl()->get(true) . '/admin/users/',
'source_photo' => User::getAvatarUrl($user, Proxy::SIZE_THUMB),
'show_in_notification_page' => false
]);
}
DBA::close($admins_stmt);
}
} }

View File

@ -483,6 +483,27 @@ class Notify extends BaseRepository
$hsitelink = sprintf($sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>'); $hsitelink = sprintf($sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>');
break; break;
case 'SYSTEM_REGISTER_NEW':
$itemlink = $params['link'];
$subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('new registration');
$preamble = $l10n->t('You\'ve received a new registration from \'%1$s\' at %2$s', $params['source_name'], $sitename);
$epreamble = $l10n->t('You\'ve received a [url=%1$s]new registration[/url] from %2$s.',
$itemlink,
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]'
);
$body = $l10n->t("Full Name: %s\nSite Location: %s\nLogin Name: %s (%s)",
$params['source_name'],
$siteurl, $params['source_mail'],
$params['source_nick']
);
$sitelink = $l10n->t('Please visit %s to have a look at the new registration.');
$tsitelink = sprintf($sitelink, $params['link']);
$hsitelink = sprintf($sitelink, '<a href="' . $params['link'] . '">' . $sitename . '</a><br><br>');
break;
case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here) case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here)
break; break;
} }

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@
{{include file="field_checkbox.tpl" field=$enable_multi_reg}} {{include file="field_checkbox.tpl" field=$enable_multi_reg}}
{{include file="field_checkbox.tpl" field=$enable_openid}} {{include file="field_checkbox.tpl" field=$enable_openid}}
{{include file="field_checkbox.tpl" field=$enable_regfullname}} {{include file="field_checkbox.tpl" field=$enable_regfullname}}
{{include file="field_checkbox.tpl" field=$register_notification}}
<div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div> <div class="submit"><input type="submit" name="page_site" value="{{$submit}}"/></div>
<h2>{{$upload}}</h2> <h2>{{$upload}}</h2>

View File

@ -77,6 +77,7 @@
{{include file="field_checkbox.tpl" field=$enable_multi_reg}} {{include file="field_checkbox.tpl" field=$enable_multi_reg}}
{{include file="field_checkbox.tpl" field=$enable_openid}} {{include file="field_checkbox.tpl" field=$enable_openid}}
{{include file="field_checkbox.tpl" field=$enable_regfullname}} {{include file="field_checkbox.tpl" field=$enable_regfullname}}
{{include file="field_checkbox.tpl" field=$register_notification}}
</div> </div>
<div class="panel-footer"> <div class="panel-footer">
<input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/> <input type="submit" name="page_site" class="btn btn-primary" value="{{$submit}}"/>