mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for unique email rule
This commit is contained in:
parent
fabc45d162
commit
671760eda4
@ -114,7 +114,7 @@ class UserController extends BaseController
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(UpdateUserRequest $request)
|
public function update(UpdateUserRequest $request, User $user)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Http\Requests\User;
|
namespace App\Http\Requests\User;
|
||||||
|
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
|
use App\Http\ValidationRules\UniqueUserRule;
|
||||||
|
|
||||||
class UpdateUserRequest extends Request
|
class UpdateUserRequest extends Request
|
||||||
{
|
{
|
||||||
@ -31,10 +32,13 @@ class UpdateUserRequest extends Request
|
|||||||
|
|
||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$input = $this->all();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'first_name' => 'required|string|max:100',
|
'first_name' => 'required|string|max:100',
|
||||||
'last_name' => 'required|string:max:100',
|
'last_name' => 'required|string:max:100',
|
||||||
'email' => new UniqueUserRule(),
|
'email' => ['required', new UniqueUserRule($this->user, $input['email'])],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,18 @@ use Illuminate\Contracts\Validation\Rule;
|
|||||||
class UniqueUserRule implements Rule
|
class UniqueUserRule implements Rule
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public $user;
|
||||||
|
|
||||||
|
public $new_email;
|
||||||
|
|
||||||
|
public function __construct($user, $new_email)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->user= $user;
|
||||||
|
|
||||||
|
$this->new_email = $new_email;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $attribute
|
* @param string $attribute
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
@ -29,7 +41,12 @@ class UniqueUserRule implements Rule
|
|||||||
*/
|
*/
|
||||||
public function passes($attribute, $value)
|
public function passes($attribute, $value)
|
||||||
{
|
{
|
||||||
return ! $this->checkIfEmailExists($value); //if it exists, return false!
|
/* If the input has not changed, return early! */
|
||||||
|
|
||||||
|
if($this->user->email == $this->new_email)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return ! $this->checkIfEmailExists($value); //if it exists, return false!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,10 +91,10 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function boot(DispatcherContract $events)
|
public function boot()
|
||||||
{
|
{
|
||||||
|
|
||||||
parent::boot($events);
|
parent::boot();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,14 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Route::bind('client', function ($value) {
|
Route::bind('client', function ($value) {
|
||||||
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
// $client->with('contacts', 'primary_contact','country');
|
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::bind('user', function ($value) {
|
||||||
|
$user = \App\Models\User::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
|
return $user;
|
||||||
|
});
|
||||||
|
|
||||||
Route::bind('invoice', function ($value) {
|
Route::bind('invoice', function ($value) {
|
||||||
return \App\Models\Invoice::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
return \App\Models\Invoice::withTrashed()->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user