feat(giftcard): add customer giftcard/mine endpoint; fix admin/app password digit normalization
This commit is contained in:
+22
-2
@@ -129,12 +129,32 @@ class Customer extends Authenticatable implements JWTSubject
|
||||
->first();
|
||||
}
|
||||
|
||||
// hash password
|
||||
// hash password — ارقام فارسی/عربی را قبل از هش انگلیسی کن (لاگین اپ هم انگلیسی میفرستد)
|
||||
public function setPasswordAttribute($value){
|
||||
if ($value === null || $value === '') {
|
||||
return;
|
||||
}
|
||||
$this->attributes['password'] = Hash::make($value);
|
||||
$value = trim((string) $value);
|
||||
if ($value === '') {
|
||||
return;
|
||||
}
|
||||
// اگر از قبل bcrypt است دوباره هش نکن
|
||||
if (preg_match('/^\$2[ayb]\$.{56}$/', $value) === 1) {
|
||||
$this->attributes['password'] = $value;
|
||||
|
||||
return;
|
||||
}
|
||||
$this->attributes['password'] = Hash::make(self::normalizeCredentialDigits($value));
|
||||
}
|
||||
|
||||
/** ارقام فارسی/عربی → لاتین (برای رمز و موبایل در احراز هویت) */
|
||||
public static function normalizeCredentialDigits(string $value): string
|
||||
{
|
||||
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
|
||||
$latin = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
||||
return str_replace(array_merge($persian, $arabic), array_merge($latin, $latin), $value);
|
||||
}
|
||||
|
||||
public function setBirthDateAttribute($value): void
|
||||
|
||||
@@ -40,4 +40,9 @@ class GiftCardCodes extends Model
|
||||
return $this->belongsTo(Customer::class, 'assigned_to', 'id')->select('id', 'name', 'mobile');
|
||||
}
|
||||
|
||||
public function giftcard()
|
||||
{
|
||||
return $this->belongsTo(GiftCard::class, 'giftcard_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user