From d47954aab3d53565c69bb273b4312b41fb411cd3 Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Wed, 2 Oct 2019 18:45:08 +0200 Subject: [PATCH 1/4] Rejestracja - potwierdzenie adresu email --- .../Controllers/RegistrationController.php | 39 ++++++++++++++++++- config/mail.php | 4 +- .../2014_10_12_000000_create_users_table.php | 2 + resources/views/emails/verify.blade.php | 17 ++++++++ routes/web.php | 5 ++- 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 resources/views/emails/verify.blade.php diff --git a/app/Http/Controllers/RegistrationController.php b/app/Http/Controllers/RegistrationController.php index 1446e00..f1ddd62 100644 --- a/app/Http/Controllers/RegistrationController.php +++ b/app/Http/Controllers/RegistrationController.php @@ -2,8 +2,10 @@ namespace App\Http\Controllers; +use Illuminate\Support\Facades\Input; use Illuminate\Http\Request; use App\User; +use Mail; use App\Rules\Pesel; /* 'phoneNumber' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:9' */ @@ -39,6 +41,9 @@ class RegistrationController extends Controller $request = request(); + + $confirmation_code = str_random(30); + $user = User::create([ 'password' => $request-> password, 'email' => $request-> email, @@ -48,13 +53,45 @@ class RegistrationController extends Controller 'phoneNumber' => $request-> phoneNumber, 'functionID' => 1, 'degreeID' => 1, - 'number' => 'ABC123' + 'number' => 'ABC123', + 'confirmation_code' => $confirmation_code ]); + Mail::send('emails.verify', compact('confirmation_code'), function($message) { + $message->to(Input::get('email'), Input::get('name'))->subject('Weryfikacja adresu e-mail'); + }); + + //Flash::message('Thanks for signing up! Please check your email.'); + auth()->login($user); return redirect()->to('/jednostka'); } + + public function confirm($confirmation_code) + { + if( ! $confirmation_code) + { + throw new InvalidConfirmationCodeException; + } + + $user = User::whereConfirmationCode($confirmation_code)->first(); + + if ( ! $user) + { + throw new InvalidConfirmationCodeException; + } + + $user->confirmed = 1; + $user->confirmation_code = null; + $user->email_verified_at = now(); + $user->save(); + + //Flash::message('You have successfully verified your account.'); + + return redirect()->to('/jednostka'); + } + } diff --git a/config/mail.php b/config/mail.php index f400645..6eb539c 100644 --- a/config/mail.php +++ b/config/mail.php @@ -29,7 +29,7 @@ return [ | */ - 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), + 'host' => env('MAIL_HOST', 'mailtrap.io'), /* |-------------------------------------------------------------------------- @@ -42,7 +42,7 @@ return [ | */ - 'port' => env('MAIL_PORT', 587), + 'port' => env('MAIL_PORT', 2525), /* |-------------------------------------------------------------------------- diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 7c5efa6..bd0ae30 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -29,6 +29,8 @@ class CreateUsersTable extends Migration $table->integer('deleted')->default(0); $table->integer('creatorID')->nullable()->default(null); $table->integer('changingID')->nullable()->default(null); + $table->boolean('confirmed')->default(0); + $table->string('confirmation_code')->nullable(); $table->timestamp('email_verified_at')->nullable(); $table->rememberToken(); $table->timestamps(); diff --git a/resources/views/emails/verify.blade.php b/resources/views/emails/verify.blade.php new file mode 100644 index 0000000..be96a1c --- /dev/null +++ b/resources/views/emails/verify.blade.php @@ -0,0 +1,17 @@ + + + + + + +

Weryfikacja adresu e-mail

+ +
+ Dziękujemy za utworzenie konta w serwisie eOSP. Proszę kliknąć w link poniżej by dokonać weryfikacji adresu e-mail {{ URL::to('register/verify/' . $confirmation_code) }}
+ + W razie problemów proszę wkleić powyższy link w polu adresowym przeglądarki internetowej. + +
+ + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index fb15870..0392299 100644 --- a/routes/web.php +++ b/routes/web.php @@ -54,7 +54,10 @@ Route::post('/strazacy', 'fireFightersController@store'); Route::get('/jednostka/getcounties/{id}','DataController@getCounties'); Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities'); - +Route::get('register/verify/{confirmationCode}', [ + 'as' => 'confirmation_path', + 'uses' => 'RegistrationController@confirm' +]); //Auth::routes(); // //Route::get('/home', 'HomeController@index')->name('home'); From 9ecf157aef5166db7ab867bf1c36a58b01be8b1d Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Wed, 2 Oct 2019 19:01:29 +0200 Subject: [PATCH 2/4] Rejestracja - weryfikacja adresu email --- routes/web.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/web.php b/routes/web.php index 2beecac..394ebea 100644 --- a/routes/web.php +++ b/routes/web.php @@ -54,6 +54,10 @@ Route::post('/jednostka', 'fireStationController@store'); Route::get('/jednostka/getcounties/{id}','DataController@getCounties'); Route::get('/jednostka/getcommunities/{id}','DataController@getCommunities'); +Route::get('register/verify/{confirmationCode}', [ + 'as' => 'confirmation_path', + 'uses' => 'RegistrationController@confirm' +]); //Auth::routes(); // //Route::get('/home', 'HomeController@index')->name('home'); From e16ae83d64f4ce106f4e51dc2f6b0185d139b9f6 Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Wed, 2 Oct 2019 19:42:56 +0200 Subject: [PATCH 3/4] potwierdzenie maila - fix zapisu kodu aktywacyjnego do bazy --- app/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/User.php b/app/User.php index 1ac71ef..9bf1995 100644 --- a/app/User.php +++ b/app/User.php @@ -18,7 +18,7 @@ class User extends Authenticatable * @var array */ protected $fillable = [ - 'name', 'surname', 'password', 'PESEL', 'phoneNumber', 'email', 'fireStationID', 'functionID', 'degreeID', 'number', 'statusID', 'deleted', 'creatorID', 'changingID', + 'name', 'surname', 'password', 'PESEL', 'phoneNumber', 'email', 'fireStationID', 'functionID', 'degreeID', 'number', 'statusID', 'deleted', 'creatorID', 'changingID', 'confirmation_code', ]; /** From 41ded8ef5deba53658a3aa89f9183a98a1999c65 Mon Sep 17 00:00:00 2001 From: Krzysztof Strzelecki Date: Thu, 3 Oct 2019 13:08:49 +0200 Subject: [PATCH 4/4] tworzenie jednostki - zapisywanie nazwy wybranej gminy/powiatu/woj. zamiast ID --- app/Http/Controllers/fireStationController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/fireStationController.php b/app/Http/Controllers/fireStationController.php index 4f9de4d..a97e451 100644 --- a/app/Http/Controllers/fireStationController.php +++ b/app/Http/Controllers/fireStationController.php @@ -51,12 +51,17 @@ class fireStationController extends Controller $request = request(); + + $voivodeship = DB::table('wojewodztwa')->select('name')->where('id', $request -> voivodeship)->first(); + $county = DB::table('powiaty')->select('name')->where('id', $request -> county)->first(); + $community = DB::table('gminy')->select('name')->where('id', $request -> community)->first(); + $jednostka = fireStation::create([ 'name' => $request -> unitName, 'number' => $request -> number, - 'voivodeship' => $request -> voivodeship, - 'county' => $request -> county, - 'community' => $request -> community, + 'voivodeship' => $voivodeship -> name, + 'county' => $county -> name, + 'community' => $community -> name, 'postOffice' => $request -> postOffice, 'zipCode' => $request -> zipCode, 'address' => $request -> address,