mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for user validation
This commit is contained in:
parent
105b5c967b
commit
040e8cf72f
@ -38,9 +38,7 @@ class UpdateUserRequest extends Request
|
||||
'password' => 'nullable|string|min:6',
|
||||
];
|
||||
|
||||
if (isset($input['email'])) {
|
||||
$rules['email'] = ['email', 'sometimes', new UniqueUserRule($this->user, $input['email'])];
|
||||
}
|
||||
$rules['email'] = ['email', 'sometimes', new UniqueUserRule($this->user, $input['email'])];
|
||||
|
||||
if (Ninja::isHosted() && $this->phone_has_changed && $this->phone && isset($this->phone)) {
|
||||
$rules['phone'] = ['sometimes', 'bail', 'string', new HasValidPhoneNumber()];
|
||||
@ -53,9 +51,11 @@ class UpdateUserRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if (array_key_exists('email', $input)) {
|
||||
if (isset($input['email']) && is_string($input['email']) && strlen($input['email']) > 2) {
|
||||
$input['email'] = trim($input['email']);
|
||||
}
|
||||
elseif(isset($input['email']))
|
||||
$input['email'] = false;
|
||||
|
||||
if (array_key_exists('first_name', $input)) {
|
||||
$input['first_name'] = strip_tags($input['first_name']);
|
||||
|
@ -109,6 +109,74 @@ class UserTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testValidEmailUpdate()
|
||||
{
|
||||
|
||||
$company_token = $this->mockAccount();
|
||||
$user = $company_token->user;
|
||||
$user->load('company_user');
|
||||
|
||||
$data = $user->toArray();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $company_token->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->putJson('/api/v1/users/'.$user->hashed_id.'?include=company_user', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testNullEmail()
|
||||
{
|
||||
|
||||
$company_token = $this->mockAccount();
|
||||
$user = $company_token->user;
|
||||
$user->load('company_user');
|
||||
|
||||
$data = $user->toArray();
|
||||
$data['email'] = '';
|
||||
unset($data['password']);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $company_token->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->putJson('/api/v1/users/'.$user->hashed_id.'?include=company_user', $data);
|
||||
|
||||
$response->assertStatus(422);
|
||||
|
||||
$data = $user->toArray();
|
||||
unset($data['password']);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $company_token->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->putJson('/api/v1/users/'.$user->hashed_id.'?include=company_user', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$data = $user->toArray();
|
||||
|
||||
$data['email'] = $this->faker->unique()->safeEmail();
|
||||
unset($data['password']);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $company_token->token,
|
||||
'X-API-PASSWORD' => 'ALongAndBriliantPassword',
|
||||
])->putJson('/api/v1/users/'.$user->hashed_id.'?include=company_user', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals($arr['data']['email'], $data['email']);
|
||||
}
|
||||
|
||||
|
||||
public function testUserLocale()
|
||||
{
|
||||
$this->user->language_id = "13";
|
||||
|
Loading…
x
Reference in New Issue
Block a user