Skip to content

Commit

Permalink
fix rule unique issue and logout user on email change
Browse files Browse the repository at this point in the history
  • Loading branch information
obinnaelviso committed Jan 7, 2024
1 parent 8a4bfdf commit 26c0c9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Http/Controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public function account_onSave()
$usernameChanged = $this->currentUser->username != post('User[username]');
$passwordChanged = strlen(post('User[password]'));
$languageChanged = $this->currentUser->language != post('User[language_id]');
$emailChanged = $this->currentUser->email != post('User[email]');
if ($emailChanged) {
AdminAuth::logout();
return redirect('/admin/login');
}
if ($usernameChanged || $passwordChanged || $languageChanged) {
$this->currentUser->reload()->reloadRelations();
AdminAuth::login($this->currentUser, true);
Expand Down
5 changes: 3 additions & 2 deletions src/Requests/UserRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Igniter\User\Requests;

use Igniter\System\Classes\FormRequest;
use Igniter\User\Facades\AdminAuth;
use Illuminate\Validation\Rule;

class UserRequest extends FormRequest
Expand Down Expand Up @@ -30,10 +31,10 @@ public function rules()
return [
'name' => ['required', 'string', 'between:2,255'],
'email' => ['required', 'max:96', 'email:filter',
Rule::unique('admin_users')->ignore($this->getRecordId(), 'user_id'),
Rule::unique('admin_users')->ignore(AdminAuth::id(), 'user_id'),
],
'username' => ['required', 'alpha_dash', 'between:2,32',
Rule::unique('admin_users')->ignore($this->getRecordId(), 'user_id'),
Rule::unique('admin_users')->ignore(AdminAuth::id(), 'user_id'),
],
'password' => ['sometimes', 'required_if:send_invite,0', 'string', 'between:6,32', 'same:password_confirm'],
'status' => ['boolean'],
Expand Down

0 comments on commit 26c0c9e

Please sign in to comment.