Skip to content

Commit

Permalink
fix rule unique issue and logout user on email change (#19)
Browse files Browse the repository at this point in the history
* fix rule unique issue and logout user on email change

* some changes

* refactor

Signed-off-by: Sam Poyigi <[email protected]>

---------

Signed-off-by: Sam Poyigi <[email protected]>
Co-authored-by: Sam Poyigi <[email protected]>
  • Loading branch information
obinnaelviso and sampoyigi authored Feb 5, 2024
1 parent b6e9645 commit 06ff32e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Http/Controllers/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Users extends \Igniter\Admin\Classes\AdminController
'configFile' => 'user',
];

public $locationConfig = [
public array $locationConfig = [
'addAbsenceConstraint' => false,
];

Expand Down Expand Up @@ -90,7 +90,13 @@ public function account_onSave()
$usernameChanged = $this->currentUser->username != post('User[username]');
$passwordChanged = strlen(post('User[password]'));
$languageChanged = $this->currentUser->language != post('User[language_id]');
if ($usernameChanged || $passwordChanged || $languageChanged) {
$emailChanged = $this->currentUser->email != post('User[email]');

Check failure on line 93 in src/Http/Controllers/Users.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\User\Models\User::$email.

Check failure on line 93 in src/Http/Controllers/Users.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\User\Models\User::$email.
if ($emailChanged || $passwordChanged) {
AdminAuth::logout();

Check failure on line 95 in src/Http/Controllers/Users.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\AdminAuth::logout().

Check failure on line 95 in src/Http/Controllers/Users.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\AdminAuth::logout().
return redirect('/logout');
}

if ($usernameChanged || $languageChanged) {
$this->currentUser->reload()->reloadRelations();
AdminAuth::login($this->currentUser, true);
}
Expand Down
9 changes: 9 additions & 0 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 @@ -46,4 +47,12 @@ public function rules()
'locations.*' => ['integer'],
];
}

protected function getRecordId(): string
{
$slugName = ($slug = $this->route('slug'))
? str_after($slug, '/') : null;

return $slugName == 'account' ? AdminAuth::id() : $slugName;

Check failure on line 56 in src/Requests/UserRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Facades\AdminAuth::id().

Check failure on line 56 in src/Requests/UserRequest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Facades\AdminAuth::id().
}
}

0 comments on commit 06ff32e

Please sign in to comment.