Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion app/Http/Controllers/Users/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,14 +130,26 @@ 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')]);
}


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 {
Expand Down
1 change: 0 additions & 1 deletion resources/lang/en-US/admin/users/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. ',
Expand Down
6 changes: 4 additions & 2 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <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',
Expand Down Expand Up @@ -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?',
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/importer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class="col-md-12 table table-striped snipe-table">
<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">
Expand Down
38 changes: 38 additions & 0 deletions resources/views/users/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')])

Expand Down Expand Up @@ -685,7 +702,28 @@ class="form-control">
$(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
Expand Down
Loading