Merge branch 'authentication' into dev
This commit is contained in:
@@ -4,8 +4,10 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
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\Hash;
|
||||
|
||||
/**
|
||||
* Class Login
|
||||
@@ -16,6 +18,13 @@ use Illuminate\Support\Facades\Auth;
|
||||
*/
|
||||
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()
|
||||
{
|
||||
if (Auth::check()) {
|
||||
@@ -26,16 +35,45 @@ class Login extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* Login handler
|
||||
*
|
||||
* @param LoginRequest $request
|
||||
*
|
||||
* @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');
|
||||
}
|
||||
|
||||
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
-2
@@ -10,7 +10,7 @@ Route::group(['middleware' => ['web']], function () {
|
||||
->name('loginForm');
|
||||
|
||||
// handle login
|
||||
Route::post('admin/login', 'Admin\Login@postLogin')
|
||||
Route::post('login', 'Admin\Login@postLogin')
|
||||
->name('login');
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ Route::group(['middleware' => ['web']], function () {
|
||||
* This route group serves to handle request in admin
|
||||
*/
|
||||
Route::group([
|
||||
'middleware' => ['auth'],
|
||||
// 'middleware' => ['auth'],
|
||||
'namespace' => 'Admin',
|
||||
'prefix' => 'admin'
|
||||
], function () {
|
||||
|
||||
@@ -7,6 +7,13 @@
|
||||
|
||||
<div class="row">
|
||||
<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') }}">
|
||||
{!! csrf_field() !!}
|
||||
|
||||
@@ -18,9 +25,9 @@
|
||||
<input type="text" placeholder="somebody@example.com" name="email">
|
||||
|
||||
@if ($errors->has('email'))
|
||||
<span class="help-block">
|
||||
<strong>{{ $errors->first('email') }}</strong>
|
||||
</span>
|
||||
<div data-alert class="callout alert text-center small">
|
||||
{{ $errors->first('email') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
|
||||
@@ -29,16 +36,16 @@
|
||||
<input type="password" placeholder="@lang('admin/loginForm.password')" name="password">
|
||||
|
||||
@if ($errors->has('password'))
|
||||
<span class="help-block">
|
||||
<strong>{{ $errors->first('password') }}</strong>
|
||||
</span>
|
||||
<div data-alert class="callout alert text-center small">
|
||||
{{ $errors->first('password') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('admin/loginForm.rememberMe')
|
||||
<input type="checkbox" name="remember">
|
||||
</label>
|
||||
{{--<label>--}}
|
||||
{{--@lang('admin/loginForm.rememberMe')--}}
|
||||
{{--<input type="checkbox" name="remember">--}}
|
||||
{{--</label>--}}
|
||||
|
||||
<p>
|
||||
<button type="submit" class="button expanded">@lang('admin/loginForm.login')</button>
|
||||
|
||||
Reference in New Issue
Block a user