Skip to content

Commit

Permalink
fix: update password attribute handling and validation in user models…
Browse files Browse the repository at this point in the history
… (v4)

Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Sep 22, 2024
1 parent 71d14b8 commit b7fb310
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/models/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
'condition' => 'unchecked',
],
],
'_confirm_password' => [
'confirm_password' => [
'label' => 'lang:igniter.user::default.customers.label_confirm_password',
'type' => 'password',
'span' => 'right',
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/InjectImpersonateBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function handle($request, \Closure $next): Response
{
$response = $next($request);

if (Igniter::runningInAdmin()) {
if (!$request->routeIs('igniter.theme.*') || Igniter::runningInAdmin()) {
return $response;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/CustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function attributes()
'addresses.*.postcode' => lang('igniter.user::default.customers.label_postcode'),
'addresses.*.country_id' => lang('igniter.user::default.customers.label_country'),
'password' => lang('igniter.user::default.customers.label_password'),
'_confirm_password' => lang('igniter.user::default.customers.label_confirm_password'),
'confirm_password' => lang('igniter.user::default.customers.label_confirm_password'),
];
}

Expand All @@ -33,7 +33,7 @@ public function rules()
'first_name' => ['required', 'string', 'between:1,48'],
'last_name' => ['required', 'string', 'between:1,48'],
'email' => ['required', 'email:filter', 'max:96', Rule::unique('customers')->ignore($this->getRecordId(), 'customer_id')],
'password' => ['nullable', 'required_if:send_invite,0', 'string', 'min:8', 'max:40', 'same:_confirm_password'],
'password' => ['nullable', 'required_if:send_invite,0', 'string', 'min:8', 'max:40', 'same:confirm_password'],
'telephone' => ['nullable', 'string'],
'newsletter' => ['nullable', 'required', 'boolean'],
'customer_group_id' => ['required', 'integer'],
Expand Down
1 change: 1 addition & 0 deletions src/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Customer extends AuthUserModel

protected $casts = [
'customer_id' => 'integer',
'password' => 'hashed',
'address_id' => 'integer',
'customer_group_id' => 'integer',
'newsletter' => 'boolean',
Expand Down
4 changes: 2 additions & 2 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Igniter\User\Classes\PermissionManager;
use Igniter\User\Classes\UserState;
use Igniter\User\Models\Concerns\SendsInvite;
use Illuminate\Support\Facades\Hash;

/**
* Users Model Class
Expand Down Expand Up @@ -43,6 +42,7 @@ class User extends AuthUserModel
protected $hidden = ['password', 'remember_token'];

protected $casts = [
'password' => 'hashed',
'user_role_id' => 'integer',
'sale_permission' => 'integer',
'language_id' => 'integer',
Expand Down Expand Up @@ -314,7 +314,7 @@ public function register(array $attributes, $activate = false)
$user->name = array_get($attributes, 'name');
$user->email = array_get($attributes, 'email');
$user->username = array_get($attributes, 'username');
$user->password = Hash::make(array_get($attributes, 'password'));
$user->password = array_get($attributes, 'password');
$user->language_id = array_get($attributes, 'language_id');
$user->user_role_id = array_get($attributes, 'user_role_id');
$user->super_user = array_get($attributes, 'super_user', false);
Expand Down

0 comments on commit b7fb310

Please sign in to comment.