Initial Gateway test implemented for Mobilebackend

This commit is contained in:
DJERY-TOM 2020-03-28 17:40:37 +01:00
commit 030a029ebd
52 changed files with 7924 additions and 0 deletions

15
.editorconfig Normal file
View File

@ -0,0 +1,15 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.{yml,yaml}]
indent_size = 2

19
.env.example Normal file
View File

@ -0,0 +1,19 @@
APP_NAME=Lumen
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
QUEUE_CONNECTION=sync

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/vendor
/.idea
Homestead.json
Homestead.yaml
.env
.phpunit.result.cache

5
.htaccess Normal file
View File

@ -0,0 +1,5 @@
# For Apache server only
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
###

6
.styleci.yml Normal file
View File

@ -0,0 +1,6 @@
php:
preset: laravel
disabled:
- unused_use
js: true
css: true

24
README.md Normal file
View File

@ -0,0 +1,24 @@
# Lumen PHP Framework
[![Build Status](https://travis-ci.org/laravel/lumen-framework.svg)](https://travis-ci.org/laravel/lumen-framework)
[![Total Downloads](https://poser.pugx.org/laravel/lumen-framework/d/total.svg)](https://packagist.org/packages/laravel/lumen-framework)
[![Latest Stable Version](https://poser.pugx.org/laravel/lumen-framework/v/stable.svg)](https://packagist.org/packages/laravel/lumen-framework)
[![License](https://poser.pugx.org/laravel/lumen-framework/license.svg)](https://packagist.org/packages/laravel/lumen-framework)
Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.
## Official Documentation
Documentation for the framework can be found on the [Lumen website](https://lumen.laravel.com/docs).
## Contributing
Thank you for considering contributing to Lumen! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
## Security Vulnerabilities
If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
## License
The Lumen framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

View File

29
app/Console/Kernel.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
//
}
}

10
app/Events/Event.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
abstract class Event
{
use SerializesModels;
}

View File

@ -0,0 +1,16 @@
<?php
namespace App\Events;
class ExampleEvent extends Event
{
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
}
}

113
app/Exceptions/Handler.php Normal file
View File

@ -0,0 +1,113 @@
<?php
namespace App\Exceptions;
use App\Traits\ApiResponser;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Response;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Throwable;
class Handler extends ExceptionHandler
{
use ApiResponser;
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
// return parent::render($request, $exception);
if ($exception instanceof HttpException)
{
$code = $exception->getStatusCode();
$message = Response::$statusTexts[$code];
return $this->errorResponse($message,$code);
}
if($exception instanceof ModelNotFoundException)
{
$model = strtolower(class_basename($exception->getModel()));
return $this->errorResponse("Does not exist any instance of {$model} with given id",
Response::HTTP_NOT_FOUND);
}
if($exception instanceof AuthorizationException)
{
return $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED);
}
if($exception instanceof ValidationException)
{
$errors = $exception->validator->errors()->getMessages();
return $this->errorResponse($errors, Response::HTTP_UNPROCESSABLE_ENTITY);
}
if ( $exception instanceof ClientException)
{
$message = $exception->getResponse()->getBody();
$code = $exception->getCode();
return $this->errorMessage($message,$code);
}
if($exception instanceof AuthenticationException)
{
return $this->errorResponse($exception->getMessage(),Response::HTTP_UNAUTHORIZED);
}
if ($exception instanceof OAuthServerException)
{
return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR);
}
if( env('APP_DEBUG', false))
{
return parent::render($request,$exception);
}
return $this->errorResponse('Unexcepted error. Try later',
Response::HTTP_INTERNAL_SERVER_ERROR);
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Response;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use League\OAuth2\Server\Exception\OAuthServerException;
use \Laravel\Passport\Http\Controllers\AccessTokenController as ATC;
// Completely overrides Laravel\Passport\Http\Controllers\AccessTokenController
class AccessTokenController extends ATC
{
public function issueToken(ServerRequestInterface $request)
{
try {
//get username (default is :email)
$username = $request->getParsedBody()['username'];
//get user
$user = User::where('email', '=', $username)->firstOrFail();
//issuetoken
$tokenResponse = parent::issueToken($request);
//convert response to json string
$content = $tokenResponse->getBody()->__toString();
//convert json to array
$data = json_decode($content, true);
if(isset($data["error"]))
throw new OAuthServerException('The user credentials were incorrect.', 6, 'invalid_credentials', 401);
//add access token to user
$user = collect($user);
$user->put('access_token', $data['access_token']);
return Response::json(array($user));
}
catch (ModelNotFoundException $e) { // email notfound
//return error message
}
catch (OAuthServerException $e) { //password not correct..token not granted
//return error message
}
catch (Exception $e) {
////return error message
}
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
//
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Http\Controllers;
class ExampleController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
//
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers;
use App\Services\MobileBackendService;
use App\Traits\ApiResponser;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class MobileBackendController extends Controller
{
use ApiResponser;
/**
* @var MobileBackendService
*/
public $mobilebackendService;
/**
* Create a new controller instance.
*
* @param MobileBackendService $mobilebackendService
*/
public function __construct(MobileBackendService $mobilebackendService)
{
$this->mobilebackendService = $mobilebackendService;
}
public function action(Request $request)
{
return $this->successResponse($this->mobilebackendService->action(
$request->getRequestUri(), $request->all()
));
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate
{
/**
* The authentication guard factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if ($this->auth->guard($guard)->guest()) {
return response('Unauthorized.', 401);
}
return $next($request);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Closure;
class ExampleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request);
}
}

26
app/Jobs/ExampleJob.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace App\Jobs;
class ExampleJob extends Job
{
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
}
}

24
app/Jobs/Job.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
abstract class Job implements ShouldQueue
{
/*
|--------------------------------------------------------------------------
| Queueable Jobs
|--------------------------------------------------------------------------
|
| This job base class provides a central location to place any logic that
| is shared across all of your jobs. The trait included with the class
| provides access to the "queueOn" and "delay" queue helper methods.
|
*/
use InteractsWithQueue, Queueable, SerializesModels;
}

View File

@ -0,0 +1,31 @@
<?php
namespace App\Listeners;
use App\Events\ExampleEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class ExampleListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param \App\Events\ExampleEvent $event
* @return void
*/
public function handle(ExampleEvent $event)
{
//
}
}

119
app/Models/Agent.php Normal file
View File

@ -0,0 +1,119 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;
use Laravel\Passport\HasApiTokens;
use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
/**
* Class Agent
*
* @property int $id
* @property string $uid
* @property string $firstname
* @property string $lastname
* @property string $email
* @property float $longitude
* @property float $latitude
* @property string $adresse
* @property float $balance
* @property string $encrypted_password
* @property string $salt
* @property int $active
* @property Carbon $date_created
* @property Carbon $open_hours
* @property Carbon $close_hours
* @property int $town_id
* @property int $number_super
* @property int $number_geoBysuper
*
* @property Town $town
*
* @package App\Models
*/
class Agent extends Model implements AuthenticatableContract, AuthorizableContract
{
use HasMultiAuthApiTokens, Authenticatable, Authorizable;
protected $table = 'agents';
public $timestamps = false;
protected $casts = [
'longitude' => 'float',
'latitude' => 'float',
'balance' => 'float',
'active' => 'int',
'town_id' => 'int',
'number_super' => 'int',
'number_geoBysuper' => 'int'
];
protected $dates = [
'date_created',
'open_hours',
'close_hours'
];
protected $hidden = [
'encrypted_password'
];
protected $fillable = [
'uid',
'firstname',
'lastname',
'email',
'longitude',
'latitude',
'adresse',
'balance',
'encrypted_password',
'salt',
'active',
'date_created',
'open_hours',
'close_hours',
'town_id',
'number_super',
'number_geoBysuper'
];
public function town()
{
return $this->belongsTo(Town::class);
}
/**
* Find the user instance for the given username.
*
* @param string $username
* @return \App\Models\User
*/
public function findForPassport($username)
{
return $this->where('email', $username)->first();
}
/**
* Validate the password of the user for the Passport password grant.
*
* @param string $password
* @return bool
*/
public function validateForPassportPasswordGrant($password)
{
// return Hash::check($password, $this->password);
$encrypted_password = base64_encode(sha1($password . $this->salt, true) . $this->salt);
return $this->encrypted_password == $encrypted_password;
}
}

103
app/Models/User.php Normal file
View File

@ -0,0 +1,103 @@
<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Laravel\Lumen\Auth\Authorizable;
use Laravel\Passport\HasApiTokens;
use Illuminate\Support\Facades\Hash;
use SMartins\PassportMultiauth\HasMultiAuthApiTokens;
/**
* Class User
*
* @property int $id
* @property string $uid
* @property string $firstname
* @property string $lastname
* @property string $phone
* @property string $email
* @property string $adresse
* @property float $solde
* @property string $encrypted_password
* @property string $salt
* @property string $validation_code
* @property int $active
* @property Carbon $date_modified
* @property Carbon $date_created
* @property int $network_id
*
* @package App\Models
*/
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use HasMultiAuthApiTokens, Authenticatable, Authorizable;
protected $table = 'users';
public $timestamps = false;
protected $casts = [
'solde' => 'float',
'active' => 'int',
'network_id' => 'int'
];
protected $dates = [
'date_modified',
'date_created'
];
protected $hidden = [
'encrypted_password'
];
protected $fillable = [
'uid',
'firstname',
'lastname',
'phone',
'email',
'adresse',
'solde',
'encrypted_password',
'salt',
'validation_code',
'active',
'date_modified',
'date_created'
];
/**
* Find the user instance for the given username.
*
* @param string $username
* @return \App\Models\User
*/
public function findForPassport($username)
{
// return $this->where('phone', $username)->first();
return $user = (new User)->where('email', $username)->orWhere('phone', $username)->first();
}
/**
* Validate the password of the user for the Passport password grant.
*
* @param string $password
* @return bool
*/
public function validateForPassportPasswordGrant($password)
{
// return Hash::check($password, $this->password);
$encrypted_password = base64_encode(sha1($password . $this->salt, true) . $this->salt);
return $this->encrypted_password == $encrypted_password;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Providers;
use App\User;
use Dusterio\LumenPassport\LumenPassport;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
class AuthServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Boot the authentication services for the application.
*
* @return void
*/
public function boot()
{
// Here you may define how you wish users to be authenticated for your Lumen
// application. The callback which receives the incoming request instance
// should return either a User instance or null. You're free to obtain
// the User instance via an API token or any other method necessary.
// $this->app['auth']->viaRequest('api', function ($request) {
// if ($request->input('api_token')) {
// return User::where('api_token', $request->input('api_token'))->first();
// }
// });
LumenPassport::routes($this->app->router);
// Middleware `oauth.providers` middleware defined on $routeMiddleware above
Route::group(['middleware' => 'oauth.providers'], function () {
// LumenPassport::routes(function ($router) {
//// dd($router);
// return $router->all();
// });
LumenPassport::routes($this->app->router);
});
//For customizing access token response
// Route::post('/oauth/token','\App\Http\Controllers\AccessTokenController@issueToken');
// Route::post('/oauth/token', [
// 'uses' => '\App\Http\Controllers\AccessTokenController@issueToken',
//// 'as' => 'passport.token',
//// 'middleware' => 'throttle',
// ]);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Providers;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
\App\Events\ExampleEvent::class => [
\App\Listeners\ExampleListener::class,
],
];
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Services;
use App\Traits\ConsumesExternalService;
class MobileBackendService
{
use ConsumesExternalService;
/**
* @var string
*/
public $baseUri ;
public function __construct()
{
$this->baseUri = config('services.mobilebackend.base_uri');
}
public function action($uri , $data)
{
return $this->perfomRequest('POST',$uri.'.php',$data);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\Traits;
use Illuminate\Http\Response;
trait ApiResponser
{
public function successResponse($data , $code = Response::HTTP_OK)
{
return response($data , $code)->header('Content-Type', 'application/json');
}
public function errorResponse($message , $code)
{
return response()->json(['error' => $message , 'code'=> $code]);
}
public function errorMessage($message , $code)
{
return response($message ,$code)->header('Content-Type', 'application/json');
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Traits;
use GuzzleHttp\Client;
trait ConsumesExternalService
{
/**
* Envoie une requete a un service
* @param $method
* @param $requestUrl
* @param array $body
* @param array $formParams
* @param array $headers
* @return string
*/
public function perfomRequest($method, $requestUrl, $body = [], $formParams = [], $headers = [])
{
$client = new Client([
'base_uri' => $this->baseUri,
]);
$response = $client->request($method , $requestUrl , ['json'=> $body , 'form_params' => $formParams , 'headers' => $headers] );
return $response->getBody()->getContents();
}
}

32
app/User.php.save Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable, Authorizable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password',
];
}

35
artisan Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(
'Illuminate\Contracts\Console\Kernel'
);
exit($kernel->handle(new ArgvInput, new ConsoleOutput));

137
bootstrap/app.php Normal file
View File

@ -0,0 +1,137 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
$app->withFacades();
$app->withEloquent();
/**
* Register config files
*/
$app->configure('services');
$app->configure('auth');
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
/*
|--------------------------------------------------------------------------
| Register Config Files
|--------------------------------------------------------------------------
|
| Now we will register the "app" configuration file. If the file exists in
| your configuration directory it will be loaded; otherwise, we'll load
| the default version. You may register other files below as needed.
|
*/
$app->configure('app');
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
// $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class
// ]);
$app->routeMiddleware([
// 'auth' => App\Http\Middleware\Authenticate::class,
'clients.credentials' => Laravel\Passport\Http\Middleware\
CheckClientCredentials::class,
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
// ** New middleware **
'multiauth' => \SMartins\PassportMultiauth\Http\Middleware\MultiAuthenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'oauth.providers' => \SMartins\PassportMultiauth\Http\Middleware\AddCustomProvider::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// $app->register(App\Providers\AppServiceProvider::class);
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(SMartins\PassportMultiauth\Providers\MultiauthServiceProvider::class);
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});
return $app;

52
composer.json Normal file
View File

@ -0,0 +1,52 @@
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"php": "^7.2.5",
"dusterio/lumen-passport": "^0.2.18",
"guzzlehttp/guzzle": "^6.5",
"laravel/lumen-framework": "^7.0",
"smartins/passport-multiauth": "^6.0"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.5"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"extra": {
"laravel": {
"dont-discover": [
"laravel/passport"
]
}
}
}

6399
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

102
config/auth.php Normal file
View File

@ -0,0 +1,102 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
// 'guard' => env('AUTH_GUARD', 'api'),
'guard' => 'api',
'passwords' => 'users'
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "token"
|
*/
'guards' => [
// 'api' => ['driver' => 'passport'],
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
'agent' => [
'driver' => 'passport',
'provider' => 'agents',
]
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Models\User::class
],
'agents' => [
'driver' => 'eloquent',
'model' => \App\Models\Agent::class
]
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
//
],
];

10
config/services.php Normal file
View File

@ -0,0 +1,10 @@
<?php
return [
'mobilebackend' => [
'base_uri' => env('MOBILEBACKEND_BASE_URL'),
],
'mobilebackendtest' => [
'base_uri' => env('MOBILEBACKENDTEST_BASE_URL'),
]
];

View File

@ -0,0 +1,24 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\User;
use Faker\Generator as Faker;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
$factory->define(User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
];
});

View File

View File

@ -0,0 +1,16 @@
<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// $this->call('UsersTableSeeder');
}
}

21
phpunit.xml Normal file
View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
</php>
</phpunit>

21
public/.htaccess Normal file
View File

@ -0,0 +1,21 @@
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

28
public/index.php Normal file
View File

@ -0,0 +1,28 @@
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| First we need to get an application instance. This creates an instance
| of the application / container and bootstraps the application so it
| is ready to receive HTTP / Console requests from the environment.
|
*/
$app = require __DIR__.'/../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$app->run();

0
resources/views/.gitkeep Normal file
View File

34
routes/web.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
//$router->get('/', function () use ($router) {
// return $router->app->version();
//});
/**
* Routes for MobileBackend
*/
$router->group(['prefix' => '/mobilebackend/interacted'], function () use ($router){
$router->post('LoginAction', 'MobileBackendController@action');
$router->group(['middleware' => 'auth'], function () use ($router){
$router->post('BalanceAction', 'MobileBackendController@action');
$router->post('ConfigAction', 'MobileBackendController@action');
$router->post('DemandeAction', 'MobileBackendController@action');
$router->post('MembersAction', 'MobileBackendController@action');
$router->post('NetworkAction', 'MobileBackendController@action');
$router->post('WalletAction', 'MobileBackendController@action');
});
});

2
storage/app/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

3
storage/framework/cache/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*
!data/
!.gitignore

View File

@ -0,0 +1,2 @@
*
!.gitignore

2
storage/framework/views/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

2
storage/logs/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

51
storage/oauth-private.key Normal file
View File

@ -0,0 +1,51 @@
-----BEGIN RSA PRIVATE KEY-----
MIIJKgIBAAKCAgEAyvpLRI1lz0oAFMBM757jlyReY1a41KUq1J3jZ6EsaPQSJJ4+
/b0ers0LytGbs7tcrHYU8W4fv/8/k7sSOaGw0lgz6Dzz5AUiOvywF2gC8yuIrmpV
O0RZVfqE6xV4Zf8LQXE6eMLUle84spzXzyqI1QEoqqTI9L0xER1qyMxnFv+KDBKc
6UWOfXFyIoPrPOxdgtdExFsUWT/VjLPHIg5NVjdF+fJVJVJWZvj4qYa6V297n6pw
TTc9aG3xbOf3bQGKbesG+P/xGy6Xce+5L7PeswiZQdCXqBy8hJsyEvRC0akkcxSt
i1ADMJpdh7bEjHavVUtUZ2Kd4Xoa2qNEfW4NUfHG8JX668UMUBqnAgyyVeYstikt
pNwrmcNVm2Lvq3X0NPUMz7xxalrxKQuPC6nEeBk2zbPUytN9SHcjnkS/YYSSeYID
IIgwbww1LVY/SvIDyAfzzNCz+cz8m0NM5XE1no+p3EKHTk9WZ47exXEGtIzNDNv3
iV33/YmO2/Y2uS22CGtD+puLzn4wSkB9cUCd4h6ouKUkjcTNSLd5oU8/Zrv4JK9/
H2amv/e1/gzwwtGCkaJFItyFzHEGSPC1QbB4gelF8rSokCAKPNJ2a7M9XhxrYO8d
FdYWNd2pVu92gZjSzBRMNPgQP0Y/ZVMd4PiK6D5f6QGLGnw/YH22YqK7vVECAwEA
AQKCAgEAw21HKMKnAnSyLUiVCqTFZdErW6O0o3A/E6TMvQruEkLkcQM3jOAYeZ6M
OwOjUOIVMSsjsOwhf58HHHqh6oEmGO+5UmHVRHY45ehCttZ6+JuyppNUapK9HM3u
SdVLLZDoymJ1NK4JNi60PSxLkHfYdJUADYRIw3KgmmTjWl+K5ha1WDhXgTVqIpcm
l9rBk8/TnNUcrZ0vs1qFhknVcZ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0uEPsX5UFtH2
Ll2QzUqJcTzeAT2ShOFIHplmV1QFP1CeBE9wy+lCrwQ3kEcAiRgWo0rmsaNjJQ==
-----END RSA PRIVATE KEY-----

14
storage/oauth-public.key Normal file
View File

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAyvpLRI1lz0oAFMBM757j
lyReY1a41KUq1J3jZ6EsaPQSJJ4+/b0ers0LytGbs7tcrHYU8W4fv/8/k7sSOaGw
0lgz6Dzz5AUiOvywF2gC8yuIrmpVO0RZVfqE6xV4Zf8LQXE6eMLUle84spzXzyqI
1QEoqqTI9L0xER1qyMxnFv+KDBKc6UWOfXFyIoPrPOxdgtdExFsUWT/VjLPHIg5N
VjdF+fJVJVJWZvj4qYa6V297n6pwTTc9aG3xbOf3bQGKbesG+P/xGy6Xce+5L7Pe
swiZQdCXqBy8hJsyEvRC0akkcxSti1ADMJpdh7bEjHavVUtUZ2Kd4Xoa2qNEfW4N
UfHG8JX668UMUBqnAgyyVeYstiktpNwrmcNVm2Lvq3X0NPUMz7xxalrxKQuPC6nE
eBk2zbPUytN9SHcjnkS/YYSSeYIDIIgwbww1LVY/SvIDyAfzzNCz+cz8m0NM5XE1
no+p3EKHTk9WZ47exXEGtIzNDNv3iV33/YmO2/Y2uS22CGtD+puLzn4wSkB9cUCd
4h6ouKUkjcTNSLd5oU8/Zrv4JK9/H2amv/e1/gzwwtGCkaJFItyFzHEGSPC1QbB4
gelF8rSokCAKPNJ2a7M9XhxrYO8dFdYWNd2pVu92gZjSzBRMNPgQP0Y/ZVMd4PiK
6D5f6QGLGnw/YH22YqK7vVECAwEAAQ==
-----END PUBLIC KEY-----

21
tests/ExampleTest.php Normal file
View File

@ -0,0 +1,21 @@
<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testExample()
{
$this->get('/');
$this->assertEquals(
$this->app->version(), $this->response->getContent()
);
}
}

16
tests/TestCase.php Normal file
View File

@ -0,0 +1,16 @@
<?php
use Laravel\Lumen\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__.'/../bootstrap/app.php';
}
}