@@ -5,105 +5,105 @@ |
||
| 5 | 5 | |
| 6 | 6 | class LoginProxy |
| 7 | 7 | { |
| 8 | - private $apiConsumer; |
|
| 9 | - |
|
| 10 | - private $auth; |
|
| 11 | - |
|
| 12 | - private $db; |
|
| 13 | - |
|
| 14 | - private $request; |
|
| 15 | - |
|
| 16 | - private $userRepository; |
|
| 17 | - |
|
| 18 | - public function __construct(Application $app) |
|
| 19 | - { |
|
| 20 | - |
|
| 21 | - $this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository'); |
|
| 22 | - $this->apiConsumer = $app->make('apiconsumer'); |
|
| 23 | - $this->auth = $app->make('auth'); |
|
| 24 | - $this->db = $app->make('db'); |
|
| 25 | - $this->request = $app->make('request'); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Attempt to create an access token using user credentials. |
|
| 30 | - * |
|
| 31 | - * @param array $credentials |
|
| 32 | - * @param boolean $adminLogin |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function login($credentials, $adminLogin = false) |
|
| 36 | - { |
|
| 37 | - $this->userRepository->login($credentials, $adminLogin); |
|
| 38 | - |
|
| 39 | - return $this->proxy('password', [ |
|
| 40 | - 'username' => $credentials['email'], |
|
| 41 | - 'password' => $credentials['password'] |
|
| 42 | - ]); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Attempt to refresh the access token useing the given refresh token. |
|
| 47 | - * |
|
| 48 | - * @param string $refreshToken |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function refreshtoken($refreshToken) |
|
| 52 | - { |
|
| 53 | - return $this->proxy('refresh_token', [ |
|
| 54 | - 'refresh_token' => $refreshToken |
|
| 55 | - ]); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Proxy a request to the OAuth server. |
|
| 60 | - * |
|
| 61 | - * @param string $grantType what type of grant type should be proxied |
|
| 62 | - * @param array |
|
| 63 | - */ |
|
| 64 | - public function proxy($grantType, array $data = []) |
|
| 65 | - { |
|
| 66 | - $data = array_merge($data, [ |
|
| 67 | - 'client_id' => env('PASSWORD_CLIENT_ID'), |
|
| 68 | - 'client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
| 69 | - 'grant_type' => $grantType |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - $response = $this->apiConsumer->post('/oauth/token', $data); |
|
| 73 | - |
|
| 74 | - if ( ! $response->isSuccessful()) |
|
| 75 | - { |
|
| 76 | - if ($grantType == 'refresh_token') |
|
| 77 | - { |
|
| 78 | - \ErrorHandler::invalidRefreshToken(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - \ErrorHandler::loginFailed(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $data = json_decode($response->getContent()); |
|
| 85 | - |
|
| 86 | - return [ |
|
| 87 | - 'access_token' => $data->access_token, |
|
| 88 | - 'refresh_token' => $data->refresh_token, |
|
| 89 | - 'expires_in' => $data->expires_in |
|
| 90 | - ]; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Logs out the user. We revoke access token and refresh token. |
|
| 95 | - */ |
|
| 96 | - public function logout() |
|
| 97 | - { |
|
| 98 | - $accessToken = $this->auth->user()->token(); |
|
| 99 | - |
|
| 100 | - $this->db |
|
| 101 | - ->table('oauth_refresh_tokens') |
|
| 102 | - ->where('access_token_id', $accessToken->id) |
|
| 103 | - ->update([ |
|
| 104 | - 'revoked' => true |
|
| 105 | - ]); |
|
| 106 | - |
|
| 107 | - $accessToken->revoke(); |
|
| 108 | - } |
|
| 8 | + private $apiConsumer; |
|
| 9 | + |
|
| 10 | + private $auth; |
|
| 11 | + |
|
| 12 | + private $db; |
|
| 13 | + |
|
| 14 | + private $request; |
|
| 15 | + |
|
| 16 | + private $userRepository; |
|
| 17 | + |
|
| 18 | + public function __construct(Application $app) |
|
| 19 | + { |
|
| 20 | + |
|
| 21 | + $this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository'); |
|
| 22 | + $this->apiConsumer = $app->make('apiconsumer'); |
|
| 23 | + $this->auth = $app->make('auth'); |
|
| 24 | + $this->db = $app->make('db'); |
|
| 25 | + $this->request = $app->make('request'); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Attempt to create an access token using user credentials. |
|
| 30 | + * |
|
| 31 | + * @param array $credentials |
|
| 32 | + * @param boolean $adminLogin |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function login($credentials, $adminLogin = false) |
|
| 36 | + { |
|
| 37 | + $this->userRepository->login($credentials, $adminLogin); |
|
| 38 | + |
|
| 39 | + return $this->proxy('password', [ |
|
| 40 | + 'username' => $credentials['email'], |
|
| 41 | + 'password' => $credentials['password'] |
|
| 42 | + ]); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Attempt to refresh the access token useing the given refresh token. |
|
| 47 | + * |
|
| 48 | + * @param string $refreshToken |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function refreshtoken($refreshToken) |
|
| 52 | + { |
|
| 53 | + return $this->proxy('refresh_token', [ |
|
| 54 | + 'refresh_token' => $refreshToken |
|
| 55 | + ]); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Proxy a request to the OAuth server. |
|
| 60 | + * |
|
| 61 | + * @param string $grantType what type of grant type should be proxied |
|
| 62 | + * @param array |
|
| 63 | + */ |
|
| 64 | + public function proxy($grantType, array $data = []) |
|
| 65 | + { |
|
| 66 | + $data = array_merge($data, [ |
|
| 67 | + 'client_id' => env('PASSWORD_CLIENT_ID'), |
|
| 68 | + 'client_secret' => env('PASSWORD_CLIENT_SECRET'), |
|
| 69 | + 'grant_type' => $grantType |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + $response = $this->apiConsumer->post('/oauth/token', $data); |
|
| 73 | + |
|
| 74 | + if ( ! $response->isSuccessful()) |
|
| 75 | + { |
|
| 76 | + if ($grantType == 'refresh_token') |
|
| 77 | + { |
|
| 78 | + \ErrorHandler::invalidRefreshToken(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + \ErrorHandler::loginFailed(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $data = json_decode($response->getContent()); |
|
| 85 | + |
|
| 86 | + return [ |
|
| 87 | + 'access_token' => $data->access_token, |
|
| 88 | + 'refresh_token' => $data->refresh_token, |
|
| 89 | + 'expires_in' => $data->expires_in |
|
| 90 | + ]; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Logs out the user. We revoke access token and refresh token. |
|
| 95 | + */ |
|
| 96 | + public function logout() |
|
| 97 | + { |
|
| 98 | + $accessToken = $this->auth->user()->token(); |
|
| 99 | + |
|
| 100 | + $this->db |
|
| 101 | + ->table('oauth_refresh_tokens') |
|
| 102 | + ->where('access_token_id', $accessToken->id) |
|
| 103 | + ->update([ |
|
| 104 | + 'revoked' => true |
|
| 105 | + ]); |
|
| 106 | + |
|
| 107 | + $accessToken->revoke(); |
|
| 108 | + } |
|
| 109 | 109 | } |
| 110 | 110 | \ No newline at end of file |
@@ -2,51 +2,51 @@ |
||
| 2 | 2 | |
| 3 | 3 | trait Translatable |
| 4 | 4 | { |
| 5 | - /** |
|
| 6 | - * Create a new model instance that is existing. |
|
| 7 | - * |
|
| 8 | - * @param array $attributes |
|
| 9 | - * @param string|null $connection |
|
| 10 | - * @return static |
|
| 11 | - */ |
|
| 12 | - public function newFromBuilder($attributes = [], $connection = null) |
|
| 13 | - { |
|
| 14 | - $model = parent::newFromBuilder($attributes, $connection); |
|
| 5 | + /** |
|
| 6 | + * Create a new model instance that is existing. |
|
| 7 | + * |
|
| 8 | + * @param array $attributes |
|
| 9 | + * @param string|null $connection |
|
| 10 | + * @return static |
|
| 11 | + */ |
|
| 12 | + public function newFromBuilder($attributes = [], $connection = null) |
|
| 13 | + { |
|
| 14 | + $model = parent::newFromBuilder($attributes, $connection); |
|
| 15 | 15 | |
| 16 | - foreach ($model->attributes AS $key => $value) |
|
| 17 | - { |
|
| 18 | - if (isset($this->translatable) && in_array($key, $this->translatable)) |
|
| 19 | - { |
|
| 20 | - $model->$key = $this->getTranslatedAttribute($key, $value); |
|
| 21 | - } |
|
| 22 | - } |
|
| 16 | + foreach ($model->attributes AS $key => $value) |
|
| 17 | + { |
|
| 18 | + if (isset($this->translatable) && in_array($key, $this->translatable)) |
|
| 19 | + { |
|
| 20 | + $model->$key = $this->getTranslatedAttribute($key, $value); |
|
| 21 | + } |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - return $model; |
|
| 25 | - } |
|
| 24 | + return $model; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | - * |
|
| 30 | - * @param $key |
|
| 31 | - * @param $values |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - protected function getTranslatedAttribute($key, $values) |
|
| 35 | - { |
|
| 36 | - $values = json_decode($values); |
|
| 37 | - $primaryLocale = \Session::get('locale'); |
|
| 38 | - $fallbackLocale = 'en'; |
|
| 27 | + /** |
|
| 28 | + * Returns a translatable model attribute based on the application's locale settings. |
|
| 29 | + * |
|
| 30 | + * @param $key |
|
| 31 | + * @param $values |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + protected function getTranslatedAttribute($key, $values) |
|
| 35 | + { |
|
| 36 | + $values = json_decode($values); |
|
| 37 | + $primaryLocale = \Session::get('locale'); |
|
| 38 | + $fallbackLocale = 'en'; |
|
| 39 | 39 | |
| 40 | - if ($primaryLocale == 'all') |
|
| 41 | - { |
|
| 42 | - return $values; |
|
| 43 | - } |
|
| 40 | + if ($primaryLocale == 'all') |
|
| 41 | + { |
|
| 42 | + return $values; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - if ( ! $primaryLocale || ! isset($values->$primaryLocale)) |
|
| 46 | - { |
|
| 47 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
| 48 | - } |
|
| 45 | + if ( ! $primaryLocale || ! isset($values->$primaryLocale)) |
|
| 46 | + { |
|
| 47 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 51 | - } |
|
| 50 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
| 51 | + } |
|
| 52 | 52 | } |
| 53 | 53 | \ No newline at end of file |
@@ -20,27 +20,27 @@ discard block |
||
| 20 | 20 | ], |
| 21 | 21 | [ |
| 22 | 22 | 'title' => 'email equal [email protected] and user is blocked:', |
| 23 | - 'content' => ['and' => ['email' => '[email protected]','blocked' => 1]] |
|
| 23 | + 'content' => ['and' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 24 | 24 | ], |
| 25 | 25 | [ |
| 26 | 26 | 'title' => 'email equal [email protected] or user is blocked:', |
| 27 | - 'content' => ['or' => ['email' => '[email protected]','blocked' => 1]] |
|
| 27 | + 'content' => ['or' => ['email' => '[email protected]', 'blocked' => 1]] |
|
| 28 | 28 | ], |
| 29 | 29 | [ |
| 30 | 30 | 'title' => 'email contain John:', |
| 31 | - 'content' => ['email' => ['op' => 'like','val' => '%John%']] |
|
| 31 | + 'content' => ['email' => ['op' => 'like', 'val' => '%John%']] |
|
| 32 | 32 | ], |
| 33 | 33 | [ |
| 34 | 34 | 'title' => 'user created after 2016-10-25:', |
| 35 | - 'content' => ['created_at' => ['op' => '>','val' => '2016-10-25']] |
|
| 35 | + 'content' => ['created_at' => ['op' => '>', 'val' => '2016-10-25']] |
|
| 36 | 36 | ], |
| 37 | 37 | [ |
| 38 | 38 | 'title' => 'user created between 2016-10-20 and 2016-10-25:', |
| 39 | - 'content' => ['created_at' => ['op' => 'between','val1' => '2016-10-20','val2' => '2016-10-25']] |
|
| 39 | + 'content' => ['created_at' => ['op' => 'between', 'val1' => '2016-10-20', 'val2' => '2016-10-25']] |
|
| 40 | 40 | ], |
| 41 | 41 | [ |
| 42 | 42 | 'title' => 'user id in 1,2,3:', |
| 43 | - 'content' => ['id' => ['op' => 'in','val' => [1, 2, 3]]] |
|
| 43 | + 'content' => ['id' => ['op' => 'in', 'val' => [1, 2, 3]]] |
|
| 44 | 44 | ], |
| 45 | 45 | [ |
| 46 | 46 | 'title' => 'user name is null:', |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | ], |
| 53 | 53 | [ |
| 54 | 54 | 'title' => 'user has group admin:', |
| 55 | - 'content' => ['groups' => ['op' => 'has','val' => ['name' => 'Admin']]] |
|
| 55 | + 'content' => ['groups' => ['op' => 'has', 'val' => ['name' => 'Admin']]] |
|
| 56 | 56 | ] |
| 57 | 57 | ]; |
| 58 | 58 | |
@@ -7,44 +7,44 @@ |
||
| 7 | 7 | class ModuleServiceProvider extends ServiceProvider |
| 8 | 8 | { |
| 9 | 9 | /** |
| 10 | - * Bootstrap the module services. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function boot() |
|
| 15 | - { |
|
| 16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 10 | + * Bootstrap the module services. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function boot() |
|
| 15 | + { |
|
| 16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
| 17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
| 18 | 18 | |
| 19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
| 21 | - } |
|
| 19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
| 20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Register the module services. |
|
| 25 | - * |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function register() |
|
| 29 | - { |
|
| 30 | - //Bind Core Facade to the IoC Container |
|
| 31 | - \App::bind('Core', function() |
|
| 32 | - { |
|
| 33 | - return new \App\Modules\V1\Core\Core; |
|
| 34 | - }); |
|
| 23 | + /** |
|
| 24 | + * Register the module services. |
|
| 25 | + * |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function register() |
|
| 29 | + { |
|
| 30 | + //Bind Core Facade to the IoC Container |
|
| 31 | + \App::bind('Core', function() |
|
| 32 | + { |
|
| 33 | + return new \App\Modules\V1\Core\Core; |
|
| 34 | + }); |
|
| 35 | 35 | |
| 36 | - //Bind ErrorHandler Facade to the IoC Container |
|
| 37 | - \App::bind('ErrorHandler', function() |
|
| 38 | - { |
|
| 39 | - return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
| 40 | - }); |
|
| 36 | + //Bind ErrorHandler Facade to the IoC Container |
|
| 37 | + \App::bind('ErrorHandler', function() |
|
| 38 | + { |
|
| 39 | + return new \App\Modules\V1\Core\Utl\ErrorHandler; |
|
| 40 | + }); |
|
| 41 | 41 | |
| 42 | - //Bind CoreConfig Facade to the IoC Container |
|
| 43 | - \App::bind('CoreConfig', function() |
|
| 44 | - { |
|
| 45 | - return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
| 46 | - }); |
|
| 42 | + //Bind CoreConfig Facade to the IoC Container |
|
| 43 | + \App::bind('CoreConfig', function() |
|
| 44 | + { |
|
| 45 | + return new \App\Modules\V1\Core\Utl\CoreConfig; |
|
| 46 | + }); |
|
| 47 | 47 | |
| 48 | - $this->app->register(RouteServiceProvider::class); |
|
| 49 | - } |
|
| 48 | + $this->app->register(RouteServiceProvider::class); |
|
| 49 | + } |
|
| 50 | 50 | } |