diff options
Diffstat (limited to 'src/controllers/PasswordReminderController.php')
-rw-r--r-- | src/controllers/PasswordReminderController.php | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/controllers/PasswordReminderController.php b/src/controllers/PasswordReminderController.php index bf9d959..b3fd8da 100644 --- a/src/controllers/PasswordReminderController.php +++ b/src/controllers/PasswordReminderController.php @@ -9,9 +9,10 @@ namespace CamilStaps\BotleaguesApi\Controllers; use CamilStaps\BotleaguesApi\Database\PasswordReminder; -use CamilStaps\BotleaguesApi\Exception\ValidationException; -use Illuminate\Support\Facades\Input; -use Illuminate\Support\Facades\Validator; +use CamilStaps\BotleaguesApi\Database\User; +use Dingo\Api\Exception\StoreResourceFailedException; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Request; class PasswordReminderController extends BaseController { @@ -23,25 +24,33 @@ class PasswordReminderController extends BaseController { /** * Set the userId and create a random token + * @param $userId + * @throws StoreResourceFailedException + * @return PasswordReminder */ - public function store() { - $rules = [ - 'user_id' => ['required'] - ]; - $payload = Input::only('user_id'); - $validator = Validator::make($payload, $rules); - if ($validator->fails()) { - throw new ValidationException('Could not find user.', $validator->errors()); - } + public function store($userId) { + $user = User::findOrFail($userId); - $this->passwordReminder->userId = Input::get('user_id'); - $this->passwordReminder->token = base64_encode(openssl_random_pseudo_bytes(64)); + $this->passwordReminder->userId = $user->id; + $this->passwordReminder->token = bin2hex(openssl_random_pseudo_bytes(24)); if ($this->passwordReminder->save()) { return $this->passwordReminder; } else { - throw new \Dingo\Api\Exception\StoreResourceFailedException; + throw new StoreResourceFailedException; } } + /** + * Destroy the password reminder means setting a new password for the user + * @param Request $request + * @param $userId + */ + public function destroy($userId, $reminderToken) { + $user = Auth::user(); + $user->password = Request::get('password'); + $user->save(); + return null; + } + }
\ No newline at end of file |