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
|
}
|