Revize 9635619e
Přidáno uživatelem Jiří Noháč před téměř 5 roky(ů)
app/Http/Controllers/Auth/RegisterController.php | ||
---|---|---|
66 | 66 |
*/ |
67 | 67 |
protected function create(array $data) |
68 | 68 |
{ |
69 |
Mail::to($data['email'])->send(new RegisterMail()); |
|
69 |
$stringH = Hash::make($data['email'] . $data['name']); |
|
70 |
$vowels = array("/", "\\"); |
|
71 |
$stringHModified = str_replace($vowels, "", $stringH); |
|
72 |
|
|
73 |
Mail::to($data['email'])->send(new RegisterMail("http://localhost/verify/". $stringHModified)); |
|
70 | 74 |
|
71 | 75 |
return User::create([ |
72 | 76 |
'name' => $data['name'], |
73 | 77 |
'email' => $data['email'], |
74 | 78 |
'password' => Hash::make($data['password']), |
79 |
'register_hash' => $stringHModified, |
|
75 | 80 |
]); |
76 | 81 |
} |
77 | 82 |
} |
app/Http/Controllers/VerifyRegisterController.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
|
|
4 |
namespace App\Http\Controllers; |
|
5 |
|
|
6 |
|
|
7 |
use App\User; |
|
8 |
use Illuminate\Contracts\View\Factory; |
|
9 |
use Illuminate\View\View; |
|
10 |
|
|
11 |
class VerifyRegisterController extends Controller |
|
12 |
{ |
|
13 |
public function __construct() |
|
14 |
{ |
|
15 |
$this->middleware('auth'); |
|
16 |
} |
|
17 |
|
|
18 |
/** |
|
19 |
* Verify registration link with time and user database, |
|
20 |
* if the user exists. If everything checks out, the user's |
|
21 |
* account will be activated. |
|
22 |
* |
|
23 |
* @param $id string hash of created user |
|
24 |
* @return Factory|View |
|
25 |
*/ |
|
26 |
public function verifyUser($id) |
|
27 |
{ |
|
28 |
$userV = User::where('register_hash', $id)->get(); |
|
29 |
$text = ""; |
|
30 |
if(!$userV->isEmpty()) |
|
31 |
{ |
|
32 |
$created = $userV[0]->created_at; |
|
33 |
$now = date('Y-m-d h:i:s'); |
|
34 |
$interval = $created->diff($now); |
|
35 |
|
|
36 |
if($interval->d >= 2) |
|
37 |
{ |
|
38 |
$text = "Registration link expired!\n Need to create new account"; |
|
39 |
$userV[0]->delete(); |
|
40 |
} |
|
41 |
else if(isset($userV[0]->email_verified_at)) |
|
42 |
{ |
|
43 |
$text = "Registration link already activated!"; |
|
44 |
} |
|
45 |
else |
|
46 |
{ |
|
47 |
$userV[0]->email_verified_at = date('Y-m-d h:i:s'); |
|
48 |
$userV[0]->save(); |
|
49 |
$text = "Registration of the user " . $userV[0]->name . " has been successful."; |
|
50 |
} |
|
51 |
} |
|
52 |
else |
|
53 |
{ |
|
54 |
$text = "The link is not valid!"; |
|
55 |
} |
|
56 |
return view('verify.index', ['text' => $text]); |
|
57 |
} |
|
58 |
} |
app/Mail/RegisterMail.php | ||
---|---|---|
11 | 11 |
{ |
12 | 12 |
use Queueable, SerializesModels; |
13 | 13 |
|
14 |
public $stringHash; |
|
15 |
|
|
14 | 16 |
/** |
15 | 17 |
* Create a new message instance. |
16 | 18 |
* |
17 | 19 |
* @return void |
18 | 20 |
*/ |
19 |
public function __construct() |
|
21 |
public function __construct($stringH)
|
|
20 | 22 |
{ |
21 |
//
|
|
23 |
$this->stringHash = $stringH;
|
|
22 | 24 |
} |
23 | 25 |
|
24 | 26 |
/** |
app/User.php | ||
---|---|---|
20 | 20 |
* @var array |
21 | 21 |
*/ |
22 | 22 |
protected $fillable = [ |
23 |
'name', 'email', 'password' |
|
23 |
'name', 'email', 'password', 'register_hash'
|
|
24 | 24 |
]; |
25 | 25 |
|
26 | 26 |
/** |
database/migrations/2020_04_06_000000_CreateUsersTable.php | ||
---|---|---|
23 | 23 |
$table->string('password'); |
24 | 24 |
$table->rememberToken(); |
25 | 25 |
$table->timestamps(); |
26 |
$table->string('register_hash'); |
|
26 | 27 |
}); |
27 | 28 |
} |
28 | 29 |
|
resources/sass/_custom.scss | ||
---|---|---|
725 | 725 |
font-size: 1.9rem; |
726 | 726 |
} |
727 | 727 |
} |
728 |
|
|
729 |
//VERIFY - main text |
|
730 |
.ver-text{ |
|
731 |
|
|
732 |
margin-top: 20pt ; |
|
733 |
|
|
734 |
h2{ |
|
735 |
text-align: center; |
|
736 |
color:$theme-color-two; |
|
737 |
} |
|
738 |
} |
|
728 | 739 |
} |
729 | 740 |
|
730 | 741 |
.arrow { |
resources/views/email/register.blade.php | ||
---|---|---|
4 | 4 |
Hello and welcome to our page. This email was sent to you due to your registration on our page. |
5 | 5 |
To activate your account, please click the link below.<br> |
6 | 6 |
|
7 |
@component('mail::button', ['url' => ''])
|
|
7 |
@component('mail::button', ['url' => $stringHash])
|
|
8 | 8 |
Activate |
9 | 9 |
@endcomponent |
10 | 10 |
|
resources/views/verify/index.blade.php | ||
---|---|---|
1 |
@extends('layouts.app') |
|
2 |
|
|
3 |
@section('title', 'Favorite artefacts') |
|
4 |
|
|
5 |
@section('content') |
|
6 |
<div class="container ver-text"> |
|
7 |
<h2>{{$text}}</h2> |
|
8 |
</div> |
|
9 |
@endsection |
routes/web.php | ||
---|---|---|
15 | 15 |
|
16 | 16 |
Route::get('/', 'PagesController@index'); |
17 | 17 |
|
18 |
Route::get('/verify/{id}', 'VerifyRegisterController@verifyUser'); |
|
18 | 19 |
Route::get('/artefact', 'ArtefactController@default'); |
19 | 20 |
Route::get('/artefact/{id}', 'ArtefactController@view'); |
20 | 21 |
Route::post('/artefact/like/{id}', 'ArtefactController@like'); |
Také k dispozici: Unified diff
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.