Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/SignupCodeObserver.php
Show All 29 Lines | public function creating(SignupCode $code): void | ||||
$code->code = Str::random($code_length); | $code->code = Str::random($code_length); | ||||
if (!SignupCode::find($code->code)) { | if (!SignupCode::find($code->code)) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$code->expires_at = Carbon::now()->addHours($exp_hours); | $code->expires_at = Carbon::now()->addHours($exp_hours); | ||||
$code->ip_address = request()->ip(); | |||||
if ($code->email) { | |||||
$parts = explode('@', $code->email); | |||||
mollekopf: Is it save to assume that this is a valid email address here? Otherwise we'll crash below. | |||||
Done Inline ActionsWe validate the email in the controller. And as we don't want invalid emails in here, I think an error is what we actually want to happen on an invalid email. So, I would not change this. machniak: We validate the email in the controller. And as we don't want invalid emails in here, I think… | |||||
$code->local_part = $parts[0]; | |||||
$code->domain_part = $parts[1]; | |||||
} | |||||
} | |||||
/** | |||||
* Handle the "updating" event. | |||||
* | |||||
* @param SignupCode $code The code being updated. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function updating(SignupCode $code) | |||||
{ | |||||
if ($code->email) { | |||||
$parts = explode('@', $code->email); | |||||
$code->local_part = $parts[0]; | |||||
Not Done Inline ActionsSame as above. mollekopf: Same as above. | |||||
$code->domain_part = $parts[1]; | |||||
} else { | |||||
$code->local_part = null; | |||||
$code->domain_part = null; | |||||
} | |||||
} | } | ||||
} | } |
Is it save to assume that this is a valid email address here? Otherwise we'll crash below.
Maybe just do the ?? null if it's not guaranteed that email is valid.