* * 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\Controllers; use CamilStaps\BotleaguesApi\Database\PasswordReminder; use CamilStaps\BotleaguesApi\Database\User; use Dingo\Api\Exception\StoreResourceFailedException; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Request; class PasswordReminderController extends BaseController { protected $passwordReminder; public function __construct(PasswordReminder $passwordReminder) { $this->passwordReminder = $passwordReminder; } /** * Set the userEmail and create a random token * @param $userEmail * @throws StoreResourceFailedException * @return PasswordReminder */ public function store($userEmail) { $user = User::findOrFail($userEmail); $this->passwordReminder->userEmail = $user->email; $this->passwordReminder->token = bin2hex(openssl_random_pseudo_bytes(24)); if ($this->passwordReminder->save()) { return $this->passwordReminder; } else { throw new StoreResourceFailedException; } } /** * Destroy the password reminder means setting a new password for the user * @param $userEmail * @param $reminderToken * @return null */ public function destroy($userEmail, $reminderToken) { $user = Auth::user(); $user->password = Request::get('password'); $user->save(); $this->passwordReminder = $this->passwordReminder->findOrFail($reminderToken); $this->passwordReminder->useToken(); return null; } }