/**
  * Handle an incoming request.
  *
  * @param  IlluminateHttpRequest  $request
  * @param  Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $role)
 {
     $id = Authorizer::getResourceOwnerId();
     $user = \CodeDelivery\Models\User::where('id', '=', $id)->first();
     //$this->userRepository->find($id);
     if ($user->role != $role) {
         abort(403, 'Access Forbiden');
     }
     return $next($request);
 }
Exemplo n.º 2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
 public function create(array $data)
 {
     $user = User::create($data['user']);
     $user->client()->save(new Client($data));
 }
Exemplo n.º 4
0
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(CodeDelivery\Models\User::class, function (Faker\Generator $faker) {
    return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10)), 'remember_token' => str_random(10)];
});
$factory->define(CodeDelivery\Models\Category::class, function (Faker\Generator $faker) {
    return ['name' => $faker->word];
});
$factory->define(CodeDelivery\Models\Product::class, function (Faker\Generator $faker) {
    return ['name' => $faker->word, 'description' => $faker->sentence, 'price' => $faker->numberBetween(10, 50)];
});
$factory->define(CodeDelivery\Models\Client::class, function (Faker\Generator $faker) {
    return ['phone' => $faker->phoneNumber, 'address' => $faker->address, 'city' => $faker->city, 'state' => $faker->state, 'zipcode' => $faker->postcode];
});
$factory->define(CodeDelivery\Models\Order::class, function (Faker\Generator $faker) {
    return ['client_id' => \CodeDelivery\Models\Client::all()->lists('id')->random(1), 'user_deliveryman_id' => \CodeDelivery\Models\User::all()->lists('id')->random(1), 'total' => $faker->randomFloat(6), 'status' => $faker->numberBetween(1, 6)];
});
$factory->define(CodeDelivery\Models\OrderItem::class, function (Faker\Generator $faker) {
    return ['product_id' => \CodeDelivery\Models\Product::all()->lists('id')->random(1), 'order_id' => \CodeDelivery\Models\Order::all()->lists('id')->random(1), 'price' => $faker->randomFloat(6), 'qtd' => $faker->randomNumber(6)];
});
$factory->define(CodeDelivery\Models\Cupom::class, function (Faker\Generator $faker) {
    return ['code' => $faker->randomNumber(4), 'value' => $faker->randomNumber(2)];
});
Exemplo n.º 5
0
        Route::get('/create', ['as' => 'create', 'uses' => 'CupomsController@create']);
        Route::get('/edit/{id}', ['as' => 'edit', 'uses' => 'CupomsController@edit']);
        Route::post('/store', ['as' => 'store', 'uses' => 'CupomsController@store']);
        Route::post('/update/{id}', ['as' => 'update', 'uses' => 'CupomsController@update']);
    });
});
Route::group(['prefix' => 'costumer', 'middleware' => 'auth.checkrole:client', 'as' => 'costumer.'], function () {
    Route::get('/order', ['as' => 'order.index', 'uses' => 'CheckoutController@index']);
    Route::get('/order/create', ['as' => 'order.create', 'uses' => 'CheckoutController@create']);
    Route::post('/order/store', ['as' => 'order.store', 'uses' => 'CheckoutController@store']);
});
Route::group(['middleware' => 'cors'], function () {
    Route::post('oauth/access_token', function () {
        return Response::json(Authorizer::issueAccessToken());
    });
    Route::group(['prefix' => 'api', 'middleware' => 'oauth', 'as' => 'api.'], function () {
        Route::group(['prefix' => 'client', 'middleware' => 'oauth.checkrole:client', 'as' => 'client.'], function () {
            Route::resource('/order', 'Api\\Client\\ClientCheckoutController', ['except' => ['create', 'edit', 'destroy']]);
        });
        Route::group(['prefix' => 'deliveryman', 'middleware' => 'oauth.checkrole:deliveryman', 'as' => 'deliveryman.'], function () {
            Route::resource('/order', 'Api\\Deliveryman\\DeliverymanCheckoutController', ['except' => ['create', 'edit', 'destroy', 'store']]);
            Route::patch('order/{id}/update-status', ['as' => 'orders.update_status', 'uses' => 'Api\\Deliveryman\\DeliverymanCheckoutController@updateStatus']);
        });
        Route::get('/test', ['as' => 'test', 'uses' => 'CheckoutController@index']);
        Route::get('user/authenticated', ['as' => 'user.auth', 'uses' => 'UserController@authenticated']);
        Route::get('authenticated', function () {
            $id = \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId();
            return \CodeDelivery\Models\User::find($id);
        });
    });
});