Skip to content

Commit a8a5cbc

Browse files
committed
First commit
0 parents  commit a8a5cbc

File tree

16 files changed

+803
-0
lines changed

16 files changed

+803
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Laravel Email Confirmation ##
2+
3+
This package is to add email confirmation to Laravel 5.4 project.
4+
5+
It should be used after `php artisan make:auth` command but can also be added to existing project.
6+
7+
### Features ###
8+
9+
- create a migration to add confirmation columns to users table
10+
- create routes for confirmation
11+
`confirmation/resend`
12+
`confirmation/{id}/{token}`
13+
- add an artisan command to override login and register views
14+
- send email notification with registration
15+
- add translations for notification (there are french and english ones)
16+
- block login for not confirmed user and launch an alert with resend link for notification
17+
- block auto login on password reset for not confirmed user
18+
19+
### Installation ###
20+
21+
Add package to your composer.json file :
22+
```
23+
composer require bestmomo/laravel-email-confirmation
24+
```
25+
26+
Add service provider to `config/app.php` :
27+
```
28+
Bestmomo\LaravelEmailConfirmation\ServiceProvider::class,
29+
```
30+
31+
Make a migration to add columns to users table :
32+
```
33+
php artisan migrate
34+
```
35+
36+
Change trait reference in `LoginController` :
37+
```
38+
use Bestmomo\LaravelEmailConfirmation\Traits\AuthenticatesUsers;
39+
```
40+
41+
Change trait reference in `RegisterController` :
42+
```
43+
use Bestmomo\LaravelEmailConfirmation\Traits\RegistersUsers;
44+
```
45+
46+
Change trait reference in `ResetPasswordController`:
47+
```
48+
use Bestmomo\LaravelEmailConfirmation\Traits\ResetsPasswords;
49+
```
50+
51+
### Publish ###
52+
53+
- If you have used the `php artisan make:auth` command
54+
55+
Override login and register views to get confirmation alerts :
56+
```
57+
php artisan confirmation:auth
58+
```
59+
60+
- If you have custom scaffold
61+
62+
You must add alerts in login and register views. Here are 2 examples with Bootstrap.
63+
64+
Login view :
65+
66+
```
67+
@if (session('confirmation-success'))
68+
<div class="alert alert-success">
69+
{{ session('confirmation-success') }}
70+
</div>
71+
@endif
72+
@if (session('confirmation-danger'))
73+
<div class="alert alert-danger">
74+
{!! session('confirmation-danger') !!}
75+
</div>
76+
@endif
77+
```
78+
79+
Register view :
80+
81+
```
82+
@if (session('confirmation-success'))
83+
<div class="alert alert-success">
84+
{{ session('confirmation-success') }}
85+
</div>
86+
@endif
87+
```
88+
89+
### Optional Publish ###
90+
91+
If you want to do some changes or add a language you can publish translations :
92+
```
93+
php artisan vendor:publish --tag=confirmation:translations
94+
```
95+
96+
If you want to do some changes to confirmation notification you can make a copy in App :
97+
```
98+
php artisan confirmation:notification
99+
```

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "bestmomo/laravel-email-confirmation",
3+
"description": "Email address confirmation with Laravel",
4+
"homepage": "http://github.com/laravel-email-confirmation",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Bestmomo",
9+
"email": "[email protected]",
10+
"homepage":"http://laravel.sillo.org"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.6.4",
15+
"illuminate/support": "~5.4"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"Bestmomo\\LaravelEmailConfirmation\\": "src/"
20+
}
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddConfirmation extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('users', function (Blueprint $table) {
17+
$table->boolean('confirmed')->default(false);
18+
$table->string('confirmation_code')->nullable();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('users', function (Blueprint $table) {
30+
$table->dropColumn('confirmed');
31+
$table->dropColumn('confirmation_code');
32+
});
33+
}
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'email-title' => 'Email verification',
5+
'email-intro'=> 'To validate your email click on the button below',
6+
'email-button' => 'Email verification',
7+
'message' => 'Thanks for signing up! Please check your email.',
8+
'success' => 'You have successfully verified your account! You can now login.',
9+
'again' => 'You must verify your email before you can access the site. ' .
10+
'<br>If you have not received the confirmation email check your spam folder.'.
11+
'<br>To get a new confirmation email please <a href="' . url('confirmation/resend') . '" class="alert-link">click here</a>.',
12+
'resend' => 'A confirmation message has been sent. Please check your email.'
13+
];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'email-title' => 'Vérification d\'email',
5+
'email-intro' => 'Pour valider votre email cliquez sur le bouton ci-dessous',
6+
'email-button' => 'Confirmation d\'email',
7+
'message' => 'Merci de vous être enregistré ! Regardez dans vos emails en réception.',
8+
'success' => 'Vous avez maintenant confirmé votre compte ! Vous pouvez vous connecter.',
9+
'again' => 'Vous devez valider votre email avant de pouvoir accéder à ce site. ' .
10+
'<br>Si vous n\'avez pas reçu l\'email de confirmation veuillez consulter votre dossier de spams.' .
11+
'<br>Pour recevoir à nouveau un email de confirmation <a href="' . url('confirmation/resend') . '" class="alert-link">cliquez ici</a>.',
12+
'resend' => 'Un email de confirmation vous a été envoyé. Regardez dans vos emails en réception.'
13+
];

routes/web.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// Email confirmation
4+
Route::get('confirmation/resend', 'Auth\RegisterController@resend');
5+
Route::get('confirmation/{id}/{token}', 'Auth\RegisterController@confirm');

src/Commands/AuthCommand.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Bestmomo\LaravelEmailConfirmation\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class AuthCommand extends Command
8+
{
9+
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'confirmation:auth';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Scaffold basic login and registration views with confirmation alerts';
23+
24+
/**
25+
* The views that need to be exported.
26+
*
27+
* @var array
28+
*/
29+
protected $views = [
30+
'auth/login.stub' => 'auth/login.blade.php',
31+
'auth/register.stub' => 'auth/register.blade.php',
32+
];
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return void
38+
*/
39+
public function fire()
40+
{
41+
$this->exportViews();
42+
43+
$this->info('Authentication scaffolding for confirmation generated successfully.');
44+
}
45+
46+
/**
47+
* Export the authentication views.
48+
*
49+
* @return void
50+
*/
51+
protected function exportViews()
52+
{
53+
foreach ($this->views as $key => $value) {
54+
copy(
55+
__DIR__.'/stubs/views/'.$key,
56+
base_path('resources/views/'.$value)
57+
);
58+
}
59+
}
60+
}

src/Commands/NotificationCommand.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace Bestmomo\LaravelEmailConfirmation\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class NotificationCommand extends GeneratorCommand
8+
{
9+
/**
10+
* The console command name.
11+
*
12+
* @var string
13+
*/
14+
protected $name = 'confirmation:notification';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Publish confirmation notification';
22+
23+
/**
24+
* The type of class being generated.
25+
*
26+
* @var string
27+
*/
28+
protected $type = 'Confirmation Notification';
29+
30+
/**
31+
* Get the stub file for the generator.
32+
*
33+
* @return string
34+
*/
35+
protected function getStub()
36+
{
37+
return __DIR__.'/stubs/Notifications/ConfirmEmail.stub';
38+
}
39+
40+
/**
41+
* Get the desired class name from the input.
42+
*
43+
* @return string
44+
*/
45+
protected function getNameInput()
46+
{
47+
return 'ConfirmEmail';
48+
}
49+
50+
/**
51+
* Get the default namespace for the class.
52+
*
53+
* @param string $rootNamespace
54+
* @return string
55+
*/
56+
protected function getDefaultNamespace($rootNamespace)
57+
{
58+
return $rootNamespace.'\Notifications';
59+
}
60+
61+
/**
62+
* Get the console command arguments.
63+
*
64+
* @return array
65+
*/
66+
protected function getArguments()
67+
{
68+
return [];
69+
}
70+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace DummyNamespace;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Notifications\Notification;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Notifications\Messages\MailMessage;
9+
10+
class ConfirmEmail extends Notification implements ShouldQueue
11+
{
12+
use Queueable;
13+
14+
/**
15+
* Get the notification's delivery channels.
16+
*
17+
* @return array
18+
*/
19+
public function via()
20+
{
21+
return ['mail'];
22+
}
23+
24+
/**
25+
* Get the mail representation of the notification.
26+
*
27+
* @param mixed $notifiable
28+
* @return \Illuminate\Notifications\Messages\MailMessage
29+
*/
30+
public function toMail($notifiable)
31+
{
32+
return (new MailMessage)
33+
->subject(__('confirmation::confirmation.email-title'))
34+
->line(__('confirmation::confirmation.email-title'))
35+
->line(__('confirmation::confirmation.email-intro'))
36+
->action(__('confirmation::confirmation.email-button'),
37+
url("confirmation/$notifiable->id/$notifiable->confirmation_code"));
38+
}
39+
}

0 commit comments

Comments
 (0)