allow to use the username for login as well

add translation strings
This commit is contained in:
Jakob Schrettenbrunner 2017-02-16 20:40:21 +01:00
parent 2e134b7a55
commit 0b2c5279a8
3 changed files with 8 additions and 4 deletions

View file

@ -87,8 +87,11 @@ class LoginController extends Controller
*/ */
public function login(Request $request) public function login(Request $request)
{ {
// Check wether login is an email address or a username
$isEmail = str_contains($request->input('user'), '@');
$this->validate($request, [ $this->validate($request, [
'email' => 'required|email', 'user' => $isEmail ? 'required|email' : 'required',
'password' => 'required', 'password' => 'required',
]); ]);
@ -98,9 +101,9 @@ class LoginController extends Controller
return $this->sendLockoutResponse($request); return $this->sendLockoutResponse($request);
} }
// Is the email & password valid? // Is the user (email or username) & password valid?
if (! Auth::once([ if (! Auth::once([
'email' => $request->input('email'), $isEmail ? 'email' : 'username' => $request->input('user'),
'password' => $request->input('password'), 'password' => $request->input('password'),
], $request->has('remember'))) { ], $request->has('remember'))) {
if (! $lockedOut) { if (! $lockedOut) {

View file

@ -2,6 +2,7 @@
return [ return [
'email' => 'Email', 'email' => 'Email',
'user_identifier' => 'Email or password',
'password' => 'Password', 'password' => 'Password',
'confirm_password' => 'Confirm Password', 'confirm_password' => 'Confirm Password',
'login' => 'Login', 'login' => 'Login',

View file

@ -47,7 +47,7 @@
<p class="login-box-msg">@lang('auth.authentication_required')</p> <p class="login-box-msg">@lang('auth.authentication_required')</p>
<form action="{{ route('auth.login') }}" method="POST"> <form action="{{ route('auth.login') }}" method="POST">
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<input type="email" name="email" class="form-control" value="{{ old('email') }}" placeholder="@lang('strings.email')"> <input name="user" class="form-control" value="{{ old('user') }}" placeholder="@lang('strings.user_identifier')">
<span class="fa fa-envelope form-control-feedback"></span> <span class="fa fa-envelope form-control-feedback"></span>
</div> </div>
<div class="form-group has-feedback"> <div class="form-group has-feedback">