1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Http/Requests/RegisterRequest.php

70 lines
1.6 KiB
PHP
Raw Normal View History

2016-03-08 22:22:59 +01:00
<?php namespace app\Http\Requests;
use Auth;
use App\Http\Requests\Request;
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:06:26 +01:00
public function __construct(array $query, array $request, array $attributes, array $cookies, array $files, array $server, $content)
{
parent::__construct($query, $request, $attributes, $cookies, $files, $server, $content);
$this->request = $request;
}
2016-03-08 22:22:59 +01:00
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$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:08:31 +01:00
public function response($errors)
2016-03-13 12:39:20 +01:00
{
2016-03-13 13:04:27 +01:00
2016-03-13 13:06:26 +01:00
if(!isset($this->request->api_secret))
2016-03-13 13:04:27 +01:00
return parent::response($errors);
2016-03-13 12:39:20 +01:00
2016-03-13 12:46:59 +01:00
Log::info($errors);
2016-03-13 12:56:44 +01:00
2016-03-13 12:41:08 +01:00
foreach($errors as $err) {
2016-03-13 12:56:44 +01:00
foreach ($err as $key => $value) {
2016-03-13 12:59:01 +01:00
Log::info($err);
Log::info($key);
Log::info($value);
2016-03-13 13:02:07 +01:00
$error['error'] = ['message'=>$value];
2016-03-13 12:56:44 +01:00
$error = json_encode($error, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
2016-03-13 12:39:20 +01:00
2016-03-13 12:56:44 +01:00
return Response::make($error, 400, $headers);
}
2016-03-13 12:41:08 +01:00
}
2016-03-13 12:39:20 +01:00
}
2016-03-08 22:22:59 +01:00
}