blob: bf9d9590d9e96450262bfb9e855bfc2dc57ee794 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<?php
/**
* Created by PhpStorm.
* User: camilstaps
* Date: 13-5-15
* Time: 13:13
*/
namespace CamilStaps\BotleaguesApi\Controllers;
use CamilStaps\BotleaguesApi\Database\PasswordReminder;
use CamilStaps\BotleaguesApi\Exception\ValidationException;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
class PasswordReminderController extends BaseController {
protected $passwordReminder;
public function __construct(PasswordReminder $passwordReminder) {
$this->passwordReminder = $passwordReminder;
}
/**
* Set the userId and create a random token
*/
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());
}
$this->passwordReminder->userId = Input::get('user_id');
$this->passwordReminder->token = base64_encode(openssl_random_pseudo_bytes(64));
if ($this->passwordReminder->save()) {
return $this->passwordReminder;
} else {
throw new \Dingo\Api\Exception\StoreResourceFailedException;
}
}
}
|