From b2888d0cdf579e4f9d3ec0a9bc5e75242bbc9d29 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Thu, 5 Mar 2020 15:44:06 +0100 Subject: [PATCH 1/3] [FEATURE] Laravel migrations (#359) --- .../2020_03_04_172425_create_hwid_table.php | 36 +++++++++++++++++++ ..._03_05_140131_add_auth_handler_collums.php | 36 +++++++++++++++++++ ..._03_05_142041_add_hwid_handler_collums.php | 32 +++++++++++++++++ compat/auth/laravel/migrations/README.MD | 1 + 4 files changed, 105 insertions(+) create mode 100644 compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php create mode 100644 compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php create mode 100644 compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php create mode 100644 compat/auth/laravel/migrations/README.MD diff --git a/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php b/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php new file mode 100644 index 00000000..db0c8b9f --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_04_172425_create_hwid_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->tinyInteger('isBanned')->default('0'); + $table->text('totalMemory'); + $table->text('serialNumber'); + $table->text('HWDiskSerial'); + $table->text('processorID'); + $table->text('macAddr'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('users_hwids'); + } +} diff --git a/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php b/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php new file mode 100644 index 00000000..8a456f60 --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_05_140131_add_auth_handler_collums.php @@ -0,0 +1,36 @@ +char('uuid', '36')->unique()->nullable(); + $table->char('accessToken', '32')->nullable(); + $table->string('serverID', '41')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('uuid'); + $table->dropColumn('accessToken'); + $table->dropColumn('serverID'); + }); + } +} diff --git a/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php b/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php new file mode 100644 index 00000000..5040340b --- /dev/null +++ b/compat/auth/laravel/migrations/2020_03_05_142041_add_hwid_handler_collums.php @@ -0,0 +1,32 @@ +bigInteger('hwid')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('hwid'); + }); + } +} diff --git a/compat/auth/laravel/migrations/README.MD b/compat/auth/laravel/migrations/README.MD new file mode 100644 index 00000000..856151ac --- /dev/null +++ b/compat/auth/laravel/migrations/README.MD @@ -0,0 +1 @@ +# Миграции для Laravel \ No newline at end of file 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 2/3] [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'); + }); + } +} From 606eca22aaa27d162665a6b5428eaa9d6b89c0a3 Mon Sep 17 00:00:00 2001 From: Zaxar163 <35835496+Zaxar163@users.noreply.github.com> Date: Thu, 5 Mar 2020 16:52:19 +0100 Subject: [PATCH 3/3] [ANY] Laravel auth controller (#361) --- .../authcontroller/LauncherAuthController.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/compat/auth/laravel/authcontroller/LauncherAuthController.php b/compat/auth/laravel/authcontroller/LauncherAuthController.php index 5d4b2732..6c41adc4 100644 --- a/compat/auth/laravel/authcontroller/LauncherAuthController.php +++ b/compat/auth/laravel/authcontroller/LauncherAuthController.php @@ -12,10 +12,9 @@ class LauncherAuthController extends Controller $data = json_decode($request->getContent()); if ($data->apiKey !== env('LAUNCHER_APIKEY')) { - $response = [ + return response()->json([ 'error' => 'Неверный ключ. Обратитесь к администратору', - ]; - return json_encode($response); + ]); } if (Auth::attempt(['name' => $data->username, 'password' => $data->password])) { @@ -24,15 +23,14 @@ class LauncherAuthController extends Controller ->where('name', '=', $data->username) ->first(); - $response = [ + return response()->json([ 'username' => $data->username, 'permission' => $perm->launcher_permission, - ]; + ]); } else { - $response = [ + return response()->json([ 'error' => 'Неверный логин или пароль', - ]; + ]); } - return json_encode($response); } }