Аутентификация
пользователей.
В консоли пишем:
php artisan make:auth
Обязательно переместим
файл User.ph в app.
В самом фале
изменим строку с пространством имен.
namespace
App;
Теперь
вы увидим страницу входа на сайт по
адресу:
Зарегестрируемся.
Вставим ссылку
логин в меню:
\resources\views\user\layouts\header.blade.php
<a
class="nav-link" href="{{ route('login') }}">Login</a>
Здесь в public
function auth() можно посмтреть все маршруты
аутентификации.
\vendor\laravel\framework\src\Illuminate\Routing\Router.php
Изменим вид
страницы логина. Скопируем разметку из
\Row files\clean blog\contact.html
и вставим в
\resources\views\auth\login.blade.php
@extends('user/app')
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Login Here')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a href="{{ route('register') }}" class="btn btn-primary">
Register
</a>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
Откроем страницу регистрации \resources\views\auth\register.blade.php
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Login Here')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a href="{{ route('register') }}" class="btn btn-primary">
Register
</a>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
Откроем страницу регистрации \resources\views\auth\register.blade.php
@extends('user/app')
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Register Here')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Register Here')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
Изменим
домашнюю страницу. Откроем
resources\views\home.blade.php
@extends('user/app')
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Welcome!')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
Welcome to the blog!
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
@section('bg-img', asset('user/img/contact-bg.jpg'))
@section('head')
@endsection
@section('title', 'Welcome!')
@section('sub-heading', '')
@section('main-content')
<!-- Post Content -->
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
Welcome to the blog!
</div>
</div>
</div>
</article>
<hr>
@endsection
@section('footer')
@endsection
Изменим ссылку
на Logout, если пользователь
залогинился. Откроем
\resources\views\layouts\app.blade.php и возьмем логику
отсюда.
Откроем
\resources\views\user\layouts\header.blade.php
<!--
Navigation -->
<nav
class="navbar navbar-expand-lg navbar-light fixed-top"
id="mainNav">
<a
class="navbar-brand" href="index.html">Start
Bootstrap</a>
<button
class="navbar-toggler navbar-toggler-right" type="button"
data-toggle="collapse" data-target="#navbarResponsive"
aria-controls="navbarResponsive" aria-expanded="false"
aria-label="Toggle navigation">
Menu
<i
class="fa fa-bars"></i>
</button>
<div
class="collapse navbar-collapse" id="navbarResponsive">
<ul
class="navbar-nav ml-auto">
<li
class="nav-item">
<a
class="nav-link" href="index.html">Home</a>
</li>
<li
class="nav-item">
<a
class="nav-link" href="about.html">About</a>
</li>
<li
class="nav-item">
<a
class="nav-link" href="post.html">Sample
Post</a>
</li>
<li
class="nav-item">
@if
(Auth::guest())
<a
class="nav-link" href="{{ route('login') }}">Login</a>
@else
<a
href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form
id="logout-form" action="{{ route('logout') }}"
method="POST" style="display: none;">
{{
csrf_field() }}
</form>
@endif
</li>
</ul>
</div>
</nav>
<!--
Page Header -->
<header
class="masthead" style="background-image:
url(@yield('bg-img'))">
<div
class="container">
<div
class="row">
<div
class="col-lg-8 col-md-10 mx-auto">
<div
class="site-heading">
<h1>@yield('title')</h1>
<span
class="subheading">@yield('sub-heading')</span>
</div>
</div>
</div>
</div>
</header>
Комментариев нет:
Отправить комментарий