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
|
|
|
use JsonResponses; |
21
|
|
|
|
22
|
|
|
/* ----------------------------------------------------------------- |
23
|
|
|
| Properties |
24
|
|
|
| ----------------------------------------------------------------- |
25
|
|
|
*/ |
26
|
|
|
/** @var int */ |
27
|
|
|
protected $perPage = 30; |
28
|
|
|
|
29
|
|
|
/* ----------------------------------------------------------------- |
30
|
|
|
| Constructor |
31
|
|
|
| ----------------------------------------------------------------- |
32
|
|
|
*/ |
33
|
|
|
/** |
34
|
|
|
* PasswordResetsController constructor. |
35
|
|
|
*/ |
36
|
|
|
public function __construct() |
37
|
|
|
{ |
38
|
|
|
parent::__construct(); |
39
|
|
|
|
40
|
|
|
$this->setCurrentPage('auth-password-resets'); |
41
|
|
|
$this->addBreadcrumbRoute(trans('auth::password-resets.titles.password-resets'), 'admin::auth.password-resets.index'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/* ----------------------------------------------------------------- |
45
|
|
|
| Main Methods |
46
|
|
|
| ----------------------------------------------------------------- |
47
|
|
|
*/ |
48
|
|
|
public function index() |
49
|
|
|
{ |
50
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_LIST); |
51
|
|
|
|
52
|
|
|
$resets = PasswordReset::with(['user']) |
53
|
|
|
->orderBy('created_at', 'desc') |
54
|
|
|
->paginate($this->perPage); |
55
|
|
|
|
56
|
|
|
$this->setTitle($title = trans('auth::password-resets.titles.password-resets-list')); |
57
|
|
|
$this->addBreadcrumb($title); |
58
|
|
|
|
59
|
|
|
return $this->view('admin.password-resets.list', compact('resets')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function delete() |
63
|
|
|
{ |
64
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_DELETE); |
65
|
|
|
|
66
|
|
|
PasswordReset::deleteAll(); |
67
|
|
|
|
68
|
|
|
return $this->jsonResponseSuccess( |
69
|
|
|
$this->transNotification('deleted') |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function clear() |
74
|
|
|
{ |
75
|
|
|
$this->authorize(PasswordResetsPolicy::PERMISSION_DELETE); |
76
|
|
|
|
77
|
|
|
PasswordReset::deleteExpired(); |
78
|
|
|
|
79
|
|
|
return $this->jsonResponseSuccess( |
80
|
|
|
$this->transNotification('cleared') |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/* ----------------------------------------------------------------- |
85
|
|
|
| Other Methods |
86
|
|
|
| ----------------------------------------------------------------- |
87
|
|
|
*/ |
88
|
|
|
/** |
89
|
|
|
* Notify with translation. |
90
|
|
|
* |
91
|
|
|
* @param string $action |
92
|
|
|
* @param array $replace |
93
|
|
|
* @param array $context |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
98
|
|
|
{ |
99
|
|
|
$title = trans("auth::password-resets.messages.{$action}.title"); |
100
|
|
|
$message = trans("auth::password-resets.messages.{$action}.message", $replace); |
101
|
|
|
|
102
|
|
|
Log::info($message, $context); |
103
|
|
|
$this->notifySuccess($message, $title); |
104
|
|
|
|
105
|
|
|
return $message; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|