diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index ac9c6add7bcc..2d55d4461198 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -20,6 +20,7 @@ use App\Models\License; use App\Models\User; use App\Notifications\CurrentInventory; +use App\Notifications\WelcomeNotification; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; use Illuminate\Database\Eloquent\Builder; @@ -437,6 +438,17 @@ public function store(SaveUserRequest $request) : JsonResponse app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); if ($user->save()) { + + if (($user->activated == '1') && ($user->email != '') && ($request->input('send_welcome') == '1')) { + + try { + $user->notify(new WelcomeNotification($user)); + } catch (\Exception $e) { + Log::warning('Could not send welcome notification for user: ' . $e->getMessage()); + } + + } + if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); } else { diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index ec87d3ec9922..aa42415065aa 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -13,7 +13,9 @@ use App\Models\Group; use App\Models\Setting; use App\Models\User; +use App\Notifications\WelcomeNotification; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Password; use Symfony\Component\HttpFoundation\StreamedResponse; use App\Notifications\CurrentInventory; @@ -128,7 +130,7 @@ public function store(SaveUserRequest $request) // we have to invoke the form request here to handle image uploads app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar'); - if($request->get('redirect_option') === 'back'){ + if ($request->get('redirect_option') === 'back'){ session()->put(['redirect_option' => 'index']); } else { session()->put(['redirect_option' => $request->get('redirect_option')]); @@ -136,6 +138,18 @@ public function store(SaveUserRequest $request) if ($user->save()) { + + if (($user->activated == '1') && ($user->email != '') && ($request->input('send_welcome') == '1')) { + + try { + $user->notify(new WelcomeNotification($user)); + } catch (\Exception $e) { + Log::warning('Could not send welcome notification for user: ' . $e->getMessage()); + } + + + } + if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); } else { diff --git a/resources/lang/en-US/admin/users/general.php b/resources/lang/en-US/admin/users/general.php index cecf786ce230..fa0f478d4bb0 100644 --- a/resources/lang/en-US/admin/users/general.php +++ b/resources/lang/en-US/admin/users/general.php @@ -24,7 +24,6 @@ 'auto_assign_label' => 'Include this user when auto-assigning eligible licenses', 'auto_assign_help' => 'Skip this user in auto assignment of licenses', 'software_user' => 'Software Checked out to :name', - 'send_email_help' => 'You must provide an email address for this user to send them credentials. Emailing credentials can only be done on user creation. Passwords are stored in a one-way hash and cannot be retrieved once saved.', 'view_user' => 'View User :name', 'usercsv' => 'CSV file', 'two_factor_admin_optin_help' => 'Your current admin settings allow selective enforcement of two-factor authentication. ', diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 1d501ee61602..eb7df70d4312 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -160,7 +160,7 @@ 'import' => 'Import', 'import_this_file' => 'Map fields and process this file', 'importing' => 'Importing', - 'importing_help' => 'You can import assets, accessories, licenses, components, consumables, and users via CSV file.

The CSV should be comma-delimited and formatted with headers that match the ones in the sample CSVs in the documentation.', + 'importing_help' => 'The CSV should be comma-delimited and formatted with headers that match the ones in the sample CSVs in the documentation.', 'import-history' => 'Import History', 'asset_maintenance' => 'Asset Maintenance', 'asset_maintenance_report' => 'Asset Maintenance Report', @@ -483,7 +483,9 @@ 'update_existing_values' => 'Update Existing Values?', 'auto_incrementing_asset_tags_disabled_so_tags_required' => 'Generating auto-incrementing asset tags is disabled so all rows need to have the "Asset Tag" column populated.', 'auto_incrementing_asset_tags_enabled_so_now_assets_will_be_created' => 'Note: Generating auto-incrementing asset tags is enabled so assets will be created for rows that do not have "Asset Tag" populated. Rows that do have "Asset Tag" populated will be updated with the provided information.', - 'send_welcome_email_to_users' => ' Send Welcome Email for new Users? Note that only users with a valid email address and who are marked as activated in your import file will received a welcome.', + 'send_welcome_email_to_users' => ' Send welcome email to new users', + 'send_welcome_email_help' => 'Only users with a valid email address and who are marked as activated will receive a welcome email where they can reset their password.', + 'send_welcome_email_import_help' => 'Only new users with a valid email address and who are marked as activated in your import file will receive a welcome email where they can set their password.', 'send_email' => 'Send Email', 'call' => 'Call number', 'back_before_importing' => 'Backup before importing?', diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 9162b09c72e5..ba6dfbfdbd74 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -196,6 +196,7 @@ class="col-md-12 table table-striped snipe-table"> {{ trans('general.send_welcome_email_to_users') }} +

{{ trans('general.send_welcome_email_import_help') }}

@endif