Skip to content

Commit 7c53c4c

Browse files
committed
Add auto-login option after verification
1 parent d4632cd commit 7c53c4c

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,20 @@ php artisan vendor:publish --provider="Jrean\UserVerification\UserVerificationSe
345345

346346
This will add `laravel-user-verification/en/user-verification.php` to your vendor folder. By creating new language folders, like `de` or `fr` and placing a `user-verification.php` with the translations inside, you can add translations for other languages. You can find out more about localization in the [Laravel documentation](https://laravel.com/docs/5.3/localization).
347347

348+
### Auto-login
349+
350+
If you wish to automaticaly log in the user after the verification process, update the package config file `user-verification.php` in the config directory and replace the following:
351+
352+
```PHP
353+
'auto-login' => false,
354+
```
355+
356+
by:
357+
358+
```PHP
359+
'auto-login' => true,
360+
```
361+
348362
### Customize
349363

350364
You can customize the package behaviour by overriding/overwriting the

src/Traits/VerifiesUsers.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getVerification(Request $request, $token)
3030
}
3131

3232
try {
33-
UserVerificationFacade::process($request->input('email'), $token, $this->userTable());
33+
$user = UserVerificationFacade::process($request->input('email'), $token, $this->userTable());
3434
} catch (UserNotFoundException $e) {
3535
return redirect($this->redirectIfVerificationFails());
3636
} catch (UserIsVerifiedException $e) {
@@ -39,6 +39,10 @@ public function getVerification(Request $request, $token)
3939
return redirect($this->redirectIfVerificationFails());
4040
}
4141

42+
if (config('user-verification.auto-login') === true) {
43+
auth()->loginUsingId($user->id);
44+
}
45+
4246
return redirect($this->redirectAfterVerification());
4347
}
4448

src/UserVerification.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,23 @@ protected function emailLaterVerificationLink(
250250
* @param string $email
251251
* @param string $token
252252
* @param string $userTable
253-
* @return void
253+
* @return stdClass
254254
*/
255255
public function process($email, $token, $userTable)
256256
{
257257
$user = $this->getUserByEmail($email, $userTable);
258258

259+
unset($user->{"password"});
260+
259261
// Check if the given user is already verified.
260262
// If he is, we stop here.
261263
$this->isVerified($user);
262264

263265
$this->verifyToken($user->verification_token, $token);
264266

265267
$this->wasVerified($user);
268+
269+
return $user;
266270
}
267271

268272
/**

src/config/user-verification.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@
1212
| Supported: "default", "markdown"
1313
|
1414
*/
15-
1615
'email' => [
1716
'type' => 'default',
1817
],
1918

19+
/*
20+
|--------------------------------------------------------------------------
21+
| Log the user in after verification
22+
|--------------------------------------------------------------------------
23+
|
24+
| This option defines if the user should be loged in after verification.
25+
| USE WITH CAUTION as it may introduce security issues in your app.
26+
|
27+
| Supported: (bool) "true", "false"
28+
|
29+
*/
30+
'auto-login' => false,
31+
2032
];

0 commit comments

Comments
 (0)