注册登录退出
This commit is contained in:
parent
af1637641b
commit
dd15a65acd
|
|
@ -54,7 +54,8 @@ class Kernel extends HttpKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'admin_auth' => \App\Http\Middleware\Authenticate::class,
|
||||
'shop_auth' => \App\Http\Middleware\ShopAuthenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class ShopAuthenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
// 后台
|
||||
return shop_route('login.show');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ Route::prefix('admin')
|
|||
Route::get('login', [\Beike\Admin\Http\Controllers\LoginController::class, 'show'])->name('login.show');
|
||||
Route::post('login', [\Beike\Admin\Http\Controllers\LoginController::class, 'store'])->name('login.store');
|
||||
|
||||
Route::middleware('auth:'.\Beike\Models\AdminUser::AUTH_GUARD)
|
||||
Route::middleware('admin_auth:'.\Beike\Models\AdminUser::AUTH_GUARD)
|
||||
->group(function () {
|
||||
Route::get('/', [\Beike\Admin\Http\Controllers\HomeController::class, 'index'])->name('home.index');
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
|
|||
* @param mixed $params
|
||||
* @return string
|
||||
*/
|
||||
function admin_route($route, $params): string
|
||||
function admin_route($route, $params = []): string
|
||||
{
|
||||
return route('admin.' . $route, $params);
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ function admin_route($route, $params): string
|
|||
* @param mixed $params
|
||||
* @return string
|
||||
*/
|
||||
function shop_route($route, $params): string
|
||||
function shop_route($route, array $params = []): string
|
||||
{
|
||||
return route('shop.' . $route, $params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* AccountController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-23 20:22:54
|
||||
* @modified 2022-06-23 20:22:54
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Controllers\account;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use function auth;
|
||||
use function view;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$data = auth(Customer::AUTH_GUARD)->user()->toArray();
|
||||
return view('account', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -9,10 +9,15 @@
|
|||
* @modified 2022-06-22 20:22:54
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Controllers;
|
||||
namespace Beike\Shop\Http\Controllers\account;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use function auth;
|
||||
use function back;
|
||||
use function redirect;
|
||||
use function view;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
|
|
@ -29,7 +34,7 @@ class LoginController extends Controller
|
|||
]);
|
||||
|
||||
if (auth(Customer::AUTH_GUARD)->attempt($credentials)) {
|
||||
return redirect(route('home'));
|
||||
return redirect(shop_route('account.index'));
|
||||
}
|
||||
|
||||
return back()->withErrors([
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* LogoutController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-23 20:22:54
|
||||
* @modified 2022-06-23 20:22:54
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Controllers\account;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use function auth;
|
||||
use function back;
|
||||
use function redirect;
|
||||
use function view;
|
||||
|
||||
class LogoutController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect(shop_route('login.index'));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* LoginController.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author TL <mengwb@opencart.cn>
|
||||
* @created 2022-06-22 20:22:54
|
||||
* @modified 2022-06-22 20:22:54
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Http\Controllers\account;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Beike\Shop\Http\Requests\RegisterRequest;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use function redirect;
|
||||
use function view;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('register');
|
||||
}
|
||||
|
||||
public function store(RegisterRequest $request)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->name = $request->get('name', '');
|
||||
$customer->email = $request->get('email');
|
||||
$customer->customer_group_id = 0;
|
||||
$customer->language_id = 0;
|
||||
$customer->password = Hash::make($request->get('password'));
|
||||
$customer->save();
|
||||
|
||||
return redirect(shop_route('login.index'));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Beike\Shop\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RegisterRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 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:rfc,dns',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'email' => '邮箱地址',
|
||||
'password' => '密码'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -15,11 +15,15 @@ Route::prefix('/')
|
|||
|
||||
Route::get('products/{product}', [Beike\Shop\Http\Controllers\ProductController::class, 'show'])->name('products.show');
|
||||
|
||||
Route::get('login', [Beike\Shop\Http\Controllers\LoginController::class, 'index'])->name('login.index');
|
||||
Route::post('login', [Beike\Shop\Http\Controllers\LoginController::class, 'store'])->name('login.store');
|
||||
Route::get('login', [\Beike\Shop\Http\Controllers\account\LoginController::class, 'index'])->name('login.index');
|
||||
Route::post('login', [\Beike\Shop\Http\Controllers\account\LoginController::class, 'store'])->name('login.store');
|
||||
Route::get('register', [\Beike\Shop\Http\Controllers\account\RegisterController::class, 'index'])->name('register.index');
|
||||
Route::post('register', [\Beike\Shop\Http\Controllers\account\RegisterController::class, 'store'])->name('register.store');
|
||||
Route::get('logout', [\Beike\Shop\Http\Controllers\account\LogoutController::class, 'index'])->name('logout');
|
||||
|
||||
Route::middleware('auth:'.\Beike\Models\Customer::AUTH_GUARD)
|
||||
Route::middleware('shop_auth:'.\Beike\Models\Customer::AUTH_GUARD)
|
||||
->group(function () {
|
||||
Route::get('account', [\Beike\Shop\Http\Controllers\account\AccountController::class, 'index'])->name('account.index');
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ class CreateCustomerTable extends Migration
|
|||
$table->string('email')->unique();
|
||||
$table->string('password');
|
||||
$table->string('name');
|
||||
$table->string('avatar');
|
||||
$table->string('avatar')->default('');
|
||||
$table->unsignedInteger('customer_group_id');
|
||||
$table->unsignedInteger('language_id');
|
||||
$table->text('cart');
|
||||
$table->tinyInteger('status');
|
||||
$table->string('code', 40);
|
||||
$table->string('from', 16);
|
||||
$table->text('cart')->nullable();
|
||||
$table->tinyInteger('status')->default(0);
|
||||
$table->string('code', 40)->default('');
|
||||
$table->string('from', 16)->default('');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
@extends('layout.master')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Account</h1>
|
||||
尊敬的会员 {{ $email }}, 欢迎您回来。
|
||||
<br/>
|
||||
<br/>
|
||||
<a href="{{ route('shop.logout') }}">退出</a>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
@extends('layout.master')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Login</h1>
|
||||
<form action="{{ route('shop.login.store') }}" method="post">
|
||||
<form action="{{ route('shop.login.store') }}" method="post">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
|
|
@ -37,5 +38,5 @@
|
|||
|
||||
<button type="submit" class="btn btn-primary btn-block mb-4">登录</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
@extends('layout.master')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h1>Register</h1>
|
||||
<form action="{{ route('shop.register.store') }}" method="post">
|
||||
@csrf
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="email">邮箱</span>
|
||||
</div>
|
||||
<input type="text" name="email" class="form-control" value="{{ old('email') }}" placeholder="邮箱地址">
|
||||
</div>
|
||||
@error('email')
|
||||
<x-admin::form.error :message="$message"/>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="password">密码</span>
|
||||
</div>
|
||||
<input type="password" name="password" class="form-control" placeholder="密码">
|
||||
</div>
|
||||
@error('password')
|
||||
<x-admin::form.error :message="$message"/>
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
@if (session('error'))
|
||||
<div class="alert alert-success">
|
||||
{{ session('error') }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-block mb-4">登录</button>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
Loading…
Reference in New Issue