Commit cf8a5d67 authored by Anh Tuan's avatar Anh Tuan

4 NLG01 Login logout

Feature login logout

Resolves: #4
parent 99a86add
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login()
{
return view('auth.login');
}
public function postLogin(Request $request)
{
$email = $request->input('email');
$password = $request->input('password');
$remember = $request->input('remember');
$user = User::where('email', '=', $email)->first();
if ($user) {
if (Auth::attempt(['email' => $email, 'password' => $password], $remember)) {
//TODO: Redirect for each role
return $this->sendLoginResponse($request);
} else {
flash(__('またはパスワードが異なります'))->error()->important();
return redirect()->route('login');
}
} else {
flash(__('入力されたIDは存在しません'))->error()->important();
return redirect()->route('login');
}
}
public function logout(Request $request)
{
Auth::logout();
$request->session()->invalidate();
return redirect()->route('login');
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "45475838e4b222ca3d1aca9ae395a652", "content-hash": "5b532959f3be18f0e770d26c81096bb1",
"packages": [ "packages": [
{ {
"name": "barryvdh/laravel-ide-helper", "name": "barryvdh/laravel-ide-helper",
...@@ -525,6 +525,60 @@ ...@@ -525,6 +525,60 @@
], ],
"time": "2015-04-20T18:58:01+00:00" "time": "2015-04-20T18:58:01+00:00"
}, },
{
"name": "laracasts/flash",
"version": "3.0.2",
"source": {
"type": "git",
"url": "https://github.com/laracasts/flash.git",
"reference": "10cd420ab63fd0796bf5e1e5b99f87636d2f4333"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laracasts/flash/zipball/10cd420ab63fd0796bf5e1e5b99f87636d2f4333",
"reference": "10cd420ab63fd0796bf5e1e5b99f87636d2f4333",
"shasum": ""
},
"require": {
"illuminate/support": "~5.0",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "dev-master",
"phpunit/phpunit": "^6.1"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Laracasts\\Flash\\FlashServiceProvider"
],
"aliases": {
"Flash": "Laracasts\\Flash\\Flash"
}
}
},
"autoload": {
"psr-0": {
"Laracasts\\Flash": "src/"
},
"files": [
"src/Laracasts/Flash/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jeffrey Way",
"email": "jeffrey@laracasts.com"
}
],
"description": "Easy flash notifications",
"time": "2017-06-22T19:01:19+00:00"
},
{ {
"name": "laravel/framework", "name": "laravel/framework",
"version": "v5.5.17", "version": "v5.5.17",
......
...@@ -170,6 +170,7 @@ return [ ...@@ -170,6 +170,7 @@ return [
Barryvdh\Debugbar\ServiceProvider::class, Barryvdh\Debugbar\ServiceProvider::class,
Collective\Html\HtmlServiceProvider::class, Collective\Html\HtmlServiceProvider::class,
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class, Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
Laracasts\Flash\FlashServiceProvider::class,
/* /*
* Application Service Providers... * Application Service Providers...
*/ */
......
...@@ -67,7 +67,8 @@ return [ ...@@ -67,7 +67,8 @@ return [
'providers' => [ 'providers' => [
'users' => [ 'users' => [
'driver' => 'eloquent', 'driver' => 'eloquent',
'model' => App\User::class, //Model use to login
'model' => App\Models\User::class,
], ],
// 'users' => [ // 'users' => [
......
@extends('layouts.master')
@section('pagetitle', __('Login'))
@section('pageheader', __('ログイン'))
@section('content')
<div class="row">
<div class="col-md-4">&nbsp;</div>
<div class="col-md-4">
<form role="form" method="post" action={{ route('login') }}>
{{ csrf_field() }}
<div class="form-group">
<label class="control-label" for="exampleInputEmail1">{{ __('Eメールアドレス') }}</label>
<input class="form-control" id="exampleInputEmail1" placeholder=": login@alexon.co.jp" type="email" name="email">
</div>
<div class="form-group">
<label class="control-label" for="exampleInputPassword1">パスワード</label>
<input class="form-control" id="exampleInputPassword1" placeholder=": pass1234" type="password" name="password">
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" id="remember"> Remember me
</label>
</div>
</div>
<br>
<button type="submit" class="btn btn-default">{{ __('ログイン') }}</button>
</form>
</div>
<div class="col-md-4">&nbsp;</div>
</div>
@endsection
\ No newline at end of file
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<a class="navbar-brand" href="#">{{ __('Next Front System / ADMIN') }}</a> <a class="navbar-brand" href="#">{{ __('Next Front System / ADMIN') }}</a>
</div> </div>
<div class="collapse navbar-collapse" id="navbar-ex-collapse"> <div class="collapse navbar-collapse" id="navbar-ex-collapse">
@if(Auth::check())
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ __('メニュー') }} <i class="fa fa-caret-down"></i></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">{{ __('メニュー') }} <i class="fa fa-caret-down"></i></a>
...@@ -30,9 +31,10 @@ ...@@ -30,9 +31,10 @@
<a href="#" onfocus="javascript:blur();">|</a> <a href="#" onfocus="javascript:blur();">|</a>
</li> </li>
<li> <li>
<a href="#">{{ __('ログアウト') }}</a> <a href={{ route('logout') }}>{{ __('ログアウト') }}</a>
</li> </li>
</ul> </ul>
@endif
</div> </div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<div class="page-header"> <div class="page-header">
<h2>@yield('pageheader')</h2> <h2>@yield('pageheader')</h2>
</div> </div>
@include('flash::message')
</div> </div>
</div> </div>
@yield('content') @yield('content')
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
| |
*/ */
Route::get('/', function () { Route::get('login', 'LoginController@login')->name('login');
return view('welcome');
}); Route::post('login', 'LoginController@postlogin');
Route::get('logout', 'LoginController@logout')->name('logout');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment