diff --git a/src/app/Mail/SignupVerification.php b/src/app/Mail/SignupVerification.php index 78481671..9036420f 100644 --- a/src/app/Mail/SignupVerification.php +++ b/src/app/Mail/SignupVerification.php @@ -1,57 +1,63 @@ code = $code; } /** * Build the message. * * @return $this */ public function build() { $href = sprintf( '%s/signup/%s-%s', \config('app.url'), $this->code->short_code, $this->code->code ); + $username = $this->code->data['first_name'] ?? ''; + if (!empty($this->code->data['last_name'])) { + $username .= ' ' . $this->code->data['last_name']; + } + $username = trim($username); + $this->view('emails.signup_code') ->subject(__('mail.signupcode-subject', ['site' => \config('app.name')])) ->with([ 'site' => \config('app.name'), - 'username' => $this->code->data['name'], + 'username' => $username ?: 'User', 'code' => $this->code->code, 'short_code' => $this->code->short_code, 'link' => sprintf('%s', $href, $href), ]); return $this; } } diff --git a/src/tests/Feature/SignupCodeTest.php b/src/tests/Feature/SignupCodeTest.php index d285aa35..78321c21 100644 --- a/src/tests/Feature/SignupCodeTest.php +++ b/src/tests/Feature/SignupCodeTest.php @@ -1,54 +1,53 @@ [ 'email' => 'User@email.org', - 'name' => 'User Name', ] ]; $now = Carbon::now(); $code = SignupCode::create($data); $this->assertFalse($code->isExpired()); $this->assertTrue(strlen($code->code) === SignupCode::CODE_LENGTH); $this->assertTrue( strlen($code->short_code) === env( 'VERIFICATION_CODE_LENGTH', SignupCode::SHORTCODE_LENGTH ) ); $this->assertSame($data['data'], $code->data); $this->assertInstanceOf(Carbon::class, $code->expires_at); $this->assertSame( env('SIGNUP_CODE_EXPIRY', SignupCode::CODE_EXP_HOURS), $code->expires_at->diffInHours($now) + 1 ); $inst = SignupCode::find($code->code); $this->assertInstanceOf(SignupCode::class, $inst); $this->assertSame($inst->code, $code->code); } } diff --git a/src/tests/Unit/Mail/SignupVerificationTest.php b/src/tests/Unit/Mail/SignupVerificationTest.php index 32138a21..5f72b366 100644 --- a/src/tests/Unit/Mail/SignupVerificationTest.php +++ b/src/tests/Unit/Mail/SignupVerificationTest.php @@ -1,38 +1,39 @@ 'code', 'short_code' => 'short-code', 'data' => [ 'email' => 'test@email', - 'name' => 'Test Name', + 'first_name' => 'First', + 'last_name' => 'Last', ], ]); $mail = new SignupVerification($code); $html = $mail->build()->render(); $url = \config('app.url') . '/signup/' . $code->short_code . '-' . $code->code; $link = "$url"; $this->assertSame(\config('app.name') . ' Registration', $mail->subject); $this->assertStringStartsWith('', $html); $this->assertTrue(strpos($html, $link) > 0); - $this->assertTrue(strpos($html, $code->data['name']) > 0); + $this->assertTrue(strpos($html, 'First Last') > 0); } }