From c44384ccb2658d7ffbccde5f07d33ca357f4ee78 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Thu, 5 Mar 2020 16:39:02 +0100 Subject: [PATCH] [FEATURE] Laravel auth controller (#360) --- .../authcontroller/LauncherAuthController.php | 38 +++++++++++++++++++ compat/auth/laravel/authcontroller/README.MD | 9 +++++ ...020_03_05_151322_add_permission_collum.php | 32 ++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 compat/auth/laravel/authcontroller/LauncherAuthController.php create mode 100644 compat/auth/laravel/authcontroller/README.MD create mode 100644 compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php diff --git a/compat/auth/laravel/authcontroller/LauncherAuthController.php b/compat/auth/laravel/authcontroller/LauncherAuthController.php new file mode 100644 index 00000000..5d4b2732 --- /dev/null +++ b/compat/auth/laravel/authcontroller/LauncherAuthController.php @@ -0,0 +1,38 @@ +getContent()); + + if ($data->apiKey !== env('LAUNCHER_APIKEY')) { + $response = [ + 'error' => 'Неверный ключ. Обратитесь к администратору', + ]; + return json_encode($response); + } + + if (Auth::attempt(['name' => $data->username, 'password' => $data->password])) { + $perm = DB::table('users') + ->select('launcher_permission') + ->where('name', '=', $data->username) + ->first(); + + $response = [ + 'username' => $data->username, + 'permission' => $perm->launcher_permission, + ]; + } else { + $response = [ + 'error' => 'Неверный логин или пароль', + ]; + } + return json_encode($response); + } +} diff --git a/compat/auth/laravel/authcontroller/README.MD b/compat/auth/laravel/authcontroller/README.MD new file mode 100644 index 00000000..d09d30bd --- /dev/null +++ b/compat/auth/laravel/authcontroller/README.MD @@ -0,0 +1,9 @@ +#Контроллер авторизации методом json + +Route: +```php +Route::put('launcher/auth', 'LauncherAuthController@json'); +``` + +Добавить в **.env** строку `LAUNCHER_APIKEY=none` +Где `none` ваш apiKey \ No newline at end of file diff --git a/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php b/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php new file mode 100644 index 00000000..d82e5eb2 --- /dev/null +++ b/compat/auth/laravel/authcontroller/migrations/2020_03_05_151322_add_permission_collum.php @@ -0,0 +1,32 @@ +integer('launcher_permission')->default('0'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('launcher_permission'); + }); + } +}