2016-03-08 22:22:59 +01:00
|
|
|
<?php namespace app\Http\Requests;
|
|
|
|
|
|
|
|
use Auth;
|
2016-03-13 13:46:51 +01:00
|
|
|
use App\Http\Requests\Request;
|
|
|
|
use Illuminate\Http\Request as InputRequest;
|
2016-03-13 12:46:59 +01:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2016-03-08 22:22:59 +01:00
|
|
|
use Illuminate\Validation\Factory;
|
2016-03-13 12:39:20 +01:00
|
|
|
use App\Libraries\Utils;
|
|
|
|
use Response;
|
2016-03-08 22:22:59 +01:00
|
|
|
|
|
|
|
class RegisterRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2016-03-13 13:46:51 +01:00
|
|
|
|
|
|
|
public function __construct(InputRequest $req)
|
|
|
|
{
|
|
|
|
$this->req = $req;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-08 22:22:59 +01:00
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-03-13 13:41:33 +01:00
|
|
|
public function rules()
|
2016-03-08 22:22:59 +01:00
|
|
|
{
|
2016-03-13 13:34:42 +01:00
|
|
|
|
2016-03-08 22:22:59 +01:00
|
|
|
$rules = [
|
|
|
|
'email' => 'required|unique:users',
|
|
|
|
'first_name' => 'required',
|
|
|
|
'last_name' => 'required',
|
|
|
|
'password' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
2016-03-13 12:39:20 +01:00
|
|
|
|
2016-03-13 13:09:11 +01:00
|
|
|
public function response(array $errors)
|
2016-03-13 12:39:20 +01:00
|
|
|
{
|
2016-03-13 13:49:51 +01:00
|
|
|
/* If the user is not validating from a mobile app - pass through parent::response*/
|
2016-03-13 13:46:51 +01:00
|
|
|
if(!isset($this->req->api_secret))
|
|
|
|
return parent::response($errors);
|
|
|
|
|
2016-03-13 13:49:51 +01:00
|
|
|
/* If the user is validating from a mobile app - pass through first error string and return error*/
|
|
|
|
foreach($errors as $error) {
|
|
|
|
foreach ($error as $key => $value) {
|
2016-03-13 12:59:01 +01:00
|
|
|
|
2016-03-13 13:49:51 +01:00
|
|
|
$message['error'] = ['message'=>$value];
|
|
|
|
$message = json_encode($error, JSON_PRETTY_PRINT);
|
2016-03-13 12:56:44 +01:00
|
|
|
$headers = Utils::getApiHeaders();
|
2016-03-13 12:39:20 +01:00
|
|
|
|
2016-03-13 13:49:51 +01:00
|
|
|
return Response::make($message, 400, $headers);
|
2016-03-13 12:56:44 +01:00
|
|
|
}
|
2016-03-13 12:41:08 +01:00
|
|
|
}
|
2016-03-13 12:39:20 +01:00
|
|
|
}
|
2016-03-13 13:20:56 +01:00
|
|
|
|
2016-03-08 22:22:59 +01:00
|
|
|
}
|