aboutsummaryrefslogtreecommitdiff
path: root/src/controllers/UserController.php
diff options
context:
space:
mode:
authorCamil Staps2015-05-07 12:42:45 +0300
committerCamil Staps2015-05-07 12:42:45 +0300
commit1b38bff248875dc32b07187f17049b75226ebac5 (patch)
tree8c95a3da71f93610e5b756464c5f50ed557c4bde /src/controllers/UserController.php
parentAllow origin for requests config option (diff)
Validate register input
Diffstat (limited to 'src/controllers/UserController.php')
-rw-r--r--src/controllers/UserController.php12
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'));