Skip to content

Commit

Permalink
Merge pull request #16091 from snipe/hide_password_reset_if_ldap
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe authored Jan 17, 2025
2 parents 7e65d68 + 02eeb7f commit 327491c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
30 changes: 16 additions & 14 deletions app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,24 @@ public function reset(Request $request)
], $messages);
}


// set the response
$response = $broker->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
});

// Check if the password reset above actually worked
if ($response == \Password::PASSWORD_RESET) {
Log::debug('Password reset for '.$user->username.' worked');
return redirect()->guest('login')->with('success', trans('passwords.reset'));
if ($user->ldap_import != '1') {

// set the response
$response = $broker->reset(
$this->credentials($request), function ($user, $password) {
$this->resetPassword($user, $password);
});

// Check if the password reset above actually worked
if ($response == \Password::PASSWORD_RESET) {
Log::debug('Password reset for ' . $user->username . ' worked');
return redirect()->guest('login')->with('success', trans('passwords.reset'));
}

Log::debug('Password reset for ' . $user->username . ' FAILED - this user exists but the token is not valid');
return redirect()->back()->withInput($request->only('email'))->with('success', trans('passwords.reset'));
}

Log::debug('Password reset for '.$user->username.' FAILED - this user exists but the token is not valid');
return redirect()->back()->withInput($request->only('email'))->with('success', trans('passwords.reset'));

}


Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ public function api(): View
* User change email page.
*
*/
public function password() : View
public function password() : View | RedirectResponse
{

$user = auth()->user();
if ($user->ldap_import=='1') {
return redirect()->route('account')->with('error', trans('admin/users/message.error.password_ldap'));
}
return view('account/change-password', compact('user'));
}

Expand All @@ -116,7 +120,7 @@ public function passwordSave(Request $request) : RedirectResponse

$user = auth()->user();
if ($user->ldap_import == '1') {
return redirect()->route('account.password.index')->with('error', trans('admin/users/message.error.password_ldap'));
return redirect()->route('account')->with('error', trans('admin/users/message.error.password_ldap'));
}

$rules = [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Users/BulkUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function edit(Request $request)
// bulk password reset, just do the thing
} elseif ($request->input('bulk_actions') == 'bulkpasswordreset') {
foreach ($users as $user) {
if (($user->activated == '1') && ($user->email != '')) {
if (($user->activated == '1') && ($user->email != '') && ($user->ldap_import != '1')) {
$credentials = ['email' => $user->email];
Password::sendResetLink($credentials/* , function (Message $message) {
$message->subject($this->getEmailSubject()); // TODO - I'm not sure if we still need this, but this second parameter is no longer accepted in later Laravel versions.
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en-US/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,5 +573,8 @@
'import_asset_tag_exists' => 'An asset with the asset tag :asset_tag already exists and an update was not requested. No change was made.',
'countries_manually_entered_help' => 'Values with an asterisk (*) were manually entered and do not match existing ISO 3166 dropdown values',
'accessories_assigned' => 'Assigned Accessories',
'user_managed_passwords' => 'Password Management',
'user_managed_passwords_disallow' => 'Disallow users from managing their own passwords',
'user_managed_passwords_allow' => 'Allow users to manage their own passwords',

];
3 changes: 3 additions & 0 deletions resources/views/account/view-assets.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@
</a>
</div>
@endcan

@if ($user->ldap_import!='1')
<div class="col-md-12" style="padding-top: 5px;">
<a href="{{ route('account.password.index') }}" style="width: 100%;" class="btn btn-sm btn-primary btn-social btn-block hidden-print" target="_blank" rel="noopener">
<x-icon type="password" class="fa-fw" />
{{ trans('general.changepassword') }}
</a>
</div>
@endif

@can('self.api')
<div class="col-md-12" style="padding-top: 5px;">
Expand Down
2 changes: 2 additions & 0 deletions resources/views/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,14 @@
</li>
@endcan

@if (Auth::user()->ldap_import!='1')
<li>
<a href="{{ route('account.password.index') }}">
<x-icon type="password" class="fa-fw" />
{{ trans('general.changepassword') }}
</a>
</li>
@endif


@can('self.api')
Expand Down
8 changes: 6 additions & 2 deletions resources/views/users/bulk-edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<!-- ldap_sync -->
<div class="form-group">
<div class="col-sm-3 control-label">
{{ trans('general.ldap_sync') }}
{{ trans('general.user_managed_passwords') }}
</div>
<div class="col-sm-9">
<label for="no_change" class="form-control">
Expand All @@ -153,7 +153,11 @@
</label>
<label for="ldap_import" class="form-control">
{{ Form::radio('ldap_import', '0', old('ldap_import'), ['id' => 'ldap_import', 'aria-label'=>'ldap_import']) }}
{{ trans('general.ldap_import') }}
{{ trans('general.user_managed_passwords_allow') }}
</label>
<label for="ldap_import" class="form-control">
{{ Form::radio('ldap_import', '1', old('ldap_import'), ['id' => 'ldap_import', 'aria-label'=>'ldap_import']) }}
{{ trans('general.user_managed_passwords_disallow') }}
</label>
</div>
</div> <!--/form-group-->
Expand Down

0 comments on commit 327491c

Please sign in to comment.