From 39aa8530424310663c888f9e02224158961532e3 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 30 Oct 2018 18:41:29 +0100 Subject: PHP is crap --- .../Api/Controllers/DefaultApiController.php | 16 --- infrastructure/Api/routes_public.php | 3 - infrastructure/Auth/AuthServiceProvider.php | 41 ------- .../Auth/Controllers/LoginController.php | 38 ------ .../Exceptions/InvalidCredentialsException.php | 13 --- infrastructure/Auth/LoginProxy.php | 129 --------------------- .../Auth/Middleware/AccessTokenChecker.php | 37 ------ infrastructure/Auth/Requests/LoginRequest.php | 21 ---- infrastructure/Auth/routes_protected.php | 3 - infrastructure/Auth/routes_public.php | 4 - infrastructure/Console/Commands/StartServer.sh | 9 -- .../Console/Commands/StartServerCommand.php | 30 ----- .../Console/Commands/WebSocketServerCommand.php | 37 ------ infrastructure/Console/Kernel.php | 33 ------ infrastructure/Database/Eloquent/Model.php | 9 -- infrastructure/Database/Eloquent/Repository.php | 9 -- infrastructure/Events/Event.php | 8 -- .../Exceptions/Formatters/ExceptionFormatter.php | 30 ----- infrastructure/Exceptions/Handler.php | 50 -------- infrastructure/Http/ApiRequest.php | 21 ---- infrastructure/Http/Controller.php | 10 -- infrastructure/Http/Kernel.php | 47 -------- infrastructure/Http/Middleware/EncryptCookies.php | 17 --- infrastructure/Http/RouteServiceProvider.php | 23 ---- infrastructure/Http/WebSocketController.php | 56 --------- .../Validation/resources/lang/en/validation.php | 113 ------------------ infrastructure/Version.php | 12 -- 27 files changed, 819 deletions(-) delete mode 100644 infrastructure/Api/Controllers/DefaultApiController.php delete mode 100644 infrastructure/Api/routes_public.php delete mode 100644 infrastructure/Auth/AuthServiceProvider.php delete mode 100644 infrastructure/Auth/Controllers/LoginController.php delete mode 100644 infrastructure/Auth/Exceptions/InvalidCredentialsException.php delete mode 100644 infrastructure/Auth/LoginProxy.php delete mode 100644 infrastructure/Auth/Middleware/AccessTokenChecker.php delete mode 100644 infrastructure/Auth/Requests/LoginRequest.php delete mode 100644 infrastructure/Auth/routes_protected.php delete mode 100644 infrastructure/Auth/routes_public.php delete mode 100644 infrastructure/Console/Commands/StartServer.sh delete mode 100644 infrastructure/Console/Commands/StartServerCommand.php delete mode 100644 infrastructure/Console/Commands/WebSocketServerCommand.php delete mode 100644 infrastructure/Console/Kernel.php delete mode 100644 infrastructure/Database/Eloquent/Model.php delete mode 100644 infrastructure/Database/Eloquent/Repository.php delete mode 100644 infrastructure/Events/Event.php delete mode 100644 infrastructure/Exceptions/Formatters/ExceptionFormatter.php delete mode 100644 infrastructure/Exceptions/Handler.php delete mode 100644 infrastructure/Http/ApiRequest.php delete mode 100644 infrastructure/Http/Controller.php delete mode 100644 infrastructure/Http/Kernel.php delete mode 100644 infrastructure/Http/Middleware/EncryptCookies.php delete mode 100644 infrastructure/Http/RouteServiceProvider.php delete mode 100644 infrastructure/Http/WebSocketController.php delete mode 100644 infrastructure/Validation/resources/lang/en/validation.php delete mode 100644 infrastructure/Version.php (limited to 'infrastructure') diff --git a/infrastructure/Api/Controllers/DefaultApiController.php b/infrastructure/Api/Controllers/DefaultApiController.php deleted file mode 100644 index 1bb11bf..0000000 --- a/infrastructure/Api/Controllers/DefaultApiController.php +++ /dev/null @@ -1,16 +0,0 @@ -json([ - 'message' => 'Welcome to the official Texx API' - ]); - } -} diff --git a/infrastructure/Api/routes_public.php b/infrastructure/Api/routes_public.php deleted file mode 100644 index 3609ea8..0000000 --- a/infrastructure/Api/routes_public.php +++ /dev/null @@ -1,3 +0,0 @@ -get('/', 'DefaultApiController@index'); \ No newline at end of file diff --git a/infrastructure/Auth/AuthServiceProvider.php b/infrastructure/Auth/AuthServiceProvider.php deleted file mode 100644 index 7f09b7d..0000000 --- a/infrastructure/Auth/AuthServiceProvider.php +++ /dev/null @@ -1,41 +0,0 @@ - 'App\Policies\ModelPolicy', - ]; - - /** - * Register any authentication / authorization services. - * - * @return void - */ - public function boot() - { - $this->registerPolicies(); - - Passport::routes(function ($router) { - $router->forAccessTokens(); - // Uncomment for allowing personal access tokens - // $router->forPersonalAccessTokens(); - $router->forTransientTokens(); - }); - - Passport::tokensExpireIn(Carbon::now()->addYears(10)); - - Passport::refreshTokensExpireIn(Carbon::now()->addDays(365)); - } -} \ No newline at end of file diff --git a/infrastructure/Auth/Controllers/LoginController.php b/infrastructure/Auth/Controllers/LoginController.php deleted file mode 100644 index a72f8a0..0000000 --- a/infrastructure/Auth/Controllers/LoginController.php +++ /dev/null @@ -1,38 +0,0 @@ -loginProxy = $loginProxy; - } - - public function login(LoginRequest $request) - { - $email = $request->get('email'); - $password = $request->get('password'); - - return $this->response($this->loginProxy->attemptLogin($email, $password)); - } - - public function refresh(Request $request) - { - return $this->response($this->loginProxy->attemptRefresh()); - } - - public function logout() - { - $this->loginProxy->logout(); - - return $this->response(null, 204); - } -} \ No newline at end of file diff --git a/infrastructure/Auth/Exceptions/InvalidCredentialsException.php b/infrastructure/Auth/Exceptions/InvalidCredentialsException.php deleted file mode 100644 index 45a8b6e..0000000 --- a/infrastructure/Auth/Exceptions/InvalidCredentialsException.php +++ /dev/null @@ -1,13 +0,0 @@ -userRepository = $userRepository; - - $this->apiConsumer = $app->make('apiconsumer'); - $this->auth = $app->make('auth'); - $this->cookie = $app->make('cookie'); - $this->db = $app->make('db'); - $this->request = $app->make('request'); - } - - /** - * Attempt to create an access token using user credentials - * - * @param string $email - * @param string $password - */ - public function attemptLogin($email, $password) - { - $user = $this->userRepository->getWhere('email', $email)->first(); - - if (!is_null($user)) { - $TokenObject = $this->proxy('password', [ - 'username' => $email, - 'password' => $password - ]); - return array_merge($TokenObject, ['user_id' => $user->id]); - } - - - throw new InvalidCredentialsException(); - } - - /** - * Attempt to refresh the access token used a refresh token that - * has been saved in a cookie - */ - public function attemptRefresh() - { - $refreshToken = $this->request->cookie(self::REFRESH_TOKEN); - - return $this->proxy('refresh_token', [ - 'refresh_token' => $refreshToken - ]); - } - - /** - * Proxy a request to the OAuth server. - * - * @param string $grantType what type of grant type should be proxied - * @param array $data the data to send to the server - */ - public function proxy($grantType, array $data = []) - { - $data = array_merge($data, [ - 'client_id' => env('PASSWORD_CLIENT_ID'), - 'client_secret' => env('PASSWORD_CLIENT_SECRET'), - 'grant_type' => $grantType - ]); - - $response = $this->apiConsumer->post('/oauth/token', $data); - - if (!$response->isSuccessful()) { - throw new InvalidCredentialsException(); - } - - $data = json_decode($response->getContent()); - - // Create a refresh token cookie - $this->cookie->queue( - self::REFRESH_TOKEN, - $data->refresh_token, - 864000, // 10 days - null, - null, - false, - true // HttpOnly - ); - - return [ - 'access_token' => $data->access_token, - 'expires_in' => $data->expires_in - ]; - } - - /** - * Logs out the user. We revoke access token and refresh token. - * Also instruct the client to forget the refresh cookie. - */ - public function logout() - { - $accessToken = $this->auth->user()->token(); - - $refreshToken = $this->db - ->table('oauth_refresh_tokens') - ->where('access_token_id', $accessToken->id) - ->update([ - 'revoked' => true - ]); - - $accessToken->revoke(); - - $this->cookie->queue($this->cookie->forget(self::REFRESH_TOKEN)); - } -} diff --git a/infrastructure/Auth/Middleware/AccessTokenChecker.php b/infrastructure/Auth/Middleware/AccessTokenChecker.php deleted file mode 100644 index f79f5cb..0000000 --- a/infrastructure/Auth/Middleware/AccessTokenChecker.php +++ /dev/null @@ -1,37 +0,0 @@ -app = $app; - $this->authenticate = $authenticate; - } - - public function handle($request, Closure $next, $scopesString = null) - { - if ($this->app->environment() !== 'testing') { - try { - return $this->authenticate->handle($request, $next, 'api'); - } catch (AuthenticationException $e) { - throw new UnauthorizedHttpException('Challenge'); - } - } - - return $next($request); - } -} diff --git a/infrastructure/Auth/Requests/LoginRequest.php b/infrastructure/Auth/Requests/LoginRequest.php deleted file mode 100644 index 5c5a3bb..0000000 --- a/infrastructure/Auth/Requests/LoginRequest.php +++ /dev/null @@ -1,21 +0,0 @@ - 'required|email', - 'password' => 'required' - ]; - } -} diff --git a/infrastructure/Auth/routes_protected.php b/infrastructure/Auth/routes_protected.php deleted file mode 100644 index 0fe814f..0000000 --- a/infrastructure/Auth/routes_protected.php +++ /dev/null @@ -1,3 +0,0 @@ -post('/logout', 'LoginController@logout'); \ No newline at end of file diff --git a/infrastructure/Auth/routes_public.php b/infrastructure/Auth/routes_public.php deleted file mode 100644 index 79f5b51..0000000 --- a/infrastructure/Auth/routes_public.php +++ /dev/null @@ -1,4 +0,0 @@ -post('/login', 'LoginController@login'); -$router->post('/login/refresh', 'LoginController@refresh'); \ No newline at end of file diff --git a/infrastructure/Console/Commands/StartServer.sh b/infrastructure/Console/Commands/StartServer.sh deleted file mode 100644 index f9feaa8..0000000 --- a/infrastructure/Console/Commands/StartServer.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -e -redis-server & -PIDS[0]=$! -sudo php artisan serve --host 0.0.0.0 --port 80 & -PIDS[1]=$! - -trap "sudo kill ${PIDS[*]}" SIGINT - -wait diff --git a/infrastructure/Console/Commands/StartServerCommand.php b/infrastructure/Console/Commands/StartServerCommand.php deleted file mode 100644 index 03ec6f9..0000000 --- a/infrastructure/Console/Commands/StartServerCommand.php +++ /dev/null @@ -1,30 +0,0 @@ -line('Starting server...'); - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - exec("wsl bash infrastructure/Console/Commands/StartServer.sh"); - } else { - exec("bash infrastructure/Console/Commands/StartServer.sh"); - } - } -} \ No newline at end of file diff --git a/infrastructure/Console/Commands/WebSocketServerCommand.php b/infrastructure/Console/Commands/WebSocketServerCommand.php deleted file mode 100644 index 764e16a..0000000 --- a/infrastructure/Console/Commands/WebSocketServerCommand.php +++ /dev/null @@ -1,37 +0,0 @@ -line('Starting websocket...'); - $server->run(); - } -} \ No newline at end of file diff --git a/infrastructure/Console/Kernel.php b/infrastructure/Console/Kernel.php deleted file mode 100644 index 61173ff..0000000 --- a/infrastructure/Console/Kernel.php +++ /dev/null @@ -1,33 +0,0 @@ -command('inspire') - // ->hourly(); - } -} diff --git a/infrastructure/Database/Eloquent/Model.php b/infrastructure/Database/Eloquent/Model.php deleted file mode 100644 index a7781f7..0000000 --- a/infrastructure/Database/Eloquent/Model.php +++ /dev/null @@ -1,9 +0,0 @@ -setStatusCode(500); - $data = $response->getData(true); - - if ($this->debug) { - $data = array_merge($data, [ - 'code' => $e->getCode(), - 'message' => $e->getMessage(), - 'exception' => (string)$e, - 'line' => $e->getLine(), - 'file' => $e->getFile() - ]); - } else { - $data['message'] = $e->getMessage(); - } - - $response->setData($data); - } -} diff --git a/infrastructure/Exceptions/Handler.php b/infrastructure/Exceptions/Handler.php deleted file mode 100644 index af48a29..0000000 --- a/infrastructure/Exceptions/Handler.php +++ /dev/null @@ -1,50 +0,0 @@ -errors()->toJson()); - } - - protected function failedAuthorization() - { - throw new HttpException(403); - } -} diff --git a/infrastructure/Http/Controller.php b/infrastructure/Http/Controller.php deleted file mode 100644 index aa567b9..0000000 --- a/infrastructure/Http/Controller.php +++ /dev/null @@ -1,10 +0,0 @@ - \Infrastructure\Auth\Middleware\AccessTokenChecker::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, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - ]; -} diff --git a/infrastructure/Http/Middleware/EncryptCookies.php b/infrastructure/Http/Middleware/EncryptCookies.php deleted file mode 100644 index 80b8da3..0000000 --- a/infrastructure/Http/Middleware/EncryptCookies.php +++ /dev/null @@ -1,17 +0,0 @@ -app->make(Router::class); - - $router->pattern('id', '[0-9]+'); - - parent::boot($router); - } -} diff --git a/infrastructure/Http/WebSocketController.php b/infrastructure/Http/WebSocketController.php deleted file mode 100644 index 19e0868..0000000 --- a/infrastructure/Http/WebSocketController.php +++ /dev/null @@ -1,56 +0,0 @@ -connections[$conn->resourceId] = compact('conn') + ['user_id' => null]; - } - - /** - * This is called before or after a socket is closed (depends on how it's closed). SendMessage to $conn will not result in an error if it has already been closed. - * @param ConnectionInterface $conn The socket/connection that is closing/closed - * @throws \Exception - */ - function onClose(ConnectionInterface $conn) - { - $disconnectedId = $conn->resourceId; - unset($this->connections[$disconnectedId]); - } - - /** - * If there is an error with one of the sockets, or somewhere in the application where an Exception is thrown, - * the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method - * @param ConnectionInterface $conn - * @param \Exception $e - * @throws \Exception - */ - function onError(ConnectionInterface $conn, \Exception $e) - { - unset($this->connections[$conn->resourceId]); - $conn->close(); - } - - /** - * Triggered when a client sends data through the socket - * @param \Ratchet\ConnectionInterface $conn The socket/connection that sent the message to your application - * @param string $msg The message received - * @throws \Exception - */ - function onMessage(ConnectionInterface $conn, $msg) - { - - } -} \ No newline at end of file diff --git a/infrastructure/Validation/resources/lang/en/validation.php b/infrastructure/Validation/resources/lang/en/validation.php deleted file mode 100644 index 208281b..0000000 --- a/infrastructure/Validation/resources/lang/en/validation.php +++ /dev/null @@ -1,113 +0,0 @@ - 'The :attribute must be accepted.', - 'active_url' => 'The :attribute is not a valid URL.', - 'after' => 'The :attribute must be a date after :date.', - 'alpha' => 'The :attribute may only contain letters.', - 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', - 'alpha_num' => 'The :attribute may only contain letters and numbers.', - 'array' => 'The :attribute must be an array.', - 'before' => 'The :attribute must be a date before :date.', - 'between' => [ - 'numeric' => 'The :attribute must be between :min and :max.', - 'file' => 'The :attribute must be between :min and :max kilobytes.', - 'string' => 'The :attribute must be between :min and :max characters.', - 'array' => 'The :attribute must have between :min and :max items.', - ], - 'boolean' => 'The :attribute must be true or false.', - 'confirmed' => 'The :attribute confirmation does not match.', - 'date' => 'The :attribute is not a valid date.', - 'date_format' => 'The :attribute does not match the format :format.', - 'different' => 'The :attribute and :other must be different.', - 'digits' => 'The :attribute must be :digits digits.', - 'digits_between' => 'The :attribute must be between :min and :max digits.', - 'distinct' => 'The :attribute has a duplicate value.', - 'email' => 'The :attribute must be a valid email address.', - 'exists' => 'The selected :attribute is invalid.', - 'filled' => 'The :attribute is required.', - 'image' => 'The :attribute must be an image.', - 'in' => 'The selected :attribute is invalid.', - 'in_array' => 'The :attribute does not exist in :other.', - 'integer' => 'The :attribute must be an integer.', - 'ip' => 'The :attribute must be a valid IP address.', - 'json' => 'The :attribute must be a valid JSON string.', - 'max' => [ - 'numeric' => 'The :attribute may not be greater than :max.', - 'file' => 'The :attribute may not be greater than :max kilobytes.', - 'string' => 'The :attribute may not be greater than :max characters.', - 'array' => 'The :attribute may not have more than :max items.', - ], - 'mimes' => 'The :attribute must be a file of type: :values.', - 'min' => [ - 'numeric' => 'The :attribute must be at least :min.', - 'file' => 'The :attribute must be at least :min kilobytes.', - 'string' => 'The :attribute must be at least :min characters.', - 'array' => 'The :attribute must have at least :min items.', - ], - 'not_in' => 'The selected :attribute is invalid.', - 'numeric' => 'The :attribute must be a number.', - 'present' => 'The :attribute must be present.', - 'regex' => 'The :attribute format is invalid.', - 'required' => 'The :attribute is required.', - 'required_if' => 'The :attribute is required when :other is :value.', - 'required_unless' => 'The :attribute is required unless :other is in :values.', - 'required_with' => 'The :attribute is required when :values is present.', - 'required_with_all' => 'The :attribute is required when :values is present.', - 'required_without' => 'The :attribute is required when :values is not present.', - 'required_without_all' => 'The :attribute is required when none of :values are present.', - 'same' => 'The :attribute and :other must match.', - 'size' => [ - 'numeric' => 'The :attribute must be :size.', - 'file' => 'The :attribute must be :size kilobytes.', - 'string' => 'The :attribute must be :size characters.', - 'array' => 'The :attribute must contain :size items.', - ], - 'string' => 'The :attribute must be a string.', - 'timezone' => 'The :attribute must be a valid zone.', - 'unique' => 'The :attribute has already been taken.', - 'url' => 'The :attribute format is invalid.', - - /* - |-------------------------------------------------------------------------- - | Custom Validation Language Lines - |-------------------------------------------------------------------------- - | - | Here you may specify custom validation messages for attributes using the - | convention "attribute.rule" to name the lines. This makes it quick to - | specify a specific custom language line for a given attribute rule. - | - */ - - 'custom' => [ - 'attribute-name' => [ - 'rule-name' => 'custom-message', - ], - ], - - /* - |-------------------------------------------------------------------------- - | Custom Validation Attributes - |-------------------------------------------------------------------------- - | - | The following language lines are used to swap attribute place-holders - | with something more reader friendly such as E-Mail Address instead - | of "email". This simply helps us make messages a little cleaner. - | - */ - - 'attributes' => [], - -]; diff --git a/infrastructure/Version.php b/infrastructure/Version.php deleted file mode 100644 index 9ca7941..0000000 --- a/infrastructure/Version.php +++ /dev/null @@ -1,12 +0,0 @@ -