77namespace Jrean \UserVerification ;
88
99use 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 ;
1112use Illuminate \Database \Schema \Builder ;
1213use Illuminate \Support \Facades \DB ;
1314use Illuminate \Support \Str ;
@@ -24,7 +25,7 @@ class UserVerification
2425 /**
2526 * Mailer instance.
2627 *
27- * @var \Illuminate\Contracts\ Mail\Mailer
28+ * @var \Illuminate\Mail\Mailer
2829 */
2930 protected $ mailer ;
3031
@@ -38,11 +39,11 @@ class UserVerification
3839 /**
3940 * Create a new instance.
4041 *
41- * @param \Illuminate\Contracts\ Mail\Mailer $mailer
42+ * @param \Illuminate\Mail\Mailer $mailer
4243 * @param \Illuminate\Database\Schema\Builder $schema
4344 * @return void
4445 */
45- public function __construct (MailerContract $ mailer , Builder $ schema )
46+ public function __construct (Mailer $ mailer , Builder $ schema )
4647 {
4748 $ this ->mailer = $ mailer ;
4849 $ this ->schema = $ schema ;
@@ -98,21 +99,24 @@ protected function saveToken(AuthenticatableContract $user, $token)
9899 * @param string $subject
99100 * @param string $from
100101 * @param string $name
101- * @return bool
102+ * @return void
102103 *
103104 * @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
104105 */
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+ )
106112 {
107113 if (! $ this ->isCompliant ($ user )) {
108114 throw new ModelNotCompliantException ();
109115 }
110116
111- $ status = (boolean ) $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
112-
113- if ($ status ) event (new VerificationEmailSent ($ user ));
117+ $ this ->emailVerificationLink ($ user , $ subject , $ from , $ name );
114118
115- return $ status ;
119+ event ( new VerificationEmailSent ( $ user )) ;
116120 }
117121
118122 /**
@@ -122,46 +126,118 @@ public function send(AuthenticatableContract $user, $subject, $from = null, $nam
122126 * @param string $subject
123127 * @param string $from
124128 * @param string $name
125- * @return bool
129+ * @return void
126130 *
127131 * @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
128132 */
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+ )
130139 {
131140 if (! $ this ->isCompliant ($ user )) {
132141 throw new ModelNotCompliantException ();
133142 }
134143
135- $ status = (boolean ) $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
136-
137- if ($ status ) event (new VerificationEmailSent ($ user ));
144+ $ this ->emailQueueVerificationLink ($ user , $ subject , $ from , $ name );
138145
139- return $ status ;
146+ event ( new VerificationEmailSent ( $ user )) ;
140147 }
141148
142149 /**
143150 * Send later by e-mail a link containing the verification token.
144151 *
145- * @param int $seconds
152+ * @param \DateTime $delay
146153 * @param \Illuminate\Contracts\Auth\Authenticatable $user
147154 * @param string $subject
148155 * @param string $from
149156 * @param string $name
150- * @return bool
157+ * @return void
151158 *
152159 * @throws \Jrean\UserVerification\Exceptions\ModelNotCompliantException
153160 */
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+ )
155168 {
156169 if (! $ this ->isCompliant ($ user )) {
157170 throw new ModelNotCompliantException ();
158171 }
159172
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+ }
161177
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+ }
163198
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 ));
165241 }
166242
167243 /**
@@ -176,6 +252,8 @@ public function process($email, $token, $userTable)
176252 {
177253 $ user = $ this ->getUserByEmail ($ email , $ userTable );
178254
255+ // Check if the given user is already verified.
256+ // If he is, we stop here.
179257 $ this ->isVerified ($ user );
180258
181259 $ this ->verifyToken ($ user ->verification_token , $ token );
@@ -271,55 +349,6 @@ protected function updateUser($user)
271349 ]);
272350 }
273351
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-
323352 /**
324353 * Determine if the given model table has the verified and verification_token
325354 * columns.
0 commit comments