* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ namespace CamilStaps\BotleaguesApi; use CamilStaps\BotleaguesApi\Database\PasswordReminder; use CamilStaps\BotleaguesApi\Database\User; use Dingo\Api\Auth\Provider\Provider; use Dingo\Api\Routing\Route; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class ActivationCodeAuthenticationProvider implements Provider { /** * Authenticate the request and return the authenticated user instance. * * @param \Illuminate\Http\Request $request * @param \Dingo\Api\Routing\Route $route * * @throw UnauthorizedHttpException invalid authentication * * @return mixed */ public function authenticate(Request $request, Route $route) { $user = User::findOrFail($request->route('user')); $passwordReminder = PasswordReminder::findOrFail($request->route('password_reminder')); if (!empty($user) && !empty($passwordReminder) && $passwordReminder->userEmail == $user->email && $passwordReminder->isValid()) { Auth::login($user); return Auth::user(); } throw new UnauthorizedHttpException(null, "Invalid credentials"); } /** * Get the providers authorization method. * * @return string */ public function getAuthorizationMethod() { return 'activationcode'; } }