Skip to content

Commit eebc2ab

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents b65b315 + b303875 commit eebc2ab

File tree

6 files changed

+70
-4
lines changed

6 files changed

+70
-4
lines changed

app/Http/Controllers/Api/UsersController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use App\Models\License;
2121
use App\Models\User;
2222
use App\Notifications\CurrentInventory;
23+
use App\Notifications\WelcomeNotification;
2324
use Illuminate\Support\Facades\Artisan;
2425
use Illuminate\Support\Facades\Auth;
2526
use Illuminate\Database\Eloquent\Builder;
@@ -437,6 +438,17 @@ public function store(SaveUserRequest $request) : JsonResponse
437438
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
438439

439440
if ($user->save()) {
441+
442+
if (($user->activated == '1') && ($user->email != '') && ($request->input('send_welcome') == '1')) {
443+
444+
try {
445+
$user->notify(new WelcomeNotification($user));
446+
} catch (\Exception $e) {
447+
Log::warning('Could not send welcome notification for user: ' . $e->getMessage());
448+
}
449+
450+
}
451+
440452
if ($request->filled('groups')) {
441453
$user->groups()->sync($request->input('groups'));
442454
} else {

app/Http/Controllers/Users/UsersController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use App\Models\Group;
1414
use App\Models\Setting;
1515
use App\Models\User;
16+
use App\Notifications\WelcomeNotification;
1617
use Illuminate\Http\Request;
18+
use Illuminate\Support\Facades\Log;
1719
use Illuminate\Support\Facades\Password;
1820
use Symfony\Component\HttpFoundation\StreamedResponse;
1921
use App\Notifications\CurrentInventory;
@@ -128,14 +130,26 @@ public function store(SaveUserRequest $request)
128130
// we have to invoke the form request here to handle image uploads
129131
app(ImageUploadRequest::class)->handleImages($user, 600, 'avatar', 'avatars', 'avatar');
130132

131-
if($request->get('redirect_option') === 'back'){
133+
if ($request->get('redirect_option') === 'back'){
132134
session()->put(['redirect_option' => 'index']);
133135
} else {
134136
session()->put(['redirect_option' => $request->get('redirect_option')]);
135137
}
136138

137139

138140
if ($user->save()) {
141+
142+
if (($user->activated == '1') && ($user->email != '') && ($request->input('send_welcome') == '1')) {
143+
144+
try {
145+
$user->notify(new WelcomeNotification($user));
146+
} catch (\Exception $e) {
147+
Log::warning('Could not send welcome notification for user: ' . $e->getMessage());
148+
}
149+
150+
151+
}
152+
139153
if ($request->filled('groups')) {
140154
$user->groups()->sync($request->input('groups'));
141155
} else {

resources/lang/en-US/admin/users/general.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
'auto_assign_label' => 'Include this user when auto-assigning eligible licenses',
2525
'auto_assign_help' => 'Skip this user in auto assignment of licenses',
2626
'software_user' => 'Software Checked out to :name',
27-
'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.',
2827
'view_user' => 'View User :name',
2928
'usercsv' => 'CSV file',
3029
'two_factor_admin_optin_help' => 'Your current admin settings allow selective enforcement of two-factor authentication. ',

resources/lang/en-US/general.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
'import' => 'Import',
161161
'import_this_file' => 'Map fields and process this file',
162162
'importing' => 'Importing',
163-
'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>.',
163+
'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>.',
164164
'import-history' => 'Import History',
165165
'asset_maintenance' => 'Asset Maintenance',
166166
'asset_maintenance_report' => 'Asset Maintenance Report',
@@ -483,7 +483,9 @@
483483
'update_existing_values' => 'Update Existing Values?',
484484
'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.',
485485
'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.',
486-
'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.',
486+
'send_welcome_email_to_users' => ' Send welcome email to new users',
487+
'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.',
488+
'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.',
487489
'send_email' => 'Send Email',
488490
'call' => 'Call number',
489491
'back_before_importing' => 'Backup before importing?',

resources/views/livewire/importer.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class="col-md-12 table table-striped snipe-table">
196196
<input type="checkbox" name="send_welcome" data-livewire-component="{{ $this->getId() }}" wire:model.live="send_welcome">
197197
{{ trans('general.send_welcome_email_to_users') }}
198198
</label>
199+
<p class="help-block"> {{ trans('general.send_welcome_email_import_help') }}</p>
199200
@endif
200201

201202
<label class="form-control">

resources/views/users/edit.blade.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,23 @@
288288

289289
</div>
290290
</div>
291+
292+
<!-- Send welcome email to user -->
293+
@if (!$user->id)
294+
<div class="form-group" id="email_user_row">
295+
296+
<div class="col-md-8 col-md-offset-3">
297+
<label class="form-control form-control--disabled">
298+
{{ Form::checkbox('send_welcome', '1', old('send_welcome'), ['id' => "email_user_checkbox", 'aria-label'=>'send_welcome']) }}
299+
{{ trans('general.send_welcome_email_to_users') }}
300+
</label>
301+
302+
<p class="help-block"> {{ trans('general.send_welcome_email_help') }}</p>
303+
304+
</div>
305+
</div> <!--/form-group-->
306+
@endif
307+
291308

292309
@include ('partials.forms.edit.image-upload', ['fieldname' => 'avatar', 'image_path' => app('users_upload_path')])
293310

@@ -685,7 +702,28 @@ class="form-control">
685702
$(document).ready(function() {
686703
687704
705+
// Set some defaults
706+
$('#email_user_checkbox').prop("disabled", true);
707+
$('#email_user_checkbox').prop("checked", false);
708+
$("#email_user_checkbox").removeAttr('checked');
688709
710+
// If the email address is longer than 5 characters, enable the "send email" checkbox
711+
$('#email').on('keyup',function(){
712+
//event.preventDefault();
713+
714+
@if (!config('app.lock_passwords'))
715+
716+
if (this.value.length > 5) {
717+
$('#email_user_checkbox').prop("disabled", false);
718+
$("#email_user_checkbox").parent().removeClass("form-control--disabled");
719+
} else {
720+
$('#email_user_checkbox').prop("disabled", true);
721+
$('#email_user_checkbox').prop("checked", false);
722+
$("#email_user_checkbox").parent().addClass("form-control--disabled");
723+
}
724+
725+
@endif
726+
});
689727
690728
691729
// Check/Uncheck all radio buttons in the group

0 commit comments

Comments
 (0)