-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordChangeByEmail.php
More file actions
101 lines (94 loc) · 3.45 KB
/
PasswordChangeByEmail.php
File metadata and controls
101 lines (94 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
use WHMCS\Auth;
use WHMCS\Mail;
use Carbon\Carbon;
use Illuminate\Database\Capsule\Manager as Capsule;
function PasswordChangeByEmail_config() {
return [
'name' => 'PasswordChangeByEmail',
'description' => 'Allows users to reset their password using a verification code sent to their email.',
'author' => 'RezaKarimi',
'version' => '1.0.0',
'fields' => [
'time_limit' => [
'FriendlyName' => 'Time Limit for Code (minutes)',
'Type' => 'text',
'Size' => '5',
'Default' => '10',
'Description' => 'The time limit for the reset code validity in minutes.',
],
'max_requests' => [
'FriendlyName' => 'Max Requests Per Hour',
'Type' => 'text',
'Size' => '5',
'Default' => '5',
'Description' => 'The maximum number of reset code requests allowed per hour for a user.',
],
]
];
}
function PasswordChangeByEmail_activate() {
try {
Capsule::schema()->create('mod_password_change_by_email', function ($table) {
$table->increments('id');
$table->integer('client_id');
$table->string('password_reset_code');
$table->timestamp('password_reset_requested_at');
});
return [
'status' => 'success',
'description' => 'PasswordChangeByEmail module activated successfully.'
];
} catch (\Exception $e) {
return [
'status' => 'error',
'description' => 'Unable to create the required database table: ' . $e->getMessage()
];
}
}
function PasswordChangeByEmail_deactivate() {
try {
Capsule::schema()->dropIfExists('mod_password_change_by_email');
return [
'status' => 'success',
'description' => 'PasswordChangeByEmail module deactivated successfully.'
];
} catch (\Exception $e) {
return [
'status' => 'error',
'description' => 'Unable to drop the required database table: ' . $e->getMessage()
];
}
}
function PasswordChangeByEmail_output($vars) {
// Fetch reset requests for admin view
$resetRequests = Capsule::table('mod_password_change_by_email')
->join('tblclients', 'mod_password_change_by_email.client_id', '=', 'tblclients.id')
->select('tblclients.firstname', 'tblclients.lastname', 'tblclients.email', 'mod_password_change_by_email.password_reset_requested_at')
->get();
// Display in admin area
echo '<h2>Password Reset Requests</h2>';
echo '<table class="table table-bordered">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Request Time</th>
</tr>
</thead>
<tbody>';
foreach ($resetRequests as $request) {
echo '<tr>
<td>' . $request->firstname . '</td>
<td>' . $request->lastname . '</td>
<td>' . $request->email . '</td>
<td>' . $request->password_reset_requested_at . '</td>
</tr>';
}
echo '</tbody>
</table>';
}