1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Controllers\Admin; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelApiHelper\Traits\JsonResponses; |
4
|
|
|
use Arcanesoft\Auth\Models\PasswordReset; |
5
|
|
|
use Arcanesoft\Auth\Policies\PasswordResetsPolicy; |
6
|
|
|
use Illuminate\Support\Facades\Log; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class PasswordResetsController |
10
|
|
|
* |
11
|
|
|
* @package Arcanesoft\Auth\Http\Controllers\Admin |
12
|
|
|
* @author ARCANEDEV <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class PasswordResetsController extends Controller |
15
|
|
|
{ |
16
|
|
|
/* ----------------------------------------------------------------- |
17
|
|
|
| Traits |
18
|
|
|
| ----------------------------------------------------------------- |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use JsonResponses; |
22
|
|
|
|
23
|
|
|
/* ----------------------------------------------------------------- |
24
|
|
|
| Properties |
25
|
|
|
| ----------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** @var int */ |
29
|
|
|
protected $perPage = 30; |
30
|
|
|
|
31
|
|
|
/* ----------------------------------------------------------------- |
32
|
|
|
| Constructor |
33
|
|
|
| ----------------------------------------------------------------- |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* PasswordResetsController constructor. |
38
|
|
|
*/ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
|
43
|
|
|
$this->setCurrentPage('auth-password-resets'); |
44
|
|
|
$this->addBreadcrumbRoute(trans('auth::password-resets.titles.password-resets'), 'admin::auth.password-resets.index'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/* ----------------------------------------------------------------- |
48
|
|
|
| Main Methods |
49
|
|
|
| ----------------------------------------------------------------- |
50
|
|
|
*/ |
51
|
|
|
|
52
|
|
|
public function index() |
53
|
|
|
{ |
54
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_LIST); |
55
|
|
|
|
56
|
|
|
$resets = PasswordReset::with(['user']) |
57
|
|
|
->orderBy('created_at', 'desc') |
58
|
|
|
->paginate($this->perPage); |
59
|
|
|
|
60
|
|
|
$this->setTitle($title = trans('auth::password-resets.titles.password-resets-list')); |
61
|
|
|
$this->addBreadcrumb($title); |
62
|
|
|
|
63
|
|
|
return $this->view('admin.password-resets.index', compact('resets')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function delete() |
67
|
|
|
{ |
68
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_DELETE); |
69
|
|
|
|
70
|
|
|
PasswordReset::deleteAll(); |
71
|
|
|
|
72
|
|
|
return $this->jsonResponseSuccess([ |
73
|
|
|
'message' => $this->transNotification('deleted'), |
74
|
|
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function clear() |
78
|
|
|
{ |
79
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_DELETE); |
80
|
|
|
|
81
|
|
|
PasswordReset::deleteExpired(); |
82
|
|
|
|
83
|
|
|
return $this->jsonResponseSuccess([ |
84
|
|
|
'message' => $this->transNotification('cleared'), |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/* ----------------------------------------------------------------- |
89
|
|
|
| Other Methods |
90
|
|
|
| ----------------------------------------------------------------- |
91
|
|
|
*/ |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Notify with translation. |
95
|
|
|
* |
96
|
|
|
* @param string $action |
97
|
|
|
* @param array $replace |
98
|
|
|
* @param array $context |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
103
|
|
|
{ |
104
|
|
|
$title = trans("auth::password-resets.messages.{$action}.title"); |
105
|
|
|
$message = trans("auth::password-resets.messages.{$action}.message", $replace); |
106
|
|
|
|
107
|
|
|
Log::info($message, $context); |
108
|
|
|
$this->notifySuccess($message, $title); |
109
|
|
|
|
110
|
|
|
return $message; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|