datagrid mass action complete, customer packagge guard working, guards now defined in main auth.php file

This commit is contained in:
prashant-webkul 2018-07-24 20:03:49 +05:30
parent 072990f6ed
commit 951266a100
18 changed files with 310 additions and 75 deletions

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomersAddressTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customers_address', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customers_address');
}
}

View File

@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomersGroupTable extends Migration
class CreateCustomerGroupsTable extends Migration
{
/**
* Run the migrations.
@ -13,8 +13,9 @@ class CreateCustomersGroupTable extends Migration
*/
public function up()
{
Schema::create('customers_group', function (Blueprint $table) {
Schema::create('customer_groups', function (Blueprint $table) {
$table->increments('id');
$table->string('group_name');
$table->timestamps();
});
}
@ -26,6 +27,6 @@ class CreateCustomersGroupTable extends Migration
*/
public function down()
{
Schema::dropIfExists('customers_group');
Schema::dropIfExists('customer_groups');
}
}

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomerAddressesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_addresses', function (Blueprint $table) {
$table->increments('id');
$table->string('street');
$table->string('address1');
$table->string('address2');
$table->string('country');
$table->string('state');
$table->string('city');
$table->integer('pincode');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer_addresses');
}
}

View File

@ -15,6 +15,14 @@ class CreateCustomersTable extends Migration
{
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('email');
$table->string('password');
$table->integer('customer_group_id')->unsigned()->nullable();
$table->integer('address_id')->unsigned()->nullable();
$table->foreign('customer_group_id')->references('id')->on('customer_groups')->onDelete('cascade');
$table->foreign('address_id')->references('id')->on('customer_addresses')->onDelete('cascade');
$table->timestamps();
});
}

View File

@ -0,0 +1,13 @@
<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

View File

@ -7,7 +7,10 @@ use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
/**
* Dashboard controller
* Customer controlller for the customer
* basically for the tasks of customers
* which will be done after customer
* authenticastion.
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
@ -25,17 +28,14 @@ class CustomerController extends Controller
{
$this->_config = request('_config');
}
public function index()
{
return view('customer::login.index');
}
public function login()
{
return view($this->_config['view']);
}
public function signup()
/**
* For taking the customer
* to the dashboard after
* authentication
* @return view
*/
public function dashboard()
{
return view($this->_config['view']);
}

View File

@ -0,0 +1,67 @@
<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Webkul\Customer\Models\Customer;
/**
* Dashboard controller
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class RegistrationController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
protected $_config;
public function __construct()
{
$this->_config = request('_config');
}
/**
* For showing the registration form
* @return view
*/
public function show()
{
return view($this->_config['view']);
}
/**
* For collecting the registration
* data from the registraion form
* @return view
*/
public function create(Request $request)
{
// return $request->except('_token'); //don't let csrf token to be openly printed
$request->validate([
'first_name' => 'string|required',
'last_name' => 'string|required',
'email' => 'email|required',
'password' => 'confirmed|min:8|required'
]);
$customer = new \Webkul\Customer\Models\Customer();
$customer->first_name = $request->first_name;
$customer->last_name = $request->last_name;
$customer->email = $request->email;
$customer->password = bcrypt($request->password);
// dd('hello1');
if ($customer->save()) {
session()->flash('success', 'Account created successfully.');
return redirect()->route($this->_config['redirect']);
} else {
session()->flash('error', 'Cannot Create Your Account.');
return redirect()->back();
}
}
}

View File

@ -0,0 +1,58 @@
<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Webkul\Customer\Models\Customer;
/**
* Session controller for the user customer
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class SessionController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
protected $_config;
public function __construct()
{
$this->_config = request('_config');
}
public function show()
{
return view($this->_config['view']);
}
public function create(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required'
]);
// $remember = request('remember');
if (!auth()->guard('customer')->attempt(request(['email', 'password']))) {
dd('cannot be authorized');
session()->flash('error', 'Please check your credentials and try again.');
return back();
}
return redirect()->route($this->_config['redirect']);
}
public function destroy($id)
{
auth()->guard('customer')->logout();
return redirect()->route($this->_config['redirect']);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Webkul\User\Http\Middleware;
namespace Webkul\Customer\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
@ -18,7 +18,7 @@ class RedirectIfNotCustomer
public function handle($request, Closure $next, $guard = 'customer')
{
if (! Auth::guard($guard)->check()) {
return redirect()->route('admin.login');
return redirect()->route('customer.session.index');
}
return $next($request);

View File

@ -2,20 +2,38 @@
Route::group(['middleware' => ['web']], function () {
Route::prefix('customer')->group(function () {
// Login Routes
Route::get('/login', 'Webkul\Customer\Http\Controllers\CustomerController@login')->defaults('_config', [
'view' => 'customer::login.index'
])->name('customer.login');
Route::get('/register', 'Webkul\Customer\Http\Controllers\CustomerController@signup')->defaults('_config', [
'view' => 'customer::signup.index'
])->name('customer.register');
// Login Routes
Route::get('/login', 'Webkul\Customer\Http\Controllers\SessionController@show')->defaults('_config', [
'view' => 'customer::login.index',
])->name('customer.session.index');
Route::post('/login', 'Webkul\Customer\Http\Controllers\SessionController@create')->defaults('_config', [
'redirect' => 'customer.dashboard.index'
])->name('customer.session.create');
// Registration Routes
Route::get('/register', 'Webkul\Customer\Http\Controllers\RegistrationController@show')->defaults('_config', [
'view' => 'customer::signup.index' //hint path
])->name('customer.register.index');
Route::post('/register', 'Webkul\Customer\Http\Controllers\RegistrationController@create')->defaults('_config', [
'redirect' => 'customer.dashboard.index',
])->name('customer.register.create');
// Auth Routes
Route::group(['middleware' => ['customer']], function () {
Route::get('/logout', 'Webkul\Customer\Http\Controllers\CustomerController@logout')->defaults('_config', [
//route for logout which will be under the auth guard of the customer by default
Route::get('/logout', 'Webkul\Customer\Http\Controllers\SessionController@logout')->defaults('_config', [
'redirect' => 'customer.session.index'
])->name('customer.session.destroy');
//customer dashboard
Route::get('/dashboard', 'Webkul\Customer\Http\Controllers\CustomerController@dashboard')->defaults('_config', [
'view' => 'customer::dashboard.index'
])->name('customer.dashboard.index');
});
});
});

View File

@ -1,9 +1,18 @@
<?php
namespace Webkul\Customer\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Customer extends Model
// use Webkul\User\Notifications\AdminResetPassword;
// use Webkul\User\Notifications\AdminResetPassword;
class Customer extends Authenticatable
{
use Notifiable;
protected $table = 'customers';
}

View File

@ -5,5 +5,5 @@ use Illuminate\Database\Eloquent\Model;
class CustomersGroups extends Model
{
protected $table = 'customers_group';
protected $table = 'customer_groups';
}

View File

@ -5,5 +5,5 @@ use Illuminate\Database\Eloquent\Model;
class CustomersAddress extends Model
{
protected $table = 'customers_address';
protected $table = 'customer_addresses';
}

View File

@ -5,8 +5,8 @@ namespace Webkul\Customer\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Blade;
use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer;
use Webkul\Admin\Providers\EventServiceProvider;
// use Webkul\Admin\Providers\ComposerServiceProvider;
@ -23,7 +23,7 @@ class CustomerServiceProvider extends ServiceProvider
$router->aliasMiddleware('customer', RedirectIfNotCustomer::class);
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->loadMigrationsFrom(__DIR__ . '/../Database/migrations');
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'customer');
}

View File

@ -64,3 +64,44 @@
}
}
}
.dashboard-content {
width: 100%;
margin-top: 5.5%;
margin-bottom: 5.5%;
.dashboard-side-menu {
display: flex;
flex-direction: column;
align-content: center;
justify-content: center;
border: 1px solid #e8e8e8;
border-right: none;
background: #ffffff;
width: 25%;
text-transform: capitalize;
li {
font-size: 16px;
width: 95%;
height: 50px;
margin-left: 15px;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
border: 1px solid $border-color;
border-left: none;
border-bottom: none;
text-align: center;
}
li:first-child {
border-top: none;
border-left: none;
border-bottom: none;
}
li:last-child {
border-bottom: none;
}
}
}

View File

@ -0,0 +1,12 @@
@extends('customer::layouts.master')
@section('content-wrapper')
<div class="dashboard-content">
<ul class="dashboard-side-menu">
<li>Profile</li>
<li>Orders</li>
<li>Address</li>
<li>Reviews</li>
<li>Wishlist</li>
</ul>
</div>
@endsection

View File

@ -2,9 +2,10 @@
@section('content-wrapper')
<div class="content">
<div class="sign-up-text">
Don't have account - <a href="{{ route('customer.register') }}">Sign Up</a>
Don't have account - <a href="{{ route('customer.register.index') }}">Sign Up</a>
</div>
<form>
<form method="POST" action="{{ route('customer.session.create') }}">
{{ csrf_field() }}
<div class="login-form">
<div class="login-text">Sign In</div>
<div class="control-group">
@ -12,8 +13,8 @@
<input type="text" class="control" name="email">
</div>
<div class="control-group">
<label for="email">Password</label>
<input type="password" class="control" name="email">
<label for="password">Password</label>
<input type="password" class="control" name="password">
</div>
<div class="forgot-password-link">
<a href="">Forgot Password?</a>

View File

@ -2,18 +2,19 @@
@section('content-wrapper')
<div class="content">
<div class="sign-up-text">
Already have an account - <a href="{{ route('customer.login') }}">Sign In</a>
Already have an account - <a href="{{ route('customer.session.index') }}">Sign In</a>
</div>
<form>
<form method="post" action="{{ route('customer.register.create') }}">
{{ csrf_field() }}
<div class="login-form">
<div class="login-text">Sign Up</div>
<div class="control-group">
<label for="email">First Name</label>
<input type="text" class="control" name="email">
<input type="text" class="control" name="first_name">
</div>
<div class="control-group">
<label for="email">Last Name</label>
<input type="text" class="control" name="email">
<input type="text" class="control" name="last_name">
</div>
<div class="control-group">
<label for="email">Email</label>
@ -21,21 +22,20 @@
</div>
<div class="control-group">
<label for="email">Password</label>
<input type="password" class="control" name="email">
<input type="password" class="control" name="password">
</div>
<div class="control-group">
<label for="email">Confirm Password</label>
<input type="password" class="control" name="email">
<input type="password" class="control" name="confirm_password">
</div>
<div class="signup-confirm">
<span class="checkbox">
<input type="checkbox" id="checkbox2" name="checkbox[]">
<label class="checkbox-view" for="checkbox2"></label>
<span>Agree <a href="">Terms</a> & <a href="">Conditions</a> by using this website.</span>
<input type="checkbox" id="checkbox2" name="agreement" required>
<label class="checkbox-view" for="checkbox2"></label>
<span>Agree <a href="">Terms</a> & <a href="">Conditions</a> by using this website.</span>
</span>
</div>
<input class="btn btn-primary btn-lg" type="submit" value="sign in">
</div>
</form>