Skip to content

Commit 035041d

Browse files
author
Addin Gama Bertaqwa
committed
dispatch EmailCheck event when success login and register
1 parent c82e738 commit 035041d

File tree

7 files changed

+116
-8
lines changed

7 files changed

+116
-8
lines changed

app/Events/EmailCheck.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Queue\SerializesModels;
7+
use Illuminate\Broadcasting\PrivateChannel;
8+
use Illuminate\Broadcasting\PresenceChannel;
9+
use Illuminate\Foundation\Events\Dispatchable;
10+
use Illuminate\Broadcasting\InteractsWithSockets;
11+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
12+
13+
class EmailCheck
14+
{
15+
use Dispatchable, InteractsWithSockets, SerializesModels;
16+
17+
public $email;
18+
19+
/**
20+
* Create a new event instance.
21+
*
22+
* @return void
23+
*/
24+
public function __construct($email)
25+
{
26+
$this->email = $email;
27+
}
28+
29+
/**
30+
* Get the channels the event should broadcast on.
31+
*
32+
* @return Channel|array
33+
*/
34+
public function broadcastOn()
35+
{
36+
return new PrivateChannel('channel-name');
37+
}
38+
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Http\Controllers\Auth;
44

5+
use App\Events\EmailCheck;
56
use App\Http\Controllers\Controller;
67
use Illuminate\Foundation\Auth\AuthenticatesUsers;
8+
use Illuminate\Http\Request;
79

810
class LoginController extends Controller
911
{
@@ -36,4 +38,15 @@ public function __construct()
3638
{
3739
$this->middleware('guest')->except('logout');
3840
}
41+
42+
43+
/**
44+
* Override authenticated function from Illuminate\Foundation\Auth\AuthenticatesUsers
45+
* @param Request $request
46+
* @param $user
47+
*/
48+
public function authenticated(Request $request, $user)
49+
{
50+
event(new EmailCheck($user->email));
51+
}
3952
}

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Http\Controllers\Auth;
44

5+
use App\Events\EmailCheck;
56
use App\User;
67
use App\Http\Controllers\Controller;
8+
use Illuminate\Http\Request;
79
use Illuminate\Support\Facades\Validator;
810
use Illuminate\Foundation\Auth\RegistersUsers;
911

@@ -68,4 +70,16 @@ protected function create(array $data)
6870
'password' => bcrypt($data['password']),
6971
]);
7072
}
73+
74+
/**
75+
* The user has been registered.
76+
*
77+
* @param \Illuminate\Http\Request $request
78+
* @param mixed $user
79+
* @return mixed
80+
*/
81+
public function registered(Request $request, $user)
82+
{
83+
event(new EmailCheck($user->email));
84+
}
7185
}

app/Http/Controllers/TMoney/GeneralController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use GuzzleHttp\Exception\BadResponseException;
77
use Illuminate\Http\Request;
88
use App\Http\Controllers\Controller;
9-
use Illuminate\Http\Response;
10-
use Illuminate\Support\Facades\Config;
11-
use Illuminate\Support\Facades\Log;
129
use Illuminate\Support\Facades\Session;
1310

1411
class GeneralController extends Controller

app/Listeners/EmailCheckListener.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Listeners;
4+
5+
use App\Events\EmailCheck;
6+
use GuzzleHttp\Exception\BadResponseException;
7+
use Illuminate\Queue\InteractsWithQueue;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use Illuminate\Support\Facades\Log;
10+
11+
class EmailCheckListener implements ShouldQueue
12+
{
13+
/**
14+
* Create the event listener.
15+
*
16+
* @return void
17+
*/
18+
public function __construct()
19+
{
20+
//
21+
}
22+
23+
/**
24+
* Handle the event.
25+
*
26+
* @param EmailCheck $event
27+
* @return void
28+
*/
29+
public function handle(EmailCheck $event)
30+
{
31+
try {
32+
$response = emailCheck($event->email);
33+
$body = $response->getBody();
34+
$json = json_decode($body);
35+
if ($json->resultCode == 188) {
36+
// TODO: dispatch signup event
37+
dd($json);
38+
}
39+
} catch (BadResponseException $e) {
40+
Log::info($e->getMessage());
41+
}
42+
}
43+
}

app/Providers/EventServiceProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ class EventServiceProvider extends ServiceProvider
1313
* @var array
1414
*/
1515
protected $listen = [
16-
'App\Events\Event' => [
17-
'App\Listeners\EventListener',
16+
'App\Events\EmailCheck' => [
17+
'App\Listeners\EmailCheckListener',
1818
],
19+
'App\Events\SignUp' => [
20+
'App\Listeners\SignUpListener'
21+
]
1922
];
2023

2124
/**

config/tmoney.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
* Time: 20.33
77
*/
88

9-
$production = "https://prodapi-app.tmoney.co.id/api/";
10-
$sandbox = "https://api-sandbox-app.tmoney.co.id/api/";
9+
$production = "https://prodapi-app.tmoney.co.id/api";
10+
$sandbox = "https://api-sandbox-app.tmoney.co.id/api";
1111
$accessTokenProduction = "T-MONEY_cc80ada3203052d4e5fe44678a981d88";
1212
$accessTokenSandbox = "T-MONEY_PUBLICKEYSANDBOX";
1313

14-
$mainapiSandbox = "https://api.mainapi.net/tmoney/1.0.0";
14+
$mainapiSandbox = "https://api.mainapi.net/tmoney/1.0.0-sandbox";
1515

1616
return [
1717
'base_url' => $sandbox,

0 commit comments

Comments
 (0)