Merge pull request #17734 from grokability/#17726-add-welcome-email-to-new-user-form

Fixed #17726: add welcome email to new user form
This commit is contained in:
snipe
2025-08-28 07:29:56 +01:00
committed by GitHub
6 changed files with 70 additions and 4 deletions
@@ -20,6 +20,7 @@ use App\Models\Consumable;
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 @@ class UsersController extends Controller
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 {
+15 -1
View File
@@ -13,7 +13,9 @@ use App\Models\Company;
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 @@ class UsersController extends Controller
// 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 @@ class UsersController extends Controller
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 {
@@ -24,7 +24,6 @@ return [
'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. ',
+4 -2
View File
@@ -160,7 +160,7 @@ return [
'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. <br><br>The CSV should be comma-delimited and formatted with headers that match the ones in the <a href="https://snipe-it.readme.io/docs/importing" target="_new">sample CSVs in the documentation</a>.',
'importing_help' => 'The CSV should be comma-delimited and formatted with headers that match the ones in the <a href="https://snipe-it.readme.io/docs/importing" target="_new">sample CSVs in the documentation</a>.',
'import-history' => 'Import History',
'asset_maintenance' => 'Asset Maintenance',
'asset_maintenance_report' => 'Asset Maintenance Report',
@@ -483,7 +483,9 @@ return [
'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?',
@@ -196,6 +196,7 @@
<input type="checkbox" name="send_welcome" data-livewire-component="{{ $this->getId() }}" wire:model.live="send_welcome">
{{ trans('general.send_welcome_email_to_users') }}
</label>
<p class="help-block"> {{ trans('general.send_welcome_email_import_help') }}</p>
@endif
<label class="form-control">
+38
View File
@@ -288,6 +288,23 @@
</div>
</div>
<!-- Send welcome email to user -->
@if (!$user->id)
<div class="form-group" id="email_user_row">
<div class="col-md-8 col-md-offset-3">
<label class="form-control form-control--disabled">
{{ Form::checkbox('send_welcome', '1', old('send_welcome'), ['id' => "email_user_checkbox", 'aria-label'=>'send_welcome']) }}
{{ trans('general.send_welcome_email_to_users') }}
</label>
<p class="help-block"> {{ trans('general.send_welcome_email_help') }}</p>
</div>
</div> <!--/form-group-->
@endif
@include ('partials.forms.edit.image-upload', ['fieldname' => 'avatar', 'image_path' => app('users_upload_path')])
@@ -685,7 +702,28 @@
$(document).ready(function() {
// Set some defaults
$('#email_user_checkbox').prop("disabled", true);
$('#email_user_checkbox').prop("checked", false);
$("#email_user_checkbox").removeAttr('checked');
// If the email address is longer than 5 characters, enable the "send email" checkbox
$('#email').on('keyup',function(){
//event.preventDefault();
@if (!config('app.lock_passwords'))
if (this.value.length > 5) {
$('#email_user_checkbox').prop("disabled", false);
$("#email_user_checkbox").parent().removeClass("form-control--disabled");
} else {
$('#email_user_checkbox').prop("disabled", true);
$('#email_user_checkbox').prop("checked", false);
$("#email_user_checkbox").parent().addClass("form-control--disabled");
}
@endif
});
// Check/Uncheck all radio buttons in the group