1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
|
8
|
|
|
class RestoreUserController extends ProfilesController |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Create a new controller instance. |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
$this->middleware('web'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* User Account Restore. |
22
|
|
|
* |
23
|
|
|
* @param string $token |
24
|
|
|
* |
25
|
|
|
* @return \Illuminate\Http\Response |
26
|
|
|
*/ |
27
|
|
|
public function userReActivate($token) |
28
|
|
|
{ |
29
|
|
|
$userKeys = new ProfilesController(); |
30
|
|
|
$sepKey = $userKeys->getSeperationKey(); |
31
|
|
|
$userIdKey = $userKeys->getIdMultiKey(); |
32
|
|
|
$restoreKey = config('settings.restoreKey'); |
33
|
|
|
$encrypter = config('settings.restoreUserEncType'); |
34
|
|
|
$level5 = base64_decode($token); |
35
|
|
|
$level4 = openssl_decrypt($level5, $encrypter, $restoreKey); |
36
|
|
|
$level3 = base64_decode($level4); |
37
|
|
|
$level2 = urldecode($level3); |
38
|
|
|
$level1[] = explode($sepKey, $level2); |
|
|
|
|
39
|
|
|
$userId = $level1[0][1] / $userIdKey; |
40
|
|
|
$user = SoftDeletesController::getDeletedUser($userId); |
41
|
|
|
|
42
|
|
|
if (!is_object($user)) { |
43
|
|
|
abort(500); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$deletedDate = $user->deleted_at; |
|
|
|
|
47
|
|
|
$currentDate = Carbon::now(); |
48
|
|
|
$daysDeleted = $currentDate->diffInDays($deletedDate); |
49
|
|
|
$cutoffDays = config('settings.restoreUserCutoff'); |
50
|
|
|
|
51
|
|
|
if ($daysDeleted >= $cutoffDays) { |
52
|
|
|
return redirect('/login')->with('error', trans('profile.errorRestoreUserTime')); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$user->restore(); |
56
|
|
|
|
57
|
|
|
return redirect('/login')->with('success', trans('profile.successUserRestore', ['username' => $user->name])); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|