7
7
namespace Jrean \UserVerification ;
8
8
9
9
use Illuminate \Contracts \Auth \Authenticatable as AuthenticatableContract ;
10
- use Illuminate \Contracts \Mail \Mailer as MailerContract ;
10
+ /* use Illuminate\Contracts\Mail\Mailer as MailerContract; */
11
+ use Illuminate \Mail \Mailer ;
11
12
use Illuminate \Database \Schema \Builder ;
12
13
use Illuminate \Support \Facades \DB ;
13
14
use Illuminate \Support \Str ;
@@ -24,7 +25,7 @@ class UserVerification
24
25
/**
25
26
* Mailer instance.
26
27
*
27
- * @var \Illuminate\Contracts\ Mail\Mailer
28
+ * @var \Illuminate\Mail\Mailer
28
29
*/
29
30
protected $ mailer ;
30
31
@@ -38,11 +39,11 @@ class UserVerification
38
39
/**
39
40
* Create a new instance.
40
41
*
41
- * @param \Illuminate\Contracts\ Mail\Mailer $mailer
42
+ * @param \Illuminate\Mail\Mailer $mailer
42
43
* @param \Illuminate\Database\Schema\Builder $schema
43
44
* @return void
44
45
*/
45
- public function __construct (MailerContract $ mailer , Builder $ schema )
46
+ public function __construct (Mailer $ mailer , Builder $ schema )
46
47
{
47
48
$ this ->mailer = $ mailer ;
48
49
$ this ->schema = $ schema ;
@@ -98,21 +99,24 @@ protected function saveToken(AuthenticatableContract $user, $token)
98
99
* @param string $subject
99
100
* @param string $from
100
101
* @param string $name
101
- * @return bool
102
+ * @return void
102
103
*
103
104
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
104
105
*/
105
- public function send (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
106
+ public function send (
107
+ AuthenticatableContract $ user ,
108
+ $ subject = null ,
109
+ $ from = null ,
110
+ $ name = null
111
+ )
106
112
{
107
113
if (! $ this ->isCompliant ($ user )) {
108
114
throw new ModelNotCompliantException ();
109
115
}
110
116
111
- $ status = (boolean ) $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
112
-
113
- if ($ status ) event (new VerificationEmailSent ($ user ));
117
+ $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
114
118
115
- return $ status ;
119
+ event ( new VerificationEmailSent ( $ user )) ;
116
120
}
117
121
118
122
/**
@@ -122,46 +126,118 @@ public function send(AuthenticatableContract $user, $subject, $from = null, $nam
122
126
* @param string $subject
123
127
* @param string $from
124
128
* @param string $name
125
- * @return bool
129
+ * @return void
126
130
*
127
131
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
128
132
*/
129
- public function sendQueue (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
133
+ public function sendQueue (
134
+ AuthenticatableContract $ user ,
135
+ $ subject = null ,
136
+ $ from = null ,
137
+ $ name = null
138
+ )
130
139
{
131
140
if (! $ this ->isCompliant ($ user )) {
132
141
throw new ModelNotCompliantException ();
133
142
}
134
143
135
- $ status = (boolean ) $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
136
-
137
- if ($ status ) event (new VerificationEmailSent ($ user ));
144
+ $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
138
145
139
- return $ status ;
146
+ event ( new VerificationEmailSent ( $ user )) ;
140
147
}
141
148
142
149
/**
143
150
* Send later by e-mail a link containing the verification token.
144
151
*
145
- * @param int $seconds
152
+ * @param \DateTime $delay
146
153
* @param \Illuminate\Contracts\Auth\Authenticatable $user
147
154
* @param string $subject
148
155
* @param string $from
149
156
* @param string $name
150
- * @return bool
157
+ * @return void
151
158
*
152
159
* @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
153
160
*/
154
- public function sendLater ($ seconds , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
161
+ public function sendLater (
162
+ $ delay ,
163
+ AuthenticatableContract $ user ,
164
+ $ subject = null ,
165
+ $ from = null ,
166
+ $ name = null
167
+ )
155
168
{
156
169
if (! $ this ->isCompliant ($ user )) {
157
170
throw new ModelNotCompliantException ();
158
171
}
159
172
160
- $ status = (boolean ) $ this ->emailLaterVerificationLink ($ seconds , $ user , $ subject , $ from , $ name );
173
+ $ this ->emailLaterVerificationLink ($ delay , $ user , $ subject , $ from , $ name );
174
+
175
+ event (new VerificationEmailSent ($ user ));
176
+ }
161
177
162
- if ($ status ) event (new VerificationEmailSent ($ user ));
178
+ /**
179
+ * Prepare and send the e-mail with the verification token link.
180
+ *
181
+ * @param \Illuminate\Contracts\Auth\Authenticatable $user
182
+ * @param string $subject
183
+ * @param string $from
184
+ * @param string $name
185
+ * @return mixed
186
+ */
187
+ protected function emailVerificationLink (
188
+ AuthenticatableContract $ user ,
189
+ $ subject = null ,
190
+ $ from = null ,
191
+ $ name = null
192
+ )
193
+ {
194
+ return $ this ->mailer
195
+ ->to ($ user ->email )
196
+ ->send (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
197
+ }
163
198
164
- return $ status ;
199
+ /**
200
+ * Prepare and push a job onto the queue to send the e-mail with the verification token link.
201
+ *
202
+ * @param \Illuminate\Contracts\Auth\Authenticatable $user
203
+ * @param string $subject
204
+ * @param string $from
205
+ * @param string $name
206
+ * @return mixed
207
+ */
208
+ protected function emailQueueVerificationLink (
209
+ AuthenticatableContract $ user ,
210
+ $ subject = null ,
211
+ $ from = null ,
212
+ $ name = null
213
+ )
214
+ {
215
+ return $ this ->mailer
216
+ ->to ($ user ->email )
217
+ ->queue (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
218
+ }
219
+
220
+ /**
221
+ * Prepare and delay the sending of the e-mail with the verification token link.
222
+ *
223
+ * @param \DateTime $delay
224
+ * @param \Illuminate\Contracts\Auth\Authenticatable $user
225
+ * @param string $subject
226
+ * @param string $from
227
+ * @param string $name
228
+ * @return mixed
229
+ */
230
+ protected function emailLaterVerificationLink (
231
+ $ delay ,
232
+ AuthenticatableContract $ user ,
233
+ $ subject = null ,
234
+ $ from = null ,
235
+ $ name = null
236
+ )
237
+ {
238
+ return $ this ->mailer
239
+ ->to ($ user ->email )
240
+ ->later ($ delay , new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
165
241
}
166
242
167
243
/**
@@ -176,6 +252,8 @@ public function process($email, $token, $userTable)
176
252
{
177
253
$ user = $ this ->getUserByEmail ($ email , $ userTable );
178
254
255
+ // Check if the given user is already verified.
256
+ // If he is, we stop here.
179
257
$ this ->isVerified ($ user );
180
258
181
259
$ this ->verifyToken ($ user ->verification_token , $ token );
@@ -271,55 +349,6 @@ protected function updateUser($user)
271
349
]);
272
350
}
273
351
274
- /**
275
- * Prepare and send the e-mail with the verification token link.
276
- *
277
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
278
- * @param string $subject
279
- * @param string $from
280
- * @param string $name
281
- * @return mixed
282
- */
283
- protected function emailVerificationLink (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
284
- {
285
- return $ this ->mailer
286
- ->to ($ user ->email )
287
- ->send (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
288
- }
289
-
290
- /**
291
- * Prepare and push a job onto the queue to send the e-mail with the verification token link.
292
- *
293
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
294
- * @param string $subject
295
- * @param string $from
296
- * @param string $name
297
- * @return mixed
298
- */
299
- protected function emailQueueVerificationLink (AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
300
- {
301
- return $ this ->mailer
302
- ->to ($ user ->email )
303
- ->queue (new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
304
- }
305
-
306
- /**
307
- * Prepare and delay the sending of the e-mail with the verification token link.
308
- *
309
- * @param int $seconds
310
- * @param \Illuminate\Contracts\Auth\Authenticatable $user
311
- * @param string $subject
312
- * @param string $from
313
- * @param string $name
314
- * @return mixed
315
- */
316
- protected function emailLaterVerificationLink ($ seconds , AuthenticatableContract $ user , $ subject , $ from = null , $ name = null )
317
- {
318
- return $ this ->mailer
319
- ->to ($ user ->email )
320
- ->later ($ seconds , new VerificationTokenGenerated ($ user , $ subject , $ from , $ name ));
321
- }
322
-
323
352
/**
324
353
* Determine if the given model table has the verified and verification_token
325
354
* columns.
0 commit comments