diff --git a/composer.json b/composer.json index 149aee428..75c04b51b 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/app.php b/config/app.php index b7729283b..7affc48ae 100644 --- a/config/app.php +++ b/config/app.php @@ -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, ], ]; \ No newline at end of file diff --git a/config/auth.php b/config/auth.php index 55a8c2653..caa89e114 100644 --- a/config/auth.php +++ b/config/auth.php @@ -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', ] ], diff --git a/packages/Webkul/API/Database/Migrations/2018_11_17_193819_create_admin_oauth_tokens_table.php b/packages/Webkul/API/Database/Migrations/2018_11_17_193819_create_admin_oauth_tokens_table.php deleted file mode 100644 index 684d8c15f..000000000 --- a/packages/Webkul/API/Database/Migrations/2018_11_17_193819_create_admin_oauth_tokens_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -} diff --git a/packages/Webkul/API/Database/Migrations/2018_11_19_104049_create_customer_oauth_tokens_table.php b/packages/Webkul/API/Database/Migrations/2018_11_19_104049_create_customer_oauth_tokens_table.php deleted file mode 100644 index 418f11017..000000000 --- a/packages/Webkul/API/Database/Migrations/2018_11_19_104049_create_customer_oauth_tokens_table.php +++ /dev/null @@ -1,37 +0,0 @@ -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'); - } -} diff --git a/packages/Webkul/API/Http/Controllers/Admin/AuthController.php b/packages/Webkul/API/Http/Controllers/Admin/AuthController.php deleted file mode 100644 index cb25e2a78..000000000 --- a/packages/Webkul/API/Http/Controllers/Admin/AuthController.php +++ /dev/null @@ -1,103 +0,0 @@ - @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']); - } -} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/AddressController.php b/packages/Webkul/API/Http/Controllers/Customer/AddressController.php new file mode 100644 index 000000000..df23f31d3 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Customer/AddressController.php @@ -0,0 +1,50 @@ + @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); + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/AuthController.php b/packages/Webkul/API/Http/Controllers/Customer/AuthController.php index f6520f715..603ccd4d7 100644 --- a/packages/Webkul/API/Http/Controllers/Customer/AuthController.php +++ b/packages/Webkul/API/Http/Controllers/Customer/AuthController.php @@ -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']); - } -} +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php b/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php new file mode 100644 index 000000000..e1a74f30d --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Customer/CustomerController.php @@ -0,0 +1,39 @@ + @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; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php b/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php new file mode 100644 index 000000000..a975d3d14 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Customer/WishlistController.php @@ -0,0 +1,40 @@ + @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); + } + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Product/ProductController.php b/packages/Webkul/API/Http/Controllers/Product/ProductController.php new file mode 100644 index 000000000..1565ed5e1 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Product/ProductController.php @@ -0,0 +1,37 @@ + @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); + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/Controllers/Shop/CartController.php b/packages/Webkul/API/Http/Controllers/Shop/CartController.php new file mode 100644 index 000000000..47b975ce7 --- /dev/null +++ b/packages/Webkul/API/Http/Controllers/Shop/CartController.php @@ -0,0 +1,49 @@ + @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; + } +} \ No newline at end of file diff --git a/packages/Webkul/API/Http/api.php b/packages/Webkul/API/Http/api.php index 8318a1a24..396c14e4f 100644 --- a/packages/Webkul/API/Http/api.php +++ b/packages/Webkul/API/Http/api.php @@ -1,15 +1,39 @@ '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) { + }); \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Http/routes.php b/packages/Webkul/Admin/src/Http/routes.php index 6ed1fa046..f394303c5 100644 --- a/packages/Webkul/Admin/src/Http/routes.php +++ b/packages/Webkul/Admin/src/Http/routes.php @@ -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',[ diff --git a/packages/Webkul/Admin/webpack.mix.js b/packages/Webkul/Admin/webpack.mix.js index 92e3d593b..3f72c18c8 100644 --- a/packages/Webkul/Admin/webpack.mix.js +++ b/packages/Webkul/Admin/webpack.mix.js @@ -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(); diff --git a/packages/Webkul/Customer/src/Models/Customer.php b/packages/Webkul/Customer/src/Models/Customer.php index c7cd36242..80e339739 100644 --- a/packages/Webkul/Customer/src/Models/Customer.php +++ b/packages/Webkul/Customer/src/Models/Customer.php @@ -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'); } diff --git a/packages/Webkul/User/src/Models/Admin.php b/packages/Webkul/User/src/Models/Admin.php index acf5b9d6a..4418ab7dc 100644 --- a/packages/Webkul/User/src/Models/Admin.php +++ b/packages/Webkul/User/src/Models/Admin.php @@ -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. */ diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 98eca79fd..13bb001e2 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -16,7 +16,6 @@ window.Vue = require('vue'); */ Vue.component('example-component', require('./components/ExampleComponent.vue')); - const app = new Vue({ el: '#app' });