FEATURE #1358: finish login
Login form should look like finished part of application.
This commit is contained in:
@@ -4,8 +4,10 @@ namespace App\Http\Controllers\Admin;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use Illuminate\Http\Request;
|
use App\Http\Requests\LoginRequest;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Login
|
* Class Login
|
||||||
@@ -16,6 +18,13 @@ use Illuminate\Support\Facades\Auth;
|
|||||||
*/
|
*/
|
||||||
class Login extends Controller
|
class Login extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Display login form
|
||||||
|
*
|
||||||
|
* This method displays login form, or in case that user is logged in, redirects him to admin dashboard panel.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||||
|
*/
|
||||||
public function getLoginForm()
|
public function getLoginForm()
|
||||||
{
|
{
|
||||||
if (Auth::check()) {
|
if (Auth::check()) {
|
||||||
@@ -26,16 +35,45 @@ class Login extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Request $request
|
* Login handler
|
||||||
|
*
|
||||||
|
* @param LoginRequest $request
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function postLogin(Request $request)
|
public function postLogin(LoginRequest $request)
|
||||||
{
|
{
|
||||||
if (Auth::attempt($request->only('email', 'password'))) {
|
$email = $request->email;
|
||||||
|
|
||||||
|
// try to find user
|
||||||
|
$user = User::where('email', $email)
|
||||||
|
->where('role', '!=', User::ROLE_VISITOR)
|
||||||
|
->where('status', User::STATE_ACTIVE)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (!$user) {
|
||||||
|
return $this->loginFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to log in user
|
||||||
|
if (Hash::check($request->password, $user->password)) {
|
||||||
|
Auth::login($user);
|
||||||
|
|
||||||
return redirect()->route('admin.dashboard');
|
return redirect()->route('admin.dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "neplatne prihlaseni";
|
// if (Auth::attempt($request->only('email', 'password'))) {
|
||||||
|
// return redirect()->route('admin.dashboard');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// login invalid, redirect and inform the user
|
||||||
|
return $this->loginFailed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function loginFailed()
|
||||||
|
{
|
||||||
|
return redirect()
|
||||||
|
->route('login')
|
||||||
|
->with('error', trans('auth.failed'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
class LoginRequest extends Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'email' => 'required|email',
|
||||||
|
'password' => 'required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-1
@@ -26,13 +26,14 @@ Route::group(['middleware' => ['web']], function () {
|
|||||||
Route::get('login', 'Admin\Login@getLoginForm')->name('loginForm');
|
Route::get('login', 'Admin\Login@getLoginForm')->name('loginForm');
|
||||||
|
|
||||||
// POST methods
|
// POST methods
|
||||||
|
// handle login
|
||||||
Route::post('login', 'Admin\Login@postLogin')
|
Route::post('login', 'Admin\Login@postLogin')
|
||||||
->name('login');
|
->name('login');
|
||||||
});
|
});
|
||||||
|
|
||||||
// list of admin routes
|
// list of admin routes
|
||||||
Route::group([
|
Route::group([
|
||||||
'middleware' => ['auth'],
|
// 'middleware' => ['auth'],
|
||||||
'namespace' => 'Admin',
|
'namespace' => 'Admin',
|
||||||
'prefix' => 'admin'
|
'prefix' => 'admin'
|
||||||
], function () {
|
], function () {
|
||||||
|
|||||||
@@ -7,6 +7,13 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="medium-6 medium-centered large-4 large-centered columns login-form">
|
<div class="medium-6 medium-centered large-4 large-centered columns login-form">
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div data-alert class="callout alert">
|
||||||
|
<strong>{{ session('error') }}</strong>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<form method="POST" action="{{ route('login') }}">
|
<form method="POST" action="{{ route('login') }}">
|
||||||
{!! csrf_field() !!}
|
{!! csrf_field() !!}
|
||||||
|
|
||||||
@@ -18,9 +25,9 @@
|
|||||||
<input type="text" placeholder="somebody@example.com" name="email">
|
<input type="text" placeholder="somebody@example.com" name="email">
|
||||||
|
|
||||||
@if ($errors->has('email'))
|
@if ($errors->has('email'))
|
||||||
<span class="help-block">
|
<div data-alert class="callout alert text-center small">
|
||||||
<strong>{{ $errors->first('email') }}</strong>
|
{{ $errors->first('email') }}
|
||||||
</span>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
@@ -29,16 +36,16 @@
|
|||||||
<input type="password" placeholder="@lang('admin/loginForm.password')" name="password">
|
<input type="password" placeholder="@lang('admin/loginForm.password')" name="password">
|
||||||
|
|
||||||
@if ($errors->has('password'))
|
@if ($errors->has('password'))
|
||||||
<span class="help-block">
|
<div data-alert class="callout alert text-center small">
|
||||||
<strong>{{ $errors->first('password') }}</strong>
|
{{ $errors->first('password') }}
|
||||||
</span>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
{{--<label>--}}
|
||||||
@lang('admin/loginForm.rememberMe')
|
{{--@lang('admin/loginForm.rememberMe')--}}
|
||||||
<input type="checkbox" name="remember">
|
{{--<input type="checkbox" name="remember">--}}
|
||||||
</label>
|
{{--</label>--}}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<button type="submit" class="button expanded">@lang('admin/loginForm.login')</button>
|
<button type="submit" class="button expanded">@lang('admin/loginForm.login')</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user