Fix activated check for login

This commit is contained in:
snipe 2018-07-16 23:48:46 -07:00
parent d9fa2f0e91
commit bf761946da
3 changed files with 45 additions and 28 deletions

View file

@ -68,9 +68,9 @@ class LoginController extends Controller
{ {
$remote_user = $request->server('REMOTE_USER'); $remote_user = $request->server('REMOTE_USER');
if (Setting::getSettings()->login_remote_user_enabled == "1" && isset($remote_user) && !empty($remote_user)) { if (Setting::getSettings()->login_remote_user_enabled == "1" && isset($remote_user) && !empty($remote_user)) {
LOG::debug("Authenticatiing via REMOTE_USER."); LOG::debug("Authenticating via REMOTE_USER.");
try { try {
$user = User::where('username', '=', $remote_user)->whereNull('deleted_at')->first(); $user = User::where('username', '=', $remote_user)->whereNull('deleted_at')->where('active', '=', '1')->first();
LOG::debug("Remote user auth lookup complete"); LOG::debug("Remote user auth lookup complete");
if(!is_null($user)) Auth::login($user, true); if(!is_null($user)) Auth::login($user, true);
} catch(Exception $e) { } catch(Exception $e) {
@ -91,7 +91,7 @@ class LoginController extends Controller
} }
// Check if the user already exists in the database and was imported via LDAP // Check if the user already exists in the database and was imported via LDAP
$user = User::where('username', '=', Input::get('username'))->whereNull('deleted_at')->where('ldap_import', '=', 1)->first(); $user = User::where('username', '=', Input::get('username'))->whereNull('deleted_at')->where('ldap_import', '=', 1)->where('active', '=', '1')->first();
LOG::debug("Local auth lookup complete"); LOG::debug("Local auth lookup complete");
// The user does not exist in the database. Try to get them from LDAP. // The user does not exist in the database. Try to get them from LDAP.
@ -171,7 +171,7 @@ class LoginController extends Controller
if (!$user) { if (!$user) {
LOG::debug("Authenticating user against database."); LOG::debug("Authenticating user against database.");
// Try to log the user in // Try to log the user in
if (!Auth::attempt(Input::only('username', 'password'), Input::get('remember-me', 0))) { if (!Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password'), 'activated' => 1], $request->input('remember'))) {
if (!$lockedOut) { if (!$lockedOut) {
$this->incrementLoginAttempts($request); $this->incrementLoginAttempts($request);

View file

@ -287,6 +287,7 @@ class UsersController extends Controller
$user->city = $request->input('city', null); $user->city = $request->input('city', null);
$user->state = $request->input('state', null); $user->state = $request->input('state', null);
$user->country = $request->input('country', null); $user->country = $request->input('country', null);
$user->activated = $request->input('activated', 0);
$user->zip = $request->input('zip', null); $user->zip = $request->input('zip', null);

View file

@ -322,24 +322,33 @@
<!-- Activation Status --> <!-- Activation Status -->
<div class="form-group {{ $errors->has('activated') ? 'has-error' : '' }}"> <div class="form-group {{ $errors->has('activated') ? 'has-error' : '' }}">
<label class="col-md-3 control-label" for="activated">{{ trans('admin/users/table.activated') }}</label>
<div class="col-md-8"> <div class="form-group">
<div class="controls"> <div class="col-md-3 control-label">
<select {{ Form::label('activated', trans('admin/users/table.activated')) }}
{{ ($user->id === Auth::user()->id ? ' disabled="disabled"' : '') }} </div>
name="activated" <div class="col-md-9">
id="activated" @if (config('app.lock_passwords'))
{{ ((config('app.lock_passwords') && ($user->id)) ? ' disabled' : '') }} <div class="icheckbox disabled" style="padding-left: 10px;">
> {{ Form::checkbox('activated', '1', old('activated', $user->activated),['class' => 'minimal', 'disabled'=>'disabled']) }}
@if ($user->id) {{ trans('admin/users/general.activated_help_text') }}
<option value="1"{{ ($user->isActivated() ? ' selected="selected"' : '') }}>{{ trans('general.yes') }}</option> <p class="help-block">{{ trans('general.feature_disabled') }}</p>
<option value="0"{{ ( ! $user->isActivated() ? ' selected="selected"' : '') }}>{{ trans('general.no') }}</option> </div>
@elseif ($user->id === Auth::user()->id)
<div class="icheckbox disabled"" style="padding-left: 10px;">
{{ Form::checkbox('activated', '1', old('activated', $user->activated),['class' => 'minimal', 'disabled'=>'disabled']) }}
{{ trans('admin/users/general.activated_help_text') }}
<p class="help-block">{{ trans('admin/users/general.activated_disabled_help_text') }}</p>
</div>
@else @else
<option value="1"{{ (Input::old('activated') == 1 ? ' selected="selected"' : '') }}>{{ trans('general.yes') }}</option> <div style="padding-left: 10px;">
<option value="0">{{ trans('general.no') }}</option> {{ Form::checkbox('activated', '1', old('activated', $user->activated),['class' => 'minimal' ]) }}
{{ trans('admin/users/general.activated_help_text') }}
</div>
@endif @endif
</select>
{!! $errors->first('activated', '<span class="alert-msg">:message</span>') !!} {!! $errors->first('activated', '<span class="alert-msg">:message</span>') !!}
</div> </div>
</div> </div>
</div> </div>
@ -351,10 +360,17 @@
{{ Form::label('two_factor_optin', trans('admin/settings/general.two_factor')) }} {{ Form::label('two_factor_optin', trans('admin/settings/general.two_factor')) }}
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{{ Form::checkbox('two_factor_optin', '1', Input::old('two_factor_optin', $user->two_factor_optin),array('class' => 'minimal')) }} @if (config('app.lock_passwords'))
{{ trans('admin/settings/general.two_factor_enabled_text') }} <div class="icheckbox disabled">
{{ Form::checkbox('two_factor_optin', '1', Input::old('two_factor_optin', $user->two_factor_optin),['class' => 'minimal', 'disabled'=>'disabled']) }} {{ trans('admin/settings/general.two_factor_enabled_text') }}
<p class="help-block">{{ trans('general.feature_disabled') }}</p>
</div>
@else
{{ Form::checkbox('two_factor_optin', '1', Input::old('two_factor_optin', $user->two_factor_optin),['class' => 'minimal']) }} {{ trans('admin/settings/general.two_factor_enabled_text') }}
<p class="help-block">{{ trans('admin/users/general.two_factor_admin_optin_help') }}</p> <p class="help-block">{{ trans('admin/users/general.two_factor_admin_optin_help') }}</p>
@endif
</div> </div>
</div> </div>
@endif @endif