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');
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 {
$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");
if(!is_null($user)) Auth::login($user, true);
} 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
$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");
// The user does not exist in the database. Try to get them from LDAP.
@ -171,7 +171,7 @@ class LoginController extends Controller
if (!$user) {
LOG::debug("Authenticating user against database.");
// 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) {
$this->incrementLoginAttempts($request);

View file

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

View file

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