顾客登录

This commit is contained in:
TL 2022-06-23 18:11:29 +08:00
parent a7f97e7bd2
commit af1637641b
7 changed files with 195 additions and 0 deletions

15
beike/Models/Customer.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace Beike\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Customer extends Authenticatable
{
use HasFactory;
const AUTH_GUARD = 'web_shop';
protected $fillable = ['name', 'email', 'password', 'status'];
}

View File

@ -2,7 +2,12 @@
namespace Beike\Shop\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
class Controller extends \App\Http\Controllers\Controller
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@ -0,0 +1,39 @@
<?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;
use Beike\Models\Customer;
use Illuminate\Http\Request;
class LoginController extends Controller
{
public function index()
{
return view('login');
}
public function store(Request $request)
{
$credentials = $request->validate([
'email' => ['required', 'email'],
'password' => ['required'],
]);
if (auth(Customer::AUTH_GUARD)->attempt($credentials)) {
return redirect(route('home'));
}
return back()->withErrors([
'email' => 'The provided credentials do not match our records.',
]);
}
}

View File

@ -2,7 +2,9 @@
namespace Beike\Shop\Providers;
use Beike\Models\Customer;
use Beike\Models\Setting;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
@ -22,6 +24,7 @@ class ShopServiceProvider extends ServiceProvider
$this->mergeConfigFrom(__DIR__ . '/../../Config/beike.php', 'beike');
$this->loadSettings();
$this->loadShareView();
$this->registerGuard();
}
protected function loadSettings()
@ -43,4 +46,17 @@ class ShopServiceProvider extends ServiceProvider
$menuCategories = CategoryRepo::getTwoLevelCategories();
View::share('categories', $menuCategories);
}
protected function registerGuard()
{
Config::set('auth.guards.'.Customer::AUTH_GUARD, [
'driver' => 'session',
'provider' => 'shop_customer',
]);
Config::set('auth.providers.shop_customer', [
'driver' => 'eloquent',
'model' => Customer::class,
]);
}
}

View File

@ -14,4 +14,12 @@ Route::prefix('/')
Route::get('categories/{category}', [Beike\Shop\Http\Controllers\CategoryController::class, 'show'])->name('categories.show');
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::middleware('auth:'.\Beike\Models\Customer::AUTH_GUARD)
->group(function () {
});
});

View File

@ -0,0 +1,71 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCustomerTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->string('email')->unique();
$table->string('password');
$table->string('name');
$table->string('avatar');
$table->unsignedInteger('customer_group_id');
$table->unsignedInteger('language_id');
$table->text('cart');
$table->tinyInteger('status');
$table->string('code', 40);
$table->string('from', 16);
$table->timestamps();
});
Schema::create('customer_groups', function (Blueprint $table) {
$table->id();
$table->decimal('total', 12, 4);
$table->decimal('reward_point_factor', 12, 4);
$table->decimal('use_point_factor', 12, 4);
$table->decimal('discount_factor', 12, 4);
$table->integer('level');
$table->timestamps();
});
Schema::create('customer_group_descriptions', function (Blueprint $table) {
$table->id();
$table->unsignedInteger('customer_group_id');
$table->unsignedInteger('language_id');
$table->string('name', 256);
$table->text('description');
$table->timestamps();
});
// Schema::create('customer_spending', function (Blueprint $table) {
// $table->id();
// $table->unsignedInteger('customer_id');
// $table->unsignedInteger('order_id');
// $table->string('order_number', 32);
// $table->decimal('total', 12, 4);
// $table->timestamps();
// });
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customers');
Schema::dropIfExists('customer_groups');
Schema::dropIfExists('customer_group_descriptions');
}
}

View File

@ -0,0 +1,41 @@
@extends('layout.master')
@section('content')
<h1>Login</h1>
<form action="{{ route('shop.login.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>
@endsection