invoiceninja/app/Http/Requests/RegisterRequest.php

62 lines
1.5 KiB
PHP
Raw Normal View History

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