Allow password reset from user profile

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2021-05-26 15:32:23 -07:00
parent 3d008079c9
commit 9f2b4c721d
6 changed files with 57 additions and 3 deletions

View file

@ -15,6 +15,7 @@ use App\Models\User;
use App\Notifications\WelcomeNotification; use App\Notifications\WelcomeNotification;
use Auth; use Auth;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Password;
use Input; use Input;
use Redirect; use Redirect;
use Str; use Str;
@ -617,4 +618,31 @@ class UsersController extends Controller
->with('show_user', $show_user) ->with('show_user', $show_user)
->with('settings', Setting::getSettings()); ->with('settings', Setting::getSettings());
} }
/**
* Send individual password reset email
*
* @author A. Gianotto
* @since [v5.0.15]
* @return \Illuminate\Http\RedirectResponse
*/
public function sendPasswordReset($id) {
if (($user = User::find($id)) && ($user->activated == '1') && ($user->email!='') && ($user->ldap_import == '0')) {
$credentials = ['email' => $user->email];
try {
\Password::sendResetLink($credentials, function (Message $message) use ($user) {
$message->subject($this->getEmailSubject());
});
return redirect()->back()->with('success', trans('admin/users/message.password_reset_sent', ['email' => $user->email]));
} catch (\Exception $e) {
return redirect()->back()->with('error', ' Error sending email. :( ');
}
}
return redirect()->back()->with('error', 'User is not activated, is LDAP synced, or does not have an email address ');
}
} }

View file

@ -13,6 +13,8 @@ return array(
'user_deleted_warning' => 'This user has been deleted. You will have to restore this user to edit them or assign them new assets.', 'user_deleted_warning' => 'This user has been deleted. You will have to restore this user to edit them or assign them new assets.',
'ldap_not_configured' => 'LDAP integration has not been configured for this installation.', 'ldap_not_configured' => 'LDAP integration has not been configured for this installation.',
'password_resets_sent' => 'The selected users who are activated and have a valid email addresses have been sent a password reset link.', 'password_resets_sent' => 'The selected users who are activated and have a valid email addresses have been sent a password reset link.',
'password_reset_sent' => 'A password reset link has been sent to :email!',
'success' => array( 'success' => array(

View file

@ -14,4 +14,5 @@ return array(
'select_file' => 'Select File...', 'select_file' => 'Select File...',
'select_files' => 'Select Files...', 'select_files' => 'Select Files...',
'generate_labels' => '{1} Generate Label|[2,*] Generate Labels', 'generate_labels' => '{1} Generate Label|[2,*] Generate Labels',
'send_password_link' => 'Send Password Reset Link',
); );

View file

@ -52,6 +52,7 @@
<select name="bulk_actions" class="form-control select2" style="width: 200px;" aria-label="bulk_actions"> <select name="bulk_actions" class="form-control select2" style="width: 200px;" aria-label="bulk_actions">
<option value="delete">Bulk Checkin &amp; Delete</option> <option value="delete">Bulk Checkin &amp; Delete</option>
<option value="edit">Bulk Edit</option> <option value="edit">Bulk Edit</option>
<option value="bulkpasswordreset">{{ trans('button.send_password_link') }}</option>
</select> </select>
<button class="btn btn-default" id="bulkEdit" disabled>Go</button> <button class="btn btn-default" id="bulkEdit" disabled>Go</button>
</div> </div>

View file

@ -128,7 +128,7 @@
@endif @endif
</div> </div>
<div class="col-md-8"> <div class="col-md-7">
<div class="table table-responsive"> <div class="table table-responsive">
<table class="table table-striped"> <table class="table table-striped">
@if (!is_null($user->company)) @if (!is_null($user->company))
@ -326,7 +326,7 @@
</div> <!--/col-md-8--> </div> <!--/col-md-8-->
<!-- Start button column --> <!-- Start button column -->
<div class="col-md-2"> <div class="col-md-3">
@can('update', $user) @can('update', $user)
<div class="col-md-12"> <div class="col-md-12">
<a href="{{ route('users.edit', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print">{{ trans('admin/users/general.edit') }}</a> <a href="{{ route('users.edit', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print">{{ trans('admin/users/general.edit') }}</a>
@ -344,9 +344,21 @@
<a href="{{ route('users.print', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print" target="_blank" rel="noopener">{{ trans('admin/users/general.print_assigned') }}</a> <a href="{{ route('users.print', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print" target="_blank" rel="noopener">{{ trans('admin/users/general.print_assigned') }}</a>
</div> </div>
@endcan @endcan
@can('update', $user)
@if (($user->activated == '1') && ($user->email != '') && ($user->ldap_import == '0'))
<div class="col-md-12" style="padding-top: 5px;">
<form action="{{ route('users.password',['userId'=> $user->id]) }}" method="POST">
{{ csrf_field() }}
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print">{{ trans('button.send_password_link') }}</button>
</form>
</div>
@endif
@endcan
@can('delete', $user) @can('delete', $user)
@if ($user->deleted_at=='') @if ($user->deleted_at=='')
<div class="col-md-12" style="padding-top: 5px;"> <div class="col-md-12" style="padding-top: 30px;">
<form action="{{route('users.destroy',$user->id)}}" method="POST"> <form action="{{route('users.destroy',$user->id)}}" method="POST">
{{csrf_field()}} {{csrf_field()}}
{{ method_field("DELETE")}} {{ method_field("DELETE")}}

View file

@ -16,6 +16,16 @@ Route::group([ 'prefix' => 'users', 'middleware' => ['auth']], function () {
[ 'as' => 'userfile.destroy', 'uses' => 'Users\UserFilesController@destroy' ] [ 'as' => 'userfile.destroy', 'uses' => 'Users\UserFilesController@destroy' ]
); );
Route::post(
'{userId}/password',
[
'as' => 'users.password',
'uses' => 'Users\UsersController@sendPasswordReset',
]
);
Route::get( Route::get(
'{userId}/print', '{userId}/print',
[ 'as' => 'users.print', 'uses' => 'Users\UsersController@printInventory' ] [ 'as' => 'users.print', 'uses' => 'Users\UsersController@printInventory' ]