完成接案者登入功能
This commit is contained in:
parent
552154f629
commit
7e9bbe282a
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
use App\Receiver;
|
||||
|
||||
class ReceiverController extends Controller
|
||||
@ -14,7 +14,7 @@ class ReceiverController extends Controller
|
||||
|
||||
public function loginProcess()
|
||||
{
|
||||
$input = $request->all();
|
||||
$input = request()->all();
|
||||
|
||||
//輸入資料驗證
|
||||
$rules = [
|
||||
@ -29,11 +29,27 @@ class ReceiverController extends Controller
|
||||
];
|
||||
$validate = Validator::make($input,$rules);
|
||||
if($validate->fails()){
|
||||
return redirect('/receiver/loginPage')
|
||||
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
|
||||
//failed -> 導向至登入畫面(附帶錯誤訊息)
|
||||
/* $record = [
|
||||
'user_id'=>$User->RID,
|
||||
'role_id'=>'Receiver'
|
||||
]; */
|
||||
//session()->put($record);
|
||||
session()->put('user_id',$User->RID);
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
|
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,9 +1,6 @@
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
@if(session()->has('receiver_id'))
|
||||
<li class="nav-item">
|
||||
<span>{{$UserName}},您好</span>
|
||||
</li>
|
||||
@if(session()->has('user_id'))
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/receiver/logout">登出</a>
|
||||
</li>
|
||||
|
@ -3,16 +3,19 @@
|
||||
@section('title','KOL登入')
|
||||
|
||||
@section('content')
|
||||
|
||||
@include('components.validationErrorMsg')
|
||||
<form action="" method="POST">
|
||||
<div class="form-group">
|
||||
<label for="InputEmail1">帳號</label>
|
||||
<input type="email" name="ID" class="form-control" id="InputEmail1" aria-describedby="emailHelp" placeholder="請輸入電子郵件地址">
|
||||
<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" class="form-control" id="InputPassword1" placeholder="請輸入密碼">
|
||||
<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
|
@ -28,7 +28,7 @@ Route::get('/', 'HomeController@index');
|
||||
//接案者相關url
|
||||
Route::group(['prefix' => 'receiver'], function () {
|
||||
Route::get('/login', 'ReceiverController@loginPage');
|
||||
//Route::post('/login', 'ReceiverController@loginProcess');
|
||||
Route::post('/login', 'ReceiverController@loginProcess');
|
||||
// Route::get('/register', '');
|
||||
// Route::post('/register', '');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user