mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Expand notifications.
This commit is contained in:
@@ -33,15 +33,16 @@ use FireflyIII\Events\RequestedNewPassword;
|
|||||||
use FireflyIII\Events\UserChangedEmail;
|
use FireflyIII\Events\UserChangedEmail;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Mail\ConfirmEmailChangeMail;
|
use FireflyIII\Mail\ConfirmEmailChangeMail;
|
||||||
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
|
|
||||||
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
|
|
||||||
use FireflyIII\Mail\UndoEmailChangeMail;
|
use FireflyIII\Mail\UndoEmailChangeMail;
|
||||||
use FireflyIII\Models\GroupMembership;
|
use FireflyIII\Models\GroupMembership;
|
||||||
use FireflyIII\Models\UserGroup;
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\Models\UserRole;
|
use FireflyIII\Models\UserRole;
|
||||||
|
use FireflyIII\Notifications\Admin\UserRegistration as AdminRegistrationNotification;
|
||||||
use FireflyIII\Notifications\User\UserLogin;
|
use FireflyIII\Notifications\User\UserLogin;
|
||||||
use FireflyIII\Notifications\User\UserNewPassword;
|
use FireflyIII\Notifications\User\UserNewPassword;
|
||||||
|
use FireflyIII\Notifications\User\UserRegistration as UserRegistrationNotification;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\FireflyConfig;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Auth\Events\Login;
|
use Illuminate\Auth\Events\Login;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
@@ -281,26 +282,28 @@ class UserEventHandler
|
|||||||
*/
|
*/
|
||||||
public function sendRegistrationMail(RegisteredUser $event): void
|
public function sendRegistrationMail(RegisteredUser $event): void
|
||||||
{
|
{
|
||||||
$sendMail = config('firefly.send_registration_mail');
|
$sendMail = FireflyConfig::get('notification_user_new_reg', true)->data;
|
||||||
if ($sendMail) {
|
if ($sendMail) {
|
||||||
// get the email address
|
Notification::send($event->user, new UserRegistrationNotification);
|
||||||
$email = $event->user->email;
|
}
|
||||||
$url = route('index');
|
|
||||||
|
|
||||||
// see if user has alternative email address:
|
|
||||||
$pref = app('preferences')->getForUser($event->user, 'remote_guard_alt_email');
|
|
||||||
if (null !== $pref) {
|
|
||||||
$email = $pref->data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// send email.
|
/**
|
||||||
try {
|
* @param RegisteredUser $event
|
||||||
Mail::to($email)->send(new RegisteredUserMail($url));
|
* @return void
|
||||||
|
*/
|
||||||
} catch (Exception $e) { // @phpstan-ignore-line
|
public function sendAdminRegistrationNotification(RegisteredUser $event): void
|
||||||
Log::error($e->getMessage());
|
{
|
||||||
|
$sendMail = FireflyConfig::get('notification_admin_new_reg', true)->data;
|
||||||
|
if ($sendMail) {
|
||||||
|
/** @var UserRepositoryInterface $repository */
|
||||||
|
$repository = app(UserRepositoryInterface::class);
|
||||||
|
$all = $repository->all();
|
||||||
|
foreach ($all as $user) {
|
||||||
|
if ($repository->hasRole($user, 'owner')) {
|
||||||
|
Notification::send($user, new AdminRegistrationNotification($event->user));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ use FireflyIII\Events\AdminRequestedTestMessage;
|
|||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||||
|
use FireflyIII\Support\Facades\FireflyConfig;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
@@ -68,9 +69,28 @@ class HomeController extends Controller
|
|||||||
if (null !== $pref && is_string($pref->data)) {
|
if (null !== $pref && is_string($pref->data)) {
|
||||||
$email = $pref->data;
|
$email = $pref->data;
|
||||||
}
|
}
|
||||||
Log::debug('Email is ', [$email]);
|
|
||||||
|
|
||||||
return view('admin.index', compact('title', 'mainTitleIcon', 'email'));
|
// admin notification settings:
|
||||||
|
$notifications = [];
|
||||||
|
foreach (config('firefly.admin_notifications') as $item) {
|
||||||
|
$notifications[$item] = FireflyConfig::get(sprintf('notification_%s', $item), true)->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notifications(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
foreach (config('firefly.admin_notifications') as $item) {
|
||||||
|
$value = false;
|
||||||
|
if ($request->has(sprintf('notification_%s', $item))) {
|
||||||
|
$value = true;
|
||||||
|
}
|
||||||
|
FireflyConfig::set(sprintf('notification_%s',$item), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
session()->flash('success', (string) trans('firefly.notification_settings_saved'));
|
||||||
|
return redirect(route('admin.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -22,7 +22,61 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Notifications\Admin;
|
namespace FireflyIII\Notifications\Admin;
|
||||||
|
|
||||||
class UserRegistration
|
use FireflyIII\User;
|
||||||
{
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class UserRegistration extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
private User $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id])
|
||||||
|
->subject((string) trans('email.registered_subject_admin'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
79
app/Notifications/User/UserRegistration.php
Normal file
79
app/Notifications/User/UserRegistration.php
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
/*
|
||||||
|
* UserRegistration.php
|
||||||
|
* Copyright (c) 2022 james@firefly-iii.org
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FireflyIII\Notifications\User;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
|
||||||
|
class UserRegistration extends Notification
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable)
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail($notifiable)
|
||||||
|
{
|
||||||
|
return (new MailMessage)
|
||||||
|
->markdown('emails.registered', ['address' => route('index')])
|
||||||
|
->subject((string) trans('email.registered_subject'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -73,6 +73,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
// is a User related event.
|
// is a User related event.
|
||||||
RegisteredUser::class => [
|
RegisteredUser::class => [
|
||||||
'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail',
|
'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationMail',
|
||||||
|
'FireflyIII\Handlers\Events\UserEventHandler@sendAdminRegistrationNotification',
|
||||||
'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole',
|
'FireflyIII\Handlers\Events\UserEventHandler@attachUserRole',
|
||||||
'FireflyIII\Handlers\Events\UserEventHandler@createGroupMembership',
|
'FireflyIII\Handlers\Events\UserEventHandler@createGroupMembership',
|
||||||
'FireflyIII\Handlers\Events\UserEventHandler@createExchangeRates',
|
'FireflyIII\Handlers\Events\UserEventHandler@createExchangeRates',
|
||||||
|
@@ -146,6 +146,7 @@ return [
|
|||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'],
|
'available_notifications' => ['bill_reminder', 'new_access_token', 'transaction_creation', 'user_login'],
|
||||||
|
'admin_notifications' => ['admin_new_reg', 'user_new_reg'],
|
||||||
|
|
||||||
// enabled languages
|
// enabled languages
|
||||||
'languages' => [
|
'languages' => [
|
||||||
|
@@ -49,6 +49,8 @@ return [
|
|||||||
|
|
||||||
// registered
|
// registered
|
||||||
'registered_subject' => 'Welcome to Firefly III!',
|
'registered_subject' => 'Welcome to Firefly III!',
|
||||||
|
'registered_subject_admin' => 'A new user has registered',
|
||||||
|
'admin_new_user_registered' => 'A new user has registered. User **:email** was given user ID #:id.',
|
||||||
'registered_welcome' => 'Welcome to [Firefly III](:address). Your registration has made it, and this email is here to confirm it. Yay!',
|
'registered_welcome' => 'Welcome to [Firefly III](:address). Your registration has made it, and this email is here to confirm it. Yay!',
|
||||||
'registered_pw' => 'If you have forgotten your password already, please reset it using [the password reset tool](:address/password/reset).',
|
'registered_pw' => 'If you have forgotten your password already, please reset it using [the password reset tool](:address/password/reset).',
|
||||||
'registered_help' => 'There is a help-icon in the top right corner of each page. If you need help, click it!',
|
'registered_help' => 'There is a help-icon in the top right corner of each page. If you need help, click it!',
|
||||||
|
@@ -1985,6 +1985,13 @@ return [
|
|||||||
'admin_maintanance_title' => 'Maintenance',
|
'admin_maintanance_title' => 'Maintenance',
|
||||||
'admin_maintanance_expl' => 'Some nifty buttons for Firefly III maintenance',
|
'admin_maintanance_expl' => 'Some nifty buttons for Firefly III maintenance',
|
||||||
'admin_maintenance_clear_cache' => 'Clear cache',
|
'admin_maintenance_clear_cache' => 'Clear cache',
|
||||||
|
'admin_notifications' => 'Admin notifications',
|
||||||
|
'admin_notifications_expl' => 'The following notifications can be enabled or disabled by the administrator.',
|
||||||
|
'admin_notification_check_user_new_reg' => 'User gets post-registration welcome message',
|
||||||
|
'admin_notification_check_admin_new_reg' => 'Administrator(s) get new user registration notification',
|
||||||
|
'save_notification_settings' => 'Save settings',
|
||||||
|
'notification_settings_saved' => 'The notification settings have been saved',
|
||||||
|
|
||||||
|
|
||||||
'split_transaction_title' => 'Description of the split transaction',
|
'split_transaction_title' => 'Description of the split transaction',
|
||||||
'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.',
|
'split_transaction_title_help' => 'If you create a split transaction, there must be a global description for all splits of the transaction.',
|
||||||
|
@@ -12,7 +12,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ route('admin.configuration.index') }}">{{ 'firefly_instance_configuration'|_ }}</a></li>
|
<li>
|
||||||
|
<a href="{{ route('admin.configuration.index') }}">{{ 'firefly_instance_configuration'|_ }}</a>
|
||||||
|
</li>
|
||||||
<li><a href="{{ route('admin.links.index') }}">{{ 'journal_link_configuration'|_ }}</a></li>
|
<li><a href="{{ route('admin.links.index') }}">{{ 'journal_link_configuration'|_ }}</a></li>
|
||||||
<li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li>
|
<li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -28,6 +30,31 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<form action="{{ route('admin.notifications') }}" method="post">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||||
|
<div class="box box-default">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ 'admin_notifications'|_ }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<p>
|
||||||
|
{{ 'admin_notifications_expl'|_ }}
|
||||||
|
</p>
|
||||||
|
{% for notification, value in notifications %}
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input value="1" {% if true == value %}checked{% endif %} type="checkbox" name="notification_{{ notification }}"> {{ trans('firefly.admin_notification_check_'~notification) }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="box-footer">
|
||||||
|
<button type="submit" class="btn btn-success">
|
||||||
|
<span class="fa fa-check-circle"></span> {{ ('save_notification_settings')|_ }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
|
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
|
||||||
<div class="box box-default">
|
<div class="box box-default">
|
||||||
@@ -35,11 +62,11 @@
|
|||||||
<h3 class="box-title">{{ 'send_test_email'|_ }}</h3>
|
<h3 class="box-title">{{ 'send_test_email'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<form action="{{ route('admin.test-message') }}" method="post">
|
<form action="{{ route('admin.test-message') }}" method="post">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<p>
|
<p>
|
||||||
{{ trans('firefly.send_test_email_text', {email:email})|raw }}
|
{{ trans('firefly.send_test_email_text', {email:email})|raw }}
|
||||||
</p>
|
</p>
|
||||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
<button type="submit" class="btn btn-success">
|
<button type="submit" class="btn btn-success">
|
||||||
@@ -57,7 +84,8 @@
|
|||||||
{{ 'admin_maintanance_expl'|_ }}
|
{{ 'admin_maintanance_expl'|_ }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<a href="{{ route('flush') }}" class="btn btn-warning">{{ 'admin_maintenance_clear_cache'|_ }}</a>
|
<a href="{{ route('flush') }}"
|
||||||
|
class="btn btn-warning">{{ 'admin_maintenance_clear_cache'|_ }}</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
3
resources/views/emails/registered-admin.blade.php
Normal file
3
resources/views/emails/registered-admin.blade.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
@component('mail::message')
|
||||||
|
{{ trans('email.admin_new_user_registered', ['id' => $id,'email' => $email]) }}
|
||||||
|
@endcomponent
|
@@ -1085,6 +1085,7 @@ Route::group(
|
|||||||
// admin home
|
// admin home
|
||||||
Route::get('', ['uses' => 'HomeController@index', 'as' => 'index']);
|
Route::get('', ['uses' => 'HomeController@index', 'as' => 'index']);
|
||||||
Route::post('test-message', ['uses' => 'HomeController@testMessage', 'as' => 'test-message']);
|
Route::post('test-message', ['uses' => 'HomeController@testMessage', 'as' => 'test-message']);
|
||||||
|
Route::post('notifications', ['uses' => 'HomeController@notifications', 'as' => 'notifications']);
|
||||||
|
|
||||||
// check for updates?
|
// check for updates?
|
||||||
Route::get('update-check', ['uses' => 'UpdateController@index', 'as' => 'update-check']);
|
Route::get('update-check', ['uses' => 'UpdateController@index', 'as' => 'update-check']);
|
||||||
|
Reference in New Issue
Block a user