From 1b38bff248875dc32b07187f17049b75226ebac5 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Thu, 7 May 2015 12:42:45 +0300
Subject: Validate register input

---
 src/controllers/UserController.php | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'src/controllers/UserController.php')

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'));
 
-- 
cgit v1.2.3