(Feature) Add Forgot Username System

- Added Forgot Username option so one can recover there username via
email.
- Cleaned Up blades.
- Updated The CSS.
This commit is contained in:
HDVinnie
2018-01-17 18:30:47 -05:00
parent f503e279ee
commit c845fcce18
10 changed files with 243 additions and 27 deletions
@@ -0,0 +1,69 @@
<?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']));
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class UsernameReminder extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* UsernameReminderEmail constructor.
* @param $token
*/
public function __construct()
{
// nothing special to do
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Your '.config('app.name').' Username')
->greeting('Hello, '.$notifiable->username)
->line('You recently sent us a request for your username on our app. Your username is '.$notifiable->username)
->action('Login as '.$notifiable->username, route('login'))
->line('Thank you for using '. config('app.name'));
}
}
File diff suppressed because one or more lines are too long
+1
View File
@@ -16,4 +16,5 @@ return [
'lost-password' => 'Forgot Your Password?',
'recover-my-password' => 'Recover My Password',
'remember-me' => 'Remember Me',
'lost-username' => 'Forgot Your Username?'
];
+4 -5
View File
@@ -15,7 +15,7 @@
<link rel="shortcut icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="stylesheet" href="{{ url('css/vendor/toastr.min.css?v=01') }}" />
<link rel="stylesheet" href="{{ url('css/main/login.css?v=01') }}">
<link rel="stylesheet" href="{{ url('css/main/login.css?v=02') }}">
</head>
<body>
@@ -59,8 +59,7 @@
<label for="username" class="col-md-4 control-label">{{ trans('auth.username') }}</label>
<div class="col-md-6">
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required>
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus>
@if ($errors->has('username'))
<br>
<span class="help-block text-red">
@@ -75,7 +74,6 @@
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<br>
<span class="help-block text-red">
@@ -99,7 +97,8 @@
<!-- Remind Passowrd -->
<div id="formFooter">
<a class="underlineHover" href="{{ route('password.request') }}">{{ trans('auth.lost-password') }}</a>
<a href="{{ route('password.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-password') }} </h2></a>
<a href="{{ route('username.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-username') }} </h2></a>
</div>
</div>
</div>
+10 -5
View File
@@ -2,7 +2,7 @@
<html >
<head>
<meta charset="UTF-8">
<title>{{ trans('auth.login') }} - {{ Config::get('other.title') }}</title>
<title>{{ trans('auth.lost-password') }} - {{ Config::get('other.title') }}</title>
<!-- Meta -->
@section('meta')
<meta name="description" content="Login now on {{ Config::get('other.title') }}. Not yet member ? Signup in less than 30s.">
@@ -17,7 +17,7 @@
<link rel="shortcut icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="stylesheet" href="{{ url('css/vendor/toastr.min.css?v=01') }}" />
<link rel="stylesheet" href="{{ url('css/main/login.css?v=01') }}">
<link rel="stylesheet" href="{{ url('css/main/login.css?v=02') }}">
</head>
<body>
@@ -54,7 +54,6 @@
<!-- Tabs Titles -->
<a href="{{ route('login') }}"><h2 class="inactive underlineHover">{{ trans('auth.login') }}</h2></a>
<a href="{{ route('register') }}"><h2 class="inactive underlineHover">{{ trans('auth.signup') }}</h2></a>
<h2 class="active">{{ trans('auth.lost-password') }} </h2>
<!-- Icon -->
<div class="fadeIn first">
@@ -64,13 +63,19 @@
<!-- SignUp Form -->
<form class="form-horizontal" role="form" method="POST" action="{{ route('password.email') }}">
{{ csrf_field() }}
<input type="text" id="email" class="fadeIn third" name="email" placeholder="email">
<input type="email" id="email" class="fadeIn third" name="email" placeholder="email" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<button type="submit" class="fadeIn fourth">{{ trans('common.submit') }}</button>
</form>
<!-- Remind Passowrd -->
<div id="formFooter">
<a href="{{ route('password.request') }}"><h2 class="active">{{ trans('auth.lost-password') }} </h2></a>
<a href="{{ route('username.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-username') }} </h2></a>
</div>
</div>
@@ -17,7 +17,7 @@
<link rel="shortcut icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="stylesheet" href="{{ url('css/vendor/toastr.min.css?v=01') }}" />
<link rel="stylesheet" href="{{ url('css/main/login.css?v=01') }}">
<link rel="stylesheet" href="{{ url('css/main/login.css?v=02') }}">
</head>
<body>
@@ -54,7 +54,6 @@
<!-- Tabs Titles -->
<a href="{{ route('login') }}"><h2 class="inactive underlineHover">{{ trans('auth.login') }} </h2></a>
<a href="{{ route('register') }}"><h2 class="inactive underlineHover">{{ trans('auth.login') }} </h2></a>
<h2 class="active">{{ trans('auth.lost-password') }} </h2>
<!-- Icon -->
<div class="fadeIn first">
<img src="{{ url('/img/icon.svg') }}" id="icon" alt="User Icon" />
@@ -66,13 +65,13 @@
<input type="hidden" name="token" value="{{ $token }}">
<div class="row">
<div class="form-group">
<input type="text" id="email" class="fadeIn third" name="email" placeholder="email">
<input type="email" id="email" class="fadeIn third" name="email" placeholder="email" required autofocus>
</div>
<div class="form-group">
<input type="password" id="password" name="password" class="form-control" placeholder="{{ trans('common.password') }}">
<input type="password" id="password" name="password" class="form-control" placeholder="{{ trans('common.password') }}" required>
</div>
<div class="form-group">
<input type="password" id="password-confirm" name="password_confirmation" class="form-control" placeholder="{{ trans('common.password') }} confirmation">
<input type="password" id="password-confirm" name="password_confirmation" class="form-control" placeholder="{{ trans('common.password') }} confirmation" required>
</div>
<div class="col s6">
<button type="submit" class="btn waves-effect waves-light blue right">{{ trans('common.submit') }}</button>
@@ -80,7 +79,8 @@
</form>
<div id="formFooter">
<a href="{{ route('password.request') }}"><h2 class="active">{{ trans('auth.lost-password') }} </h2></a>
<a href="{{ route('username.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-username') }} </h2></a>
</div>
</div>
+7 -6
View File
@@ -2,7 +2,7 @@
<html >
<head>
<meta charset="UTF-8">
<title>{{ trans('auth.login') }} - {{ Config::get('other.title') }}</title>
<title>{{ trans('auth.signup') }} - {{ Config::get('other.title') }}</title>
<!-- Meta -->
<meta name="description" content="Login now on {{ Config::get('other.title') }}. Not yet member ? Signup in less than 30s.">
<meta property="og:title" content="{{ Config::get('other.title') }}">
@@ -15,7 +15,7 @@
<link rel="shortcut icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="stylesheet" href="{{ url('css/vendor/toastr.min.css?v=01') }}" />
<link rel="stylesheet" href="{{ url('css/main/login.css?v=01') }}">
<link rel="stylesheet" href="{{ url('css/main/login.css?v=02') }}">
</head>
<body>
@@ -60,15 +60,16 @@
<!-- SignUp Form -->
{{ Form::open(array('route' => array('register', 'code' => $code))) }}
<input type="text" id="username" class="fadeIn second" name="username" placeholder="username">
<input type="text" id="email" class="fadeIn third" name="email" placeholder="email">
<input type="password" id="password" class="fadeIn third" name="password" placeholder="password">
<input type="text" id="username" class="fadeIn second" name="username" placeholder="username" required autofocus>
<input type="email" id="email" class="fadeIn third" name="email" placeholder="email" required>
<input type="password" id="password" class="fadeIn third" name="password" placeholder="password" required>
<button type="submit" class="fadeIn fourth">{{ trans('auth.signup') }}</button>
{{ Form::close() }}
<!-- Remind Passowrd -->
<div id="formFooter">
<a class="underlineHover" href="{{ route('password.request') }}">{{ trans('auth.lost-password') }}</a>
<a href="{{ route('password.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-password') }} </h2></a>
<a href="{{ route('username.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-username') }} </h2></a>
</div>
</div>
+86
View File
@@ -0,0 +1,86 @@
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>{{ trans('auth.lost-username') }} - {{ Config::get('other.title') }}</title>
<!-- Meta -->
@section('meta')
<meta name="description" content="Login now on {{ Config::get('other.title') }}. Not yet member ? Signup in less than 30s.">
<meta property="og:title" content="{{ Config::get('other.title') }}">
<meta property="og:type" content="website">
<meta property="og:image" content="{{ url('/img/rlm.png') }}">
<meta property="og:url" content="{{ url('/') }}">
<meta name="csrf-token" content="{{ csrf_token() }}">
@show
<!-- /Meta -->
<link rel="shortcut icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="icon" href="{{ url('/favicon.ico') }}" type="image/x-icon">
<link rel="stylesheet" href="{{ url('css/vendor/toastr.min.css?v=01') }}" />
<link rel="stylesheet" href="{{ url('css/main/login.css?v=02') }}">
</head>
<body>
<div class="wrapper fadeInDown">
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
<svg viewBox="0 0 1320 100">
<!-- Symbol -->
<symbol id="s-text">
<text text-anchor="middle"
x="50%" y="50%" dy=".35em">
{{ Config::get('other.title') }}
</text>
</symbol>
<!-- Duplicate symbols -->
<use xlink:href="#s-text" class="text"
></use>
<use xlink:href="#s-text" class="text"
></use>
<use xlink:href="#s-text" class="text"
></use>
<use xlink:href="#s-text" class="text"
></use>
<use xlink:href="#s-text" class="text"
></use>
</svg>
<div id="formContent">
<!-- Tabs Titles -->
<a href="{{ route('login') }}"><h2 class="inactive underlineHover">{{ trans('auth.login') }}</h2></a>
<a href="{{ route('register') }}"><h2 class="inactive underlineHover">{{ trans('auth.signup') }}</h2></a>
<!-- Icon -->
<div class="fadeIn first">
<img src="{{ url('/img/icon.svg') }}" id="icon" alt="User Icon" />
</div>
<!-- SignUp Form -->
<form class="form-horizontal" role="form" method="POST" action="{{ route('username.email') }}">
{{ csrf_field() }}
<input type="email" id="email" class="fadeIn third" name="email" placeholder="email" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<button type="submit" class="fadeIn fourth">{{ trans('common.submit') }}</button>
</form>
<!-- Remind Passowrd -->
<div id="formFooter">
<a href="{{ route('password.request') }}"><h2 class="inactive underlineHover">{{ trans('auth.lost-password') }} </h2></a>
<a href="{{ route('username.request') }}"><h2 class="active">{{ trans('auth.lost-username') }} </h2></a>
</div>
</div>
</div>
<script type="text/javascript" src="{{ url('js/vendor/app.js?v=04') }}"></script>
{!! Toastr::message() !!}
</body>
</html>
+8 -4
View File
@@ -29,21 +29,25 @@ Route::group(['middleware' => 'language'], function () {
|------------------------------------------
*/
Route::group(['before' => 'auth', 'middleware' => 'guest'], function () {
// Authentication Routes...
// Authentication Routes
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login')->name('');
// Password Reset Routes...
// Password Reset Routes
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('');
Route::get('/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
// Registration Routes...
// Registration Routes
Route::any('/register/{code?}', 'Auth\RegisterController@register')->name('register');
// Activation Routes...
// Activation Routes
Route::get('/activate/{token}', 'Auth\ActivationController@activate')->name('activate');
// Forgot Username Routes
Route::get('username/reminder', 'Auth\ForgotUsernameController@showForgotUsernameForm')->name('username.request');
Route::post('username/reminder', 'Auth\ForgotUsernameController@sendUserameReminder')->name('username.email');
});
Route::group(['before' => 'auth'], function () {