Bug Fixes

This commit is contained in:
prashant-webkul 2018-11-21 11:59:18 +05:30
parent ab9328d755
commit 662ff09a24
18 changed files with 290 additions and 330 deletions

View File

@ -21,8 +21,7 @@
"laravel/tinker": "^1.0",
"nwidart/laravel-modules": "^3.2",
"prettus/l5-repository": "^2.6",
"propaganistas/laravel-intl": "^2.0",
"tymon/jwt-auth": "dev-develop"
"propaganistas/laravel-intl": "^2.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.1",

View File

@ -199,7 +199,6 @@ return [
Konekt\Concord\ConcordServiceProvider::class,
Flynsarmy\DbBladeCompiler\DbBladeCompilerServiceProvider::class,
Barryvdh\DomPDF\ServiceProvider::class,
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
//Webkul packages
Webkul\Theme\Providers\ThemeServiceProvider::class,
@ -274,6 +273,5 @@ return [
'Core' => Webkul\Core\Facades\Core::class,
'DbView' => Flynsarmy\DbBladeCompiler\Facades\DbView::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
],
];

View File

@ -13,7 +13,7 @@ return [
],
'api' => [
'driver' => 'jwt',
'driver' => 'token',
'provider' => 'customers',
],
@ -28,7 +28,7 @@ return [
],
'admin-api' => [
'driver' => 'jwt',
'driver' => 'token',
'provider' => 'admins',
]
],

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateAdminOauthTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_oauth_tokens', function (Blueprint $table) {
$table->increments('id');
$table->integer('admin_id')->unsigned();
$table->foreign('admin_id')->references('id')->on('admins');
$table->integer('throttle')->default(0)->unsigned();
$table->mediumText('api_token')->nullable();
$table->string('token_name')->nullable();
$table->dateTime('ttl');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admin_oauth_tokens');
}
}

View File

@ -1,37 +0,0 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCustomerOauthTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customer_oauth_tokens', function (Blueprint $table) {
$table->increments('id');
$table->integer('customer_id')->unsigned();
$table->foreign('customer_id')->references('id')->on('customers');
$table->integer('throttle')->default(0)->unsigned();
$table->mediumText('api_token')->nullable();
$table->string('token_name')->nullable();
$table->dateTime('ttl');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customer_oauth_tokens');
}
}

View File

@ -1,103 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Admin;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Webkul\User\Repositories\AdminRepository;
/**
* Session controller for the APIs of user admins
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AuthController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
protected $_config;
public function __construct()
{
$this->middleware('admin')->except(['show','create']);
$this->_config = request('_config');
}
public function create(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required'
]);
$credentials['email'] = $request->input('email');
$credentials['password'] = $request->input('password');
if ($token = $this->guard()->attempt(request(['email', 'password']))) {
return $this->respondWithToken($token);
}
return response()->json(['error' => 'Unauthorized'], 401);
}
/**
* Get the token array structure.
*
* @param string $token
*
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60,
'admin_id' => auth()->guard('admin-api')->user()->id,
'admin_email' => auth()->guard('admin-api')->user()->email
]);
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\Guard
*/
public function guard()
{
return auth()->guard('admin-api');
}
/**
* Refresh a token.
*
* @return \Illuminate\Http\JsonResponse
*/
public function refresh()
{
return $this->respondWithToken($this->guard()->refresh());
}
/**
* Get the authenticated User
*
* @return \Illuminate\Http\JsonResponse
*/
public function me()
{
return response()->json($this->guard()->user());
}
public function destroy($id)
{
$this->guard()->logout();
return response()->json(['message' => 'Successfully logged out']);
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Auth;
use Cart;
/**
* Address controller for the APIs Customer Address
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AddressController extends Controller
{
protected $customer;
public function __construct()
{
if(auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
return response()->json('Unauthorized', 401);
}
}
/**
* To get the details of user to display on profile
*
* @return response JSON
*/
public function getAddress() {
$addresses = $this->customer->addresses;
return response()->json($addresses, 200);
}
public function getDefaultAddress() {
$defaultAddress = $this->customer->default_address;
if($defaultAddress->count() > 0)
return response()->json($defaultAddress, 200);
else
return response()->json(false, 200);
}
}

View File

@ -6,7 +6,7 @@ use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Webkul\Customer\Http\Listeners\CustomerEventsHandler;
// use Webkul\Customer\Http\Listeners\CustomerEventsHandler;
use Auth;
use Cart;
@ -18,93 +18,26 @@ use Cart;
*/
class AuthController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
protected $_config;
public function __construct()
{
$this->middleware('customer')->except(['show','create']);
$this->_config = request('_config');
$subscriber = new CustomerEventsHandler;
Event::subscribe($subscriber);
// $this->middleware('customer')->except(['show','create']);
// $this->_config = request('_config');
// $subscriber = new CustomerEventsHandler;
// Event::subscribe($subscriber);
}
public function create(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required'
]);
/**
* To get the details of user to display on profile
*
* @return response JSON
*/
public function create() {
$data = request()->except('_token');
$credentials['email'] = $request->input('email');
$credentials['password'] = $request->input('password');
if ($token = $this->guard()->attempt(request(['email', 'password']))) {
return $this->respondWithToken($token);
if(!auth()->guard('customer')->attempt($data)) {
return response()->json('Incorrect Credentials', 200);
} else {
return response()->json(auth()->guard('customer')->user(), 200);
}
return response()->json(['error' => 'Unauthorized'], 401);
}
/**
* Get the token array structure.
*
* @param string $token
*
* @return \Illuminate\Http\JsonResponse
*/
protected function respondWithToken($token)
{
return response()->json([
'access_token' => $token,
'token_type' => 'bearer',
'expires_in' => auth('api')->factory()->getTTL() * 60,
'customer_id' => auth()->guard('customer')->user()->id,
'customer_email' => auth()->guard('customer')->user()->email
]);
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\Guard
*/
public function guard()
{
return Auth::guard('api');
}
/**
* Refresh a token.
*
* @return \Illuminate\Http\JsonResponse
*/
public function refresh()
{
return $this->respondWithToken($this->guard()->refresh());
}
/**
* Get the authenticated User
*
* @return \Illuminate\Http\JsonResponse
*/
public function me()
{
return response()->json($this->guard()->user());
}
public function destroy($id)
{
$this->guard()->logout();
return response()->json(['message' => 'Successfully logged out']);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Auth;
use Cart;
/**
* Customer controller for the APIs of Profile customer
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CustomerController extends Controller
{
protected $customer;
public function __construct()
{
if(auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
return response()->json('Unauthorized', 401);
}
}
/**
* To get the details of user to display on profile
*
* @return response JSON
*/
public function getProfile() {
return $this->customer;
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Auth;
use Cart;
/**
* Wishlist controller for the APIs of User's Wishlist
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class WishlistController extends Controller
{
protected $customer;
public function __construct()
{
if(auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
return response()->json('Unauthorized', 401);
}
}
public function getWishlist()
{
$wishlist = $this->customer->wishlist_items;
if($wishlist->count() > 0) {
return response()->json($wishlist, 200);
} else {
return response()->json('Wishlist Empty', 200);
}
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace Webkul\API\Http\Controllers\Product;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
use Auth;
/**
* Product controller for the APIs of Getting Products
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductController extends Controller
{
protected $product;
public function __construct(Product $product)
{
$this->product = $product;
}
public function getAllProducts() {
$products = $this->product->all();
return response()->json($products, 200);
}
public function getNewProducts() {
$newProducts = $this->product->getNewProduct();
return response()->json($newProducts, 200);
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Auth;
// use Cart;
use Webkul\Checkout\Repositories\CartRepository;
/**
* Cart controller for the APIs of User Cart
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartController extends Controller
{
protected $customer;
protected $cart;
public function __construct(CartRepository $cart)
{
$this->cart = $cart;
if(auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
return response()->json('Unauthorized', 401);
}
}
public function getAllCart() {
$carts = $this->customer->carts;
if($cart->count() > 0) {
return response()->json($cart, 200);
} else {
return response()->json('Cart Empty', 200);
}
}
public function getActiveCart() {
return $this->customer->cart;
}
}

View File

@ -1,15 +1,39 @@
<?php
Route::group(['middleware' => 'api', 'namespace' => 'Webkul\API\Http\Controllers', 'prefix' => 'api/customer'], function ($router) {
Route::post('login', 'Customer\AuthController@create');
Route::post('logout', 'Customer\AuthController@destroy');
Route::post('refresh', 'Customer\AuthController@refresh');
Route::post('me', 'Customer\AuthController@me');
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => 'api/customer'], function ($router) {
//auth route for customer
Route::post('login', 'AuthController@create');
//get user
Route::get('get/user', 'CustomerController@getProfile');
//wishlist
Route::get('get/wishlist', 'WishlistController@getWishlist');
//address
Route::get('get/address', 'AddressController@getAddress');
Route::get('get/default/address', 'AddressController@getDefaultAddress');
});
Route::group(['namespace' => 'Webkul\API\Http\Controllers', 'prefix' => 'api/admin'], function ($router) {
Route::post('login', 'Admin\AuthController@create');
Route::post('logout', 'Admin\AuthController@destroy');
Route::post('refresh', 'Admin\AuthController@refresh');
Route::post('me', 'Admin\AuthController@me');
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/cart'], function ($router) {
//cart
//active + inactive instances of cart for the current logged in user
Route::get('get/all', 'CartController@getAllCart');
//active instances of cart for the current logged in user
Route::get('get/active', 'CartController@getActiveCart');
//inactive instances of cart for the current logged in user
Route::get('get/inactive', 'CartController@getInactiveCart');
});
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Product', 'prefix' => 'api/product'], function ($router) {
//product
//to fetch the new product
Route::get('get/all', 'ProductController@getAllProducts');
});
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Admin', 'prefix' => 'api/admin'], function ($router) {
});

View File

@ -2,8 +2,6 @@
Route::group(['middleware' => ['web']], function () {
Route::prefix('admin')->group(function () {
Route::get('/grid', 'Webkul\Product\Http\Controllers\ProductController@test');
// Login Routes
Route::get('/login', 'Webkul\User\Http\Controllers\SessionController@create')->defaults('_config', [
'view' => 'admin::users.sessions.create'
@ -13,7 +11,6 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.dashboard.index'
])->name('admin.session.store');
// Forget Password Routes
Route::get('/forget-password', 'Webkul\User\Http\Controllers\ForgetPasswordController@create')->defaults('_config', [
'view' => 'admin::users.forget-password.create'
@ -30,7 +27,6 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.dashboard.index'
])->name('admin.reset-password.store');
// Admin Routes
Route::group(['middleware' => ['admin']], function () {
Route::get('/logout', 'Webkul\User\Http\Controllers\SessionController@destroy')->defaults('_config', [
@ -445,6 +441,22 @@ Route::group(['middleware' => ['web']], function () {
Route::put('/account', 'Webkul\User\Http\Controllers\AccountController@update')->name('admin.account.update');
//API Authorizations
Route::get('/api/clients', 'Webkul\Admin\Http\Controllers\AuthorizationController@show')->defaults('_config', [
'view' => 'admin::apiauth.client'
])->name('admin.index.oauth.client');
//view an OAuth API Client
Route::get('/api/clients/view/{id}', 'Webkul\Admin\Http\Controllers\AuthorizationController@view')->defaults('_config', [
'view' => 'admin::apiauth.view'
])->name('admin.view.oauth.client');
//edit an OAuth API Client
Route::get('/api/clients/delete/{id}', 'Webkul\Admin\Http\Controllers\AuthorizationController@delete')->defaults('_config', [
'view' => 'admin::apiauth.edit'
])->name('admin.delete.oauth.client');
// Admin Store Front Settings Route
//slider index
Route::get('/slider','Webkul\Shop\Http\Controllers\SliderController@index')->defaults('_config',[

View File

@ -1,8 +1,8 @@
const { mix } = require("laravel-mix");
require("laravel-mix-merge-manifest");
var publicPath = 'publishable/assets';
// var publicPath = "../../../public/vendor/webkul/admin/assets";
// var publicPath = 'publishable/assets';
var publicPath = "../../../public/vendor/webkul/admin/assets";
mix.setPublicPath(publicPath).mergeManifest();
mix.disableNotifications();

View File

@ -2,7 +2,6 @@
namespace Webkul\Customer\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Webkul\Customer\Models\CustomerGroup;
@ -11,8 +10,7 @@ use Webkul\Sales\Models\Order;
use Webkul\Customer\Models\Wishlist;
use Webkul\Customer\Notifications\CustomerResetPassword;
class Customer extends Authenticatable implements JWTSubject
class Customer extends Authenticatable
{
use Notifiable;
@ -22,26 +20,6 @@ class Customer extends Authenticatable implements JWTSubject
protected $hidden = ['password', 'remember_token'];
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* Get the customer full name.
*/
@ -94,7 +72,7 @@ class Customer extends Authenticatable implements JWTSubject
/**
* get all cart inactive cart instance of a customer
*/
public function carts() {
public function all_carts() {
return $this->hasMany(Cart::class, 'customer_id');
}

View File

@ -2,14 +2,13 @@
namespace Webkul\User\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Webkul\User\Models\Role;
use Webkul\User\Notifications\AdminResetPassword;
class Admin extends Authenticatable implements JWTSubject
class Admin extends Authenticatable
{
use Notifiable;
@ -31,26 +30,6 @@ class Admin extends Authenticatable implements JWTSubject
'password', 'remember_token',
];
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
/**
* Get the role that owns the admin.
*/

View File

@ -16,7 +16,6 @@ window.Vue = require('vue');
*/
Vue.component('example-component', require('./components/ExampleComponent.vue'));
const app = new Vue({
el: '#app'
});