Files
UNIT3D-Community-Edition/app/Http/Controllers/Auth/ForgotUsernameController.php
Laravel Shift 0e48e34c8a Adopt PSR-2 coding style
The Laravel framework adopts the PSR-2 coding style in version 5.1.
Laravel apps *should* adopt this coding style as well. Read the
[PSR-2 coding style guide][1] for more details and check out [PHPCS][2]
to use as a code formatting tool.

[1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
[2]: https://github.com/squizlabs/PHP_CodeSniffer
2018-01-18 01:04:19 +00:00

73 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use App\Notifications\UsernameReminder;
use \Toastr;
class ForgotUsernameController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
$validator = Validator::make(
$data,
['email' => 'required|email'],
['email.required' => 'Email is required', 'email.email' => 'Email is invalid']
);
return $validator;
}
public function showForgotUsernameForm()
{
return view('auth.username');
}
public function sendUserameReminder(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request,
$validator
);
}
$email = $request->get('email');
// get the user associated to this activation key
$user = User::where('email', $email)->first();
if (empty($user)) {
return redirect()->route('username.request')->with(Toastr::warning('We could not find this email in our system!', 'Error', ['options']));
}
//send username reminder notification
$user->notify(new UsernameReminder());
return redirect()->route('login')->with(Toastr::success('Your username has been sent to your email address!', 'Yay!', ['options']));
}
}