Files
UNIT3D-Community-Edition/app/Http/Controllers/Auth/ForgotUsernameController.php
HDVinnie 321847e067 Apply fixes from StyleCI
[ci skip] [skip ci]
2021-05-16 02:41:53 +00:00

71 lines
2.0 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Notifications\UsernameReminder;
use Illuminate\Http\Request;
/**
* @see \Tests\Feature\Http\Controllers\Auth\ForgotUsernameControllerTest
*/
class ForgotUsernameController extends Controller
{
/**
* Forgot Username Form.
*/
public function showForgotUsernameForm(): \Illuminate\Contracts\View\Factory | \Illuminate\View\View
{
return \view('auth.username');
}
/**
* Send Username Reminder.
*
*
* @return \Illuminate\Http\RedirectResponse
*/
public function sendUsernameReminder(Request $request)
{
$email = $request->get('email');
if (\config('captcha.enabled') == false) {
$v = \validator($request->all(), [
'email' => 'required',
]);
} else {
$v = \validator($request->all(), [
'email' => 'required',
'captcha' => 'hiddencaptcha',
]);
}
if ($v->fails()) {
return \redirect()->route('username.request')
->withErrors($v->errors());
}
$user = User::where('email', '=', $email)->first();
if (empty($user)) {
return \redirect()->route('username.request')
->withErrors(\trans('email.no-email-found'));
}
//send username reminder notification
$user->notify(new UsernameReminder());
return \redirect()->route('login')
->withSuccess(\trans('email.username-sent'));
}
}