Skip to content

Commit 3f04137

Browse files
authored
Merge pull request #60 from BinaryStudioAcademy/feature/invitation-email
Implement mail queue
2 parents fbe9889 + 10c3913 commit 3f04137

File tree

8 files changed

+105
-5
lines changed

8 files changed

+105
-5
lines changed

backend/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ MAIL_PORT=2525
2929
MAIL_USERNAME=null
3030
MAIL_PASSWORD=null
3131
MAIL_ENCRYPTION=null
32+
MAIL_FROM_ADDRESS=
33+
MAIL_FROM_NAME=
3234

3335
AWS_ACCESS_KEY_ID=
3436
AWS_SECRET_ACCESS_KEY=
@@ -48,3 +50,5 @@ JWT_SECRET=
4850
MYSQL_PORT=33061
4951
APP_PORT=7777
5052
MYSQL_PORT_TEST_DB=33062
53+
54+
BEANSTALKD_HOST=

backend/app/Action/Auth/RegisterAction.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
namespace App\Action\Auth;
66

77
use App\Repository\UserRepository;
8+
use Illuminate\Mail\Mailer;
9+
use App\Mail\WelcomeEmail;
810

911
final class RegisterAction
1012
{
1113
private $userRepository;
14+
private $mailer;
1215

13-
public function __construct(UserRepository $userRepository)
16+
public function __construct(UserRepository $userRepository, Mailer $mailer)
1417
{
1518
$this->userRepository = $userRepository;
19+
$this->mailer = $mailer;
1620
}
1721

1822
public function execute(RegisterRequest $request): AuthenticationResponse
@@ -23,13 +27,14 @@ public function execute(RegisterRequest $request): AuthenticationResponse
2327
'name' => $request->getName(),
2428
'nickname' => $request->getNickname()
2529
]);
26-
2730
$token = auth()->login($user);
2831

32+
$this->mailer->to($user)->send(new WelcomeEmail());
33+
2934
return new AuthenticationResponse(
3035
$token,
3136
'bearer',
3237
auth()->factory()->getTTL() * 60
3338
);
3439
}
35-
}
40+
}

backend/app/Mail/WelcomeEmail.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Mail;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Mail\Mailable;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
10+
class WelcomeEmail extends Mailable implements ShouldQueue
11+
{
12+
use Queueable, SerializesModels;
13+
14+
/**
15+
* Build the message.
16+
*
17+
* @return $this
18+
*/
19+
public function build()
20+
{
21+
return $this->subject('Welcome!')->view('emails.welcome');
22+
}
23+
}

backend/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"fideloper/proxy": "^4.0",
1616
"laravel/framework": "5.8.*",
1717
"laravel/tinker": "^1.0",
18+
"pda/pheanstalk": "^4.0",
1819
"tymon/jwt-auth": "1.0.*"
1920
},
2021
"require-dev": {

backend/composer.lock

Lines changed: 54 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/config/queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
'beanstalkd' => [
4545
'driver' => 'beanstalkd',
46-
'host' => 'localhost',
46+
'host' => env('BEANSTALKD_HOST', 'localhost'),
4747
'queue' => 'default',
4848
'retry_after' => 90,
4949
'block_for' => 0,

backend/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ services:
4646
- MYSQL_DATABASE=thread-testing
4747
- MYSQL_USER=user
4848
- MYSQL_PASSWORD=secret
49+
50+
beanstalkd:
51+
image: schickling/beanstalkd
52+
container_name: thread-beanstalkd
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Welcome!</title>
6+
</head>
7+
<body>
8+
Welcome to Thread application!
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)