DEV.XFOR.TOP

Email: dev@xfor.top Skype: utz0r2 Github: utz0r2
CSSHTMLPHPJSVideoNoty
E-commerce Scripts: vvStore | vvShop | Avox
© 2008 – 2020
Вернуться
» » » laravel / airlock - легковесная система аутентификации для SPA и простых API

laravel / airlock - легковесная система аутентификации для SPA и простых API

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\ValidationException;

Route::post('/airlock/token', function (Request $request) {
    $request->validate([
        'email' => 'required|email',
        'password' => 'required',
        'device_name' => 'required'
    ]);

    $user = User::where('email', $request->email)->first();

    if (! $user || ! Hash::check($request->password, $user->password)) {
        throw ValidationException::withMessages([
            'email' => ['The provided credentials are incorrect.'],
        ]);
    }

    return $user->createToken($request->device_name)->plainTextToken;
});

https://github.com/laravel/airlock
Оставить комментарий
Вверх