11
11
use Illuminate \Database \Schema \Builder ;
12
12
use Illuminate \Support \Facades \DB ;
13
13
use Illuminate \Support \Str ;
14
+ use Jrean \UserVerification \Mail \VerificationTokenGenerated ;
14
15
use Jrean \UserVerification \Events \UserVerified ;
15
16
use Jrean \UserVerification \Events \VerificationEmailSent ;
16
17
use Jrean \UserVerification \Exceptions \ModelNotCompliantException ;
17
- use Jrean \UserVerification \Exceptions \UserNotFoundException ;
18
- use Jrean \UserVerification \Exceptions \UserIsVerifiedException ;
19
18
use Jrean \UserVerification \Exceptions \TokenMismatchException ;
19
+ use Jrean \UserVerification \Exceptions \UserIsVerifiedException ;
20
+ use Jrean \UserVerification \Exceptions \UserNotFoundException ;
20
21
21
22
class UserVerification
22
23
{
@@ -34,13 +35,6 @@ class UserVerification
34
35
*/
35
36
protected $ schema ;
36
37
37
- /**
38
- * E-mail view name.
39
- *
40
- * @var string
41
- */
42
- protected $ emailView ;
43
-
44
38
/**
45
39
* Create a new instance.
46
40
*
@@ -50,9 +44,8 @@ class UserVerification
50
44
*/
51
45
public function __construct (MailerContract $ mailer , Builder $ schema )
52
46
{
53
- $ this ->mailer = $ mailer ;
54
- $ this ->schema = $ schema ;
55
- $ this ->emailView = 'laravel-user-verification::email ' ;
47
+ $ this ->mailer = $ mailer ;
48
+ $ this ->schema = $ schema ;
56
49
}
57
50
58
51
/**
@@ -109,13 +102,17 @@ protected function saveToken(AuthenticatableContract $user, $token)
109
102
*
110
103
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
111
104
*/
112
- public function send (AuthenticatableContract $ user , $ subject = null , $ from = null , $ name = null )
105
+ public function send (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
113
106
{
114
107
if (! $ this ->isCompliant ($ user )) {
115
108
throw new ModelNotCompliantException ();
116
109
}
117
110
118
- return (boolean ) $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
111
+ $ status = (boolean ) $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
112
+
113
+ if ($ status ) event (new VerificationEmailSent ($ user ));
114
+
115
+ return $ status ;
119
116
}
120
117
121
118
/**
@@ -129,34 +126,17 @@ public function send(AuthenticatableContract $user, $subject = null, $from = nul
129
126
*
130
127
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
131
128
*/
132
- public function sendQueue (AuthenticatableContract $ user , $ subject = null , $ from = null , $ name = null )
129
+ public function sendQueue (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
133
130
{
134
131
if (! $ this ->isCompliant ($ user )) {
135
132
throw new ModelNotCompliantException ();
136
133
}
137
134
138
- return (boolean ) $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
139
- }
135
+ $ status = (boolean ) $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
140
136
141
- /**
142
- * Queue on the given queue and send by e-mail a link containing the verification token.
143
- *
144
- * @param string $queue
145
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
146
- * @param string $subject
147
- * @param string $from
148
- * @param string $name
149
- * @return bool
150
- *
151
- * @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
152
- */
153
- public function sendQueueOn ($ queue , AuthenticatableContract $ user , $ subject = null , $ from = null , $ name = null )
154
- {
155
- if (! $ this ->isCompliant ($ user )) {
156
- throw new ModelNotCompliantException ();
157
- }
137
+ if ($ status ) event (new VerificationEmailSent ($ user ));
158
138
159
- return ( boolean ) $ this -> emailQueueOnVerificationLink ( $ queue , $ user , $ subject , $ from , $ name ) ;
139
+ return $ status ;
160
140
}
161
141
162
142
/**
@@ -171,48 +151,17 @@ public function sendQueueOn($queue, AuthenticatableContract $user, $subject = nu
171
151
*
172
152
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
173
153
*/
174
- public function sendLater ($ seconds , AuthenticatableContract $ user , $ subject = null , $ from = null , $ name = null )
154
+ public function sendLater ($ seconds , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
175
155
{
176
156
if (! $ this ->isCompliant ($ user )) {
177
157
throw new ModelNotCompliantException ();
178
158
}
179
159
180
- return (boolean ) $ this ->emailLaterVerificationLink ($ seconds , $ user , $ subject , $ from , $ name );
181
- }
160
+ $ status = (boolean ) $ this ->emailLaterVerificationLink ($ seconds , $ user , $ subject , $ from , $ name );
182
161
183
- /**
184
- * Send later on the given queue by e-mail a link containing the verification token.
185
- *
186
- * @param string $queue
187
- * @param int $seconds
188
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
189
- * @param string $subject
190
- * @param string $from
191
- * @param string $name
192
- * @return bool
193
- *
194
- * @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
195
- */
196
- public function sendLaterOn ($ queue , $ seconds , AuthenticatableContract $ user , $ subject = null , $ from = null , $ name = null )
197
- {
198
- if (! $ this ->isCompliant ($ user )) {
199
- throw new ModelNotCompliantException ();
200
- }
162
+ if ($ status ) event (new VerificationEmailSent ($ user ));
201
163
202
- return (boolean ) $ this ->emailLaterOnVerificationLink ($ queue , $ seconds , $ user , $ subject , $ from , $ name );
203
- }
204
-
205
- /**
206
- * Set the e-mail view name.
207
- *
208
- * @param string $name
209
- * @return \Jrean\UserVerification
210
- */
211
- public function emailView ($ name )
212
- {
213
- $ this ->emailView = $ name ;
214
-
215
- return $ this ;
164
+ return $ status ;
216
165
}
217
166
218
167
/**
@@ -333,17 +282,9 @@ protected function updateUser($user)
333
282
*/
334
283
protected function emailVerificationLink (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
335
284
{
336
- return $ this ->mailer ->send ($ this ->emailView , compact ('user ' ), function ($ m ) use ($ user , $ subject , $ from , $ name ) {
337
- if (! empty ($ from )) {
338
- $ m ->from ($ from , $ name );
339
- }
340
-
341
- $ m ->to ($ user ->email );
342
-
343
- $ m ->subject (is_null ($ subject ) ? trans ('laravel-user-verification::user-verification.verification_email_subject ' ) : $ subject );
344
-
345
- event (new VerificationEmailSent ($ user ));
346
- });
285
+ return $ this ->mailer
286
+ ->to ($ user ->email )
287
+ ->send (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
347
288
}
348
289
349
290
/**
@@ -357,46 +298,13 @@ protected function emailVerificationLink(AuthenticatableContract $user, $subject
357
298
*/
358
299
protected function emailQueueVerificationLink (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
359
300
{
360
- return $ this ->mailer ->queue ($ this ->emailView , compact ('user ' ), function ($ m ) use ($ user , $ subject , $ from , $ name ) {
361
- if (! empty ($ from )) {
362
- $ m ->from ($ from , $ name );
363
- }
364
-
365
- $ m ->to ($ user ->email );
366
-
367
- $ m ->subject (is_null ($ subject ) ? trans ('laravel-user-verification::user-verification.verification_email_subject ' ) : $ subject );
368
-
369
- event (new VerificationEmailSent ($ user ));
370
- });
301
+ return $ this ->mailer
302
+ ->to ($ user ->email )
303
+ ->queue (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
371
304
}
372
305
373
306
/**
374
- * Prepare and push a job onto the given queue to send the e-mail with the verification token link.
375
- *
376
- * @param string $queue
377
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
378
- * @param string $subject
379
- * @param string $from
380
- * @param string $name
381
- * @return mixed
382
- */
383
- protected function emailQueueOnVerificationLink ($ queue , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
384
- {
385
- return $ this ->mailer ->queueOn ($ queue , $ this ->emailView , compact ('user ' ), function ($ m ) use ($ user , $ subject , $ from , $ name ) {
386
- if (! empty ($ from )) {
387
- $ m ->from ($ from , $ name );
388
- }
389
-
390
- $ m ->to ($ user ->email );
391
-
392
- $ m ->subject (is_null ($ subject ) ? trans ('laravel-user-verification::user-verification.verification_email_subject ' ) : $ subject );
393
-
394
- event (new VerificationEmailSent ($ user ));
395
- });
396
- }
397
-
398
- /**
399
- * Prepare and send later the e-mail with the verification token link.
307
+ * Prepare and delay the sending of the e-mail with the verification token link.
400
308
*
401
309
* @param int $seconds
402
310
* @param \Illuminate\Contracts\Auth\Authenticatable $user
@@ -407,42 +315,9 @@ protected function emailQueueOnVerificationLink($queue, AuthenticatableContract
407
315
*/
408
316
protected function emailLaterVerificationLink ($ seconds , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
409
317
{
410
- return $ this ->mailer ->later ($ seconds , $ this ->emailView , compact ('user ' ), function ($ m ) use ($ user , $ subject , $ from , $ name ) {
411
- if (! empty ($ from )) {
412
- $ m ->from ($ from , $ name );
413
- }
414
-
415
- $ m ->to ($ user ->email );
416
-
417
- $ m ->subject (is_null ($ subject ) ? trans ('laravel-user-verification::user-verification.verification_email_subject ' ) : $ subject );
418
-
419
- event (new VerificationEmailSent ($ user ));
420
- });
421
- }
422
-
423
- /**
424
- * Prepare and send later on the given queue the e-mail with the verification token link.
425
- *
426
- * @param int $seconds
427
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
428
- * @param string $subject
429
- * @param string $from
430
- * @param string $name
431
- * @return mixed
432
- */
433
- protected function emailLaterOnVerificationLink ($ queue , $ seconds , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
434
- {
435
- return $ this ->mailer ->laterOn ($ queue , $ seconds , $ this ->emailView , compact ('user ' ), function ($ m ) use ($ user , $ subject , $ from , $ name ) {
436
- if (! empty ($ from )) {
437
- $ m ->from ($ from , $ name );
438
- }
439
-
440
- $ m ->to ($ user ->email );
441
-
442
- $ m ->subject (is_null ($ subject ) ? trans ('laravel-user-verification::user-verification.verification_email_subject ' ) : $ subject );
443
-
444
- event (new VerificationEmailSent ($ user ));
445
- });
318
+ return $ this ->mailer
319
+ ->to ($ user ->email )
320
+ ->later ($ seconds , new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
446
321
}
447
322
448
323
/**
@@ -455,8 +330,9 @@ protected function emailLaterOnVerificationLink($queue, $seconds, Authenticatabl
455
330
protected function isCompliant (AuthenticatableContract $ user )
456
331
{
457
332
return $ this ->hasColumn ($ user , 'verified ' )
458
- && $ this ->hasColumn ($ user , 'verification_token ' ) ?
459
- true : false ;
333
+ && $ this ->hasColumn ($ user , 'verification_token ' )
334
+ ? true
335
+ : false ;
460
336
}
461
337
462
338
/**
0 commit comments