2020-03-05 18:39:02 +03:00
|
|
|
<?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')) {
|
2020-03-05 18:52:19 +03:00
|
|
|
return response()->json([
|
2020-03-05 18:39:02 +03:00
|
|
|
'error' => 'Неверный ключ. Обратитесь к администратору',
|
2020-03-05 18:52:19 +03:00
|
|
|
]);
|
2020-03-05 18:39:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Auth::attempt(['name' => $data->username, 'password' => $data->password])) {
|
|
|
|
$perm = DB::table('users')
|
|
|
|
->select('launcher_permission')
|
|
|
|
->where('name', '=', $data->username)
|
|
|
|
->first();
|
|
|
|
|
2020-03-05 18:52:19 +03:00
|
|
|
return response()->json([
|
2020-03-05 18:39:02 +03:00
|
|
|
'username' => $data->username,
|
|
|
|
'permission' => $perm->launcher_permission,
|
2020-03-05 18:52:19 +03:00
|
|
|
]);
|
2020-03-05 18:39:02 +03:00
|
|
|
} else {
|
2020-03-05 18:52:19 +03:00
|
|
|
return response()->json([
|
2020-03-05 18:39:02 +03:00
|
|
|
'error' => 'Неверный логин или пароль',
|
2020-03-05 18:52:19 +03:00
|
|
|
]);
|
2020-03-05 18:39:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|