commit 9635619e94fe7a49c7b17752ee4980dbb08ba654
Author: rizir01 <themurrayms@seznam.cz>
Date:   Sun May 17 13:31:34 2020 +0200

    Issue #8001 @3h
    
    Funkci posilani registracniho emailu registrovanemu uzivateli. Po registraci se uzivateli vytvori unikatni hash, ktery se mu preda v emailu jako registracni kod. Po vstupu na stranky verify/{reg.klic}, bude klic prijat a ucet aktivovan, ci bude zamitnut na zaklade pozdni registace uctu, ci spatne zadaneho klice (chybne zapsany klic). IMPORTANT!! - byla upravena struktrua tabulky Users, je tedy nutne znovu zmigrovat celou databasi. Migrace by mela byt upravena tak, aby se prislusny sloupec vytvoril.

diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 4c71b92..ba06e0a 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -66,12 +66,17 @@ class RegisterController extends Controller
      */
     protected function create(array $data)
     {
-        Mail::to($data['email'])->send(new RegisterMail());
+        $stringH = Hash::make($data['email'] . $data['name']);
+        $vowels = array("/", "\\");
+        $stringHModified = str_replace($vowels, "", $stringH);
+
+        Mail::to($data['email'])->send(new RegisterMail("http://localhost/verify/". $stringHModified));
 
         return User::create([
             'name' => $data['name'],
             'email' => $data['email'],
             'password' => Hash::make($data['password']),
+            'register_hash' => $stringHModified,
         ]);
     }
 }
diff --git a/app/Http/Controllers/VerifyRegisterController.php b/app/Http/Controllers/VerifyRegisterController.php
new file mode 100644
index 0000000..a061fb7
--- /dev/null
+++ b/app/Http/Controllers/VerifyRegisterController.php
@@ -0,0 +1,58 @@
+<?php
+
+
+namespace App\Http\Controllers;
+
+
+use App\User;
+use Illuminate\Contracts\View\Factory;
+use Illuminate\View\View;
+
+class VerifyRegisterController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+    /**
+     * Verify registration link with time and user database,
+     * if the user exists. If everything checks out, the user's
+     * account will be activated.
+     *
+     * @param $id string hash of created user
+     * @return Factory|View
+     */
+    public function verifyUser($id)
+    {
+        $userV = User::where('register_hash', $id)->get();
+        $text = "";
+        if(!$userV->isEmpty())
+        {
+            $created = $userV[0]->created_at;
+            $now = date('Y-m-d h:i:s');
+            $interval = $created->diff($now);
+
+            if($interval->d >= 2)
+            {
+                $text = "Registration link expired!\n Need to create new account";
+                $userV[0]->delete();
+            }
+            else if(isset($userV[0]->email_verified_at))
+            {
+                $text = "Registration link already activated!";
+            }
+            else
+            {
+                $userV[0]->email_verified_at = date('Y-m-d h:i:s');
+                $userV[0]->save();
+                $text = "Registration of the user " . $userV[0]->name . " has been successful.";
+            }
+        }
+        else
+        {
+            $text = "The link is not valid!";
+        }
+        return view('verify.index', ['text' => $text]);
+    }
+}
diff --git a/app/Mail/RegisterMail.php b/app/Mail/RegisterMail.php
index 3537271..cca8861 100644
--- a/app/Mail/RegisterMail.php
+++ b/app/Mail/RegisterMail.php
@@ -11,14 +11,16 @@ class RegisterMail extends Mailable
 {
     use Queueable, SerializesModels;
 
+    public $stringHash;
+
     /**
      * Create a new message instance.
      *
      * @return void
      */
-    public function __construct()
+    public function __construct($stringH)
     {
-        //
+        $this->stringHash = $stringH;
     }
 
     /**
diff --git a/app/User.php b/app/User.php
index da5cf4a..469eec2 100644
--- a/app/User.php
+++ b/app/User.php
@@ -20,7 +20,7 @@ class User extends Authenticatable
      * @var array
      */
     protected $fillable = [
-         'name', 'email', 'password'
+         'name', 'email', 'password', 'register_hash'
     ];
 
     /**
diff --git a/database/migrations/2020_04_06_000000_CreateUsersTable.php b/database/migrations/2020_04_06_000000_CreateUsersTable.php
index 89604d6..a7bdd89 100644
--- a/database/migrations/2020_04_06_000000_CreateUsersTable.php
+++ b/database/migrations/2020_04_06_000000_CreateUsersTable.php
@@ -23,6 +23,7 @@ class CreateUsersTable extends Migration
             $table->string('password');
             $table->rememberToken();
             $table->timestamps();
+            $table->string('register_hash');
         });
     }
 
diff --git a/resources/sass/_custom.scss b/resources/sass/_custom.scss
index 0b6d833..91ed734 100644
--- a/resources/sass/_custom.scss
+++ b/resources/sass/_custom.scss
@@ -725,6 +725,17 @@ body {
             font-size: 1.9rem;
         }
     }
+
+    //VERIFY - main text
+    .ver-text{
+
+        margin-top: 20pt    ;
+
+        h2{
+            text-align: center;
+            color:$theme-color-two;
+        }
+    }
 }
 
 .arrow {
diff --git a/resources/views/email/register.blade.php b/resources/views/email/register.blade.php
index f2d224f..9b3604b 100644
--- a/resources/views/email/register.blade.php
+++ b/resources/views/email/register.blade.php
@@ -4,7 +4,7 @@
 Hello and welcome to our page. This email was sent to you due to your registration on our page.
 To activate your account, please click the link below.<br>
 
-@component('mail::button', ['url' => ''])
+@component('mail::button', ['url' => $stringHash])
 Activate
 @endcomponent
 
diff --git a/resources/views/verify/index.blade.php b/resources/views/verify/index.blade.php
new file mode 100644
index 0000000..d2dfefd
--- /dev/null
+++ b/resources/views/verify/index.blade.php
@@ -0,0 +1,9 @@
+@extends('layouts.app')
+
+@section('title', 'Favorite artefacts')
+
+@section('content')
+    <div class="container ver-text">
+        <h2>{{$text}}</h2>
+    </div>
+@endsection
diff --git a/routes/web.php b/routes/web.php
index 9853bcd..f3b1e0b 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -15,6 +15,7 @@ use Illuminate\Support\Facades\Route;
 
 Route::get('/', 'PagesController@index');
 
+Route::get('/verify/{id}', 'VerifyRegisterController@verifyUser');
 Route::get('/artefact', 'ArtefactController@default');
 Route::get('/artefact/{id}', 'ArtefactController@view');
 Route::post('/artefact/like/{id}', 'ArtefactController@like');
