mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-21 23:04:45 +03:00
[FEATURE] Laravel auth controller (#360)
This commit is contained in:
parent
b2888d0cdf
commit
c44384ccb2
3 changed files with 79 additions and 0 deletions
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LauncherAuthController extends Controller
|
||||
{
|
||||
public function json(Request $request) {
|
||||
$data = json_decode($request->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);
|
||||
}
|
||||
}
|
9
compat/auth/laravel/authcontroller/README.MD
Normal file
9
compat/auth/laravel/authcontroller/README.MD
Normal file
|
@ -0,0 +1,9 @@
|
|||
#Контроллер авторизации методом json
|
||||
|
||||
Route:
|
||||
```php
|
||||
Route::put('launcher/auth', 'LauncherAuthController@json');
|
||||
```
|
||||
|
||||
Добавить в **.env** строку `LAUNCHER_APIKEY=none`
|
||||
Где `none` ваш apiKey
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddPermissionCollum extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->integer('launcher_permission')->default('0');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('launcher_permission');
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue