diff options
author | Camil Staps | 2015-05-07 12:42:45 +0300 |
---|---|---|
committer | Camil Staps | 2015-05-07 12:42:45 +0300 |
commit | 1b38bff248875dc32b07187f17049b75226ebac5 (patch) | |
tree | 8c95a3da71f93610e5b756464c5f50ed557c4bde /src/controllers/UserController.php | |
parent | Allow origin for requests config option (diff) |
Validate register input
Diffstat (limited to 'src/controllers/UserController.php')
-rw-r--r-- | src/controllers/UserController.php | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php index 03bebbc..e52d8c3 100644 --- a/src/controllers/UserController.php +++ b/src/controllers/UserController.php @@ -4,6 +4,7 @@ namespace CamilStaps\BotleaguesApi; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Input; +use Illuminate\Support\Facades\Validator; class UserController extends BaseController { @@ -37,6 +38,17 @@ class UserController extends BaseController { } public function store() { + $rules = [ + 'email' => ['required', 'email'], + 'password' => ['required', 'min:7'] + ]; + $payload = Input::only('email', 'password'); + $validator = Validator::make($payload, $rules); + + if ($validator->fails()) { + throw new \Dingo\Api\Exception\StoreResourceFailedException('Could not create new user.', $validator->errors()); + } + $this->user->email = Input::get('email'); $this->user->password = empty(Input::get('password')) ? null : Hash::make(Input::get('password')); |