forked from kol/BlogMatch
Merge branch 'feature/LoginAuthentication' into develop
This commit is contained in:
commit
167427381f
42
app/Admin.php
Normal file
42
app/Admin.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
* Date: Sun, 29 Jul 2018 08:54:26 +0000.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Admin
|
||||||
|
*
|
||||||
|
* @property string $ID
|
||||||
|
* @property string $password
|
||||||
|
* @property string $name
|
||||||
|
* @property string $nick_name
|
||||||
|
* @property string $phone_number
|
||||||
|
* @property \Carbon\Carbon $created_at
|
||||||
|
* @property \Carbon\Carbon $updated_at
|
||||||
|
*
|
||||||
|
* @package App
|
||||||
|
*/
|
||||||
|
class Admin extends Eloquent
|
||||||
|
{
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
protected $table = 'admin';
|
||||||
|
protected $primaryKey = 'ID';
|
||||||
|
public $incrementing = false;
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'password'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'password',
|
||||||
|
'name',
|
||||||
|
'nick_name',
|
||||||
|
'phone_number'
|
||||||
|
];
|
||||||
|
}
|
10
app/Exceptions/UserNotFoundException.php
Normal file
10
app/Exceptions/UserNotFoundException.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class UserNotFoundException extends Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
65
app/Http/Controllers/ReceiverController.php
Normal file
65
app/Http/Controllers/ReceiverController.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Validator;
|
||||||
|
use App\Receiver;
|
||||||
|
|
||||||
|
class ReceiverController extends Controller
|
||||||
|
{
|
||||||
|
public function loginPage()
|
||||||
|
{
|
||||||
|
return view('receiver.login');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loginProcess()
|
||||||
|
{
|
||||||
|
$input = request()->all();
|
||||||
|
|
||||||
|
//輸入資料驗證
|
||||||
|
$rules = [
|
||||||
|
'email'=>[
|
||||||
|
'required',
|
||||||
|
'email',
|
||||||
|
],
|
||||||
|
'password'=>[
|
||||||
|
'required',
|
||||||
|
'min:6'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$validate = Validator::make($input,$rules);
|
||||||
|
if($validate->fails()){
|
||||||
|
return redirect('/receiver/login')
|
||||||
|
->withErrors($validate)->withInput();
|
||||||
|
}
|
||||||
|
//驗證通過,巷資料庫查詢使用者是否存在
|
||||||
|
$User = Receiver::where('email',$input['email'])->firstOrFail();
|
||||||
|
$isPasswordCorrect = $input['password'] == $User->password;
|
||||||
|
if(!$isPasswordCorrect){
|
||||||
|
//failed -> 導向至登入畫面(附帶錯誤訊息)
|
||||||
|
$error_msg = [
|
||||||
|
'msg'=>['密碼錯誤']
|
||||||
|
];
|
||||||
|
return redirect('/receiver/login')->withErrors($error_msg)
|
||||||
|
->withInput();
|
||||||
|
}
|
||||||
|
//Pass->紀錄session
|
||||||
|
/* $record = [
|
||||||
|
'user_id'=>$User->RID,
|
||||||
|
'role_id'=>'Receiver'
|
||||||
|
]; */
|
||||||
|
//session()->put($record);
|
||||||
|
// $binds = [
|
||||||
|
// 'name'=>$User->nickname
|
||||||
|
// ];
|
||||||
|
// $name = $User->nickname;
|
||||||
|
session()->put('user_id',$User->RID);
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
session()->forget('user_id');
|
||||||
|
return redirect('/');
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@ -13,7 +14,7 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
//
|
Schema::defaultStringLength(191);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
36
database/migrations/2018_07_29_083103_create_admin_table.php
Normal file
36
database/migrations/2018_07_29_083103_create_admin_table.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateAdminTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('admin', function (Blueprint $table) {
|
||||||
|
$table->string('ID');
|
||||||
|
$table->string('password');
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('nick_name');
|
||||||
|
$table->string('phone_number');
|
||||||
|
$table->primary('ID');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('admin');
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
// $this->call(UsersTableSeeder::class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
resources/views/components/validationErrorMsg.blade.php
Normal file
10
resources/views/components/validationErrorMsg.blade.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
<div class=" alert alert-danger" role="alert">
|
||||||
|
<ul>
|
||||||
|
@if($errors AND count($errors))
|
||||||
|
@foreach($errors->all() as $err)
|
||||||
|
<li>{{$err}}</li>
|
||||||
|
@endForeach
|
||||||
|
@endif
|
||||||
|
</ul>
|
||||||
|
</div>
|
@ -1,5 +1,7 @@
|
|||||||
@extends('layout.app')
|
@extends('layout.app')
|
||||||
|
|
||||||
|
@section('title','部落客媒合系統')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<button class="btn btn-primary">我想成為KOL</button>
|
<button class="btn btn-primary">我想成為KOL</button>
|
||||||
<button class="btn btn-primary">我想成為品牌/代理商</button>
|
<button class="btn btn-primary">我想成為品牌/代理商</button>
|
||||||
|
@ -4,30 +4,17 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
<title>部落客媒合系統</title>
|
<title>@yield('title')</title>
|
||||||
<link rel="stylesheet" href="/css/app.css">
|
<link rel="stylesheet" href="/css/app.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
<a class="navbar-brand" href="#">部落客媒合系統</a>
|
<a class="navbar-brand" href="/">部落客媒合系統</a>
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
|
@include('layout.navbar')
|
||||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
|
||||||
<ul class="navbar-nav ml-auto">
|
|
||||||
<li class="nav-item active">
|
|
||||||
<a class="nav-link" href="#">KOL登入<span class="sr-only">(current)</span></a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#">品牌/代理商登入</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#">後台登入</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
</nav>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
@yield('content')
|
@yield('content')
|
||||||
|
24
resources/views/layout/login.blade.php
Normal file
24
resources/views/layout/login.blade.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>@yield('title')</title>
|
||||||
|
<link rel="stylesheet" href="/css/app.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
<a class="navbar-brand" href="/">部落客媒合系統</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
<div class="mt-3">
|
||||||
|
@yield('content')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="/js/app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
22
resources/views/layout/navbar.blade.php
Normal file
22
resources/views/layout/navbar.blade.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||||
|
<ul class="navbar-nav ml-auto">
|
||||||
|
@if(session()->has('user_id'))
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">{{session()->get('user_id')}},您好</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="/receiver/logout">登出</a>
|
||||||
|
</li>
|
||||||
|
@else
|
||||||
|
<li class="nav-item active">
|
||||||
|
<a class="nav-link" href="/receiver/login">KOL登入<span class="sr-only">(current)</span></a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">品牌/代理商登入</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="#">後台登入</a>
|
||||||
|
</li>
|
||||||
|
@endif
|
||||||
|
</ul>
|
||||||
|
</div>
|
21
resources/views/receiver/login.blade.php
Normal file
21
resources/views/receiver/login.blade.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
@extends('layout.login')
|
||||||
|
|
||||||
|
@section('title','KOL登入')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
@include('components.validationErrorMsg')
|
||||||
|
<form action="" method="POST">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="InputEmail1">帳號</label>
|
||||||
|
<input type="email" name="email" value="{{old('email')}}" class="form-control" id="InputEmail1" aria-describedby="emailHelp" placeholder="請輸入電子郵件地址">
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="InputPassword1">密碼</label>
|
||||||
|
<input type="password" name="password" value="{{old('password')}}" class="form-control" id="InputPassword1" placeholder="請輸入密碼">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg">登入</button>
|
||||||
|
<input type="button" class="btn btn-default btn-lg" value="取消">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
</form>
|
||||||
|
@endsection
|
@ -25,13 +25,14 @@ Route::get('/', 'HomeController@index');
|
|||||||
// Route::get('/dashbord', '');
|
// Route::get('/dashbord', '');
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// //接案者相關url
|
//接案者相關url
|
||||||
// Route::group(['prefix' => 'receiver'], function () {
|
Route::group(['prefix' => 'receiver'], function () {
|
||||||
// Route::get('/login', '');
|
Route::get('/login', 'ReceiverController@loginPage');
|
||||||
// Route::post('/login', '');
|
Route::post('/login', 'ReceiverController@loginProcess');
|
||||||
// Route::get('/register', '');
|
Route::get('/logout','ReceiverController@logout');
|
||||||
// Route::post('/register', '');
|
// Route::get('/register', '');
|
||||||
// });
|
// Route::post('/register', '');
|
||||||
|
});
|
||||||
//
|
//
|
||||||
// //發案者相關url
|
// //發案者相關url
|
||||||
// Route::group(['prefix' => 'casebuilder'], function () {
|
// Route::group(['prefix' => 'casebuilder'], function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user