1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Auth; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
use App\Jobs\SendPasswordForgottenEmail; |
7
|
|
|
use App\Models\Settings; |
8
|
|
|
use App\Models\User; |
9
|
|
|
use DariusIII\Token\Facades\Token; |
10
|
|
|
use Illuminate\Foundation\Auth\SendsPasswordResetEmails; |
11
|
|
|
use Illuminate\Http\Request; |
12
|
|
|
|
13
|
|
|
class ForgotPasswordController extends Controller |
14
|
|
|
{ |
15
|
|
|
/* |
16
|
|
|
|-------------------------------------------------------------------------- |
17
|
|
|
| Password Reset Controller |
18
|
|
|
|-------------------------------------------------------------------------- |
19
|
|
|
| |
20
|
|
|
| This controller is responsible for handling password reset emails and |
21
|
|
|
| includes a trait which assists in sending these notifications from |
22
|
|
|
| your application to your users. Feel free to explore this trait. |
23
|
|
|
| |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use SendsPasswordResetEmails; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new controller instance. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function __construct() |
34
|
|
|
{ |
35
|
|
|
$this->middleware('guest'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param \Illuminate\Http\Request $request |
40
|
|
|
* |
41
|
|
|
* @throws \Exception |
42
|
|
|
*/ |
43
|
|
|
public function showLinkRequestForm(Request $request) |
44
|
|
|
{ |
45
|
|
|
$sent = ''; |
46
|
|
|
$email = request()->input('email') ?? ''; |
47
|
|
|
$rssToken = request()->input('apikey') ?? ''; |
48
|
|
|
if (empty($email) && empty($rssToken)) { |
49
|
|
|
app('smarty.view')->assign('error', 'Missing parameter(email and/or apikey to send password reset'); |
50
|
|
|
} else { |
51
|
|
|
if (config('captcha.enabled') === true && (! empty(config('captcha.secret')) && ! empty(config('captcha.sitekey')))) { |
52
|
|
|
$this->validate($request, [ |
53
|
|
|
'g-recaptcha-response' => 'required|captcha', |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
// |
57
|
|
|
// Check users exists and send an email |
58
|
|
|
// |
59
|
|
|
$ret = ! empty($rssToken) ? User::getByRssToken($rssToken) : User::getByEmail($email); |
60
|
|
|
if ($ret === null) { |
61
|
|
|
app('smarty.view')->assign('error', 'The email or apikey are not recognised.'); |
62
|
|
|
$sent = true; |
63
|
|
|
} else { |
64
|
|
|
// |
65
|
|
|
// Generate a forgottenpassword guid, store it in the user table |
66
|
|
|
// |
67
|
|
|
$guid = /Token::random(32); |
|
|
|
|
68
|
|
|
User::updatePassResetGuid($ret['id'], $guid); |
69
|
|
|
// |
70
|
|
|
// Send the email |
71
|
|
|
// |
72
|
|
|
$resetLink = url('/').'/resetpassword?guid='.$guid; |
73
|
|
|
SendPasswordForgottenEmail::dispatch($ret, $resetLink); |
74
|
|
|
$sent = true; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$theme = Settings::settingValue('site.main.style'); |
79
|
|
|
|
80
|
|
|
$title = 'Forgotten Password'; |
81
|
|
|
$meta_title = 'Forgotten Password'; |
82
|
|
|
$meta_keywords = 'forgotten,password,signup,registration'; |
83
|
|
|
$meta_description = 'Forgotten Password'; |
84
|
|
|
|
85
|
|
|
$content = app('smarty.view')->fetch($theme.'/forgottenpassword.tpl'); |
86
|
|
|
|
87
|
|
|
app('smarty.view')->assign( |
88
|
|
|
[ |
89
|
|
|
'content' => $content, |
90
|
|
|
'title' => $title, |
91
|
|
|
'meta_title' => $meta_title, |
92
|
|
|
'meta_keywords' => $meta_keywords, |
93
|
|
|
'meta_description' => $meta_description, |
94
|
|
|
'email' => $email, |
95
|
|
|
'apikey' => $rssToken, |
96
|
|
|
'sent' => $sent, |
97
|
|
|
] |
98
|
|
|
); |
99
|
|
|
app('smarty.view')->display($theme.'/basepage.tpl'); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|