[FEATURE] Laravel auth controller (#360)

This commit is contained in:
Zaxar163 2020-03-05 16:39:02 +01:00 committed by GitHub
parent b2888d0cdf
commit c44384ccb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -0,0 +1,9 @@
#Контроллер авторизации методом json
Route:
```php
Route::put('launcher/auth', 'LauncherAuthController@json');
```
Добавить в **.env** строку `LAUNCHER_APIKEY=none`
Где `none` ваш apiKey

View file

@ -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');
});
}
}