mirror of
https://github.com/supanadit/todo.git
synced 2024-11-22 01:56:21 +00:00
Forgot password feature added
This commit is contained in:
parent
54037eed87
commit
550a96d27b
@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\ForgotPassword;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SecurityController extends Controller
|
||||
{
|
||||
@ -108,6 +111,28 @@ class SecurityController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function formForgotPassword(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
"email" => "required",
|
||||
]);
|
||||
$user = \App\User::where("email", $request->input("email"))->first();
|
||||
if ($user != null) {
|
||||
$name = $user->name;
|
||||
$newPassword = Str::random(4);
|
||||
$user->password = Hash::make($newPassword);
|
||||
Mail::to($user->email)->send(new ForgotPassword($name, $newPassword));
|
||||
$user->save();
|
||||
return response()->json([
|
||||
"message" => "Please check your email",
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
"message" => "Email " . $request->input('email') . " is not exist",
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function formLogout(Request $request)
|
||||
{
|
||||
$request->session()->flush();
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
@ -11,14 +10,19 @@ class ForgotPassword extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $name;
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
* @param $name
|
||||
* @param $password
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($name, $password)
|
||||
{
|
||||
//
|
||||
$this->name = $name;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,6 +32,6 @@ class ForgotPassword extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
return $this->view('view.name');
|
||||
return $this->view('template.email.forgot');
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@
|
||||
<div class="login-box-body">
|
||||
<p class="login-box-msg">Forgot Password</p>
|
||||
|
||||
<form action="/" method="post" id="login-form">
|
||||
<form action="/" method="post" id="forgot-password-form">
|
||||
<div class="form-group has-feedback">
|
||||
<input type="email" class="form-control" placeholder="Email" id="email">
|
||||
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
|
||||
@ -72,17 +72,16 @@
|
||||
<script src="{{asset('plugin/iCheck/icheck.min.js')}}"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#login-form").on("submit", function (e) {
|
||||
$("#forgot-password-form").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/web/login",
|
||||
url: "/web/forgot",
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
|
||||
},
|
||||
data: JSON.stringify({
|
||||
"email": $("#email").val(),
|
||||
"password": $("#password").val()
|
||||
}),
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
@ -90,7 +89,7 @@
|
||||
success: function (result) {
|
||||
toastr.success(result.message);
|
||||
window.setTimeout(function () {
|
||||
location.reload();
|
||||
location.href = "/";
|
||||
}, 500);
|
||||
},
|
||||
error: function (result) {
|
||||
|
@ -53,7 +53,7 @@
|
||||
<div class="row">
|
||||
<div class="col-xs-8">
|
||||
<a href="/register" class="text-center">Register new account</a><br/>
|
||||
Version 1.0.2
|
||||
<a href="/forgot/password" class="text-center">Forgot Password</a><br/>
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
<div class="col-xs-4">
|
||||
@ -62,7 +62,8 @@
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
</form>
|
||||
{{-- <a href="/forgot/password">Forgot Password</a><br>--}}
|
||||
<br/>
|
||||
Version 1.0.2
|
||||
</div>
|
||||
<!-- /.login-box-body -->
|
||||
</div>
|
||||
|
5
resources/views/template/email/forgot.blade.php
Normal file
5
resources/views/template/email/forgot.blade.php
Normal file
@ -0,0 +1,5 @@
|
||||
<div>
|
||||
Hi, {{ $name }}<br/>
|
||||
This is your new password : {{ $password }}<br/>
|
||||
<p>You can change it after login back</p>
|
||||
</div>
|
@ -15,7 +15,7 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', "SecurityController@initSystem");
|
||||
Route::get('/login', "SecurityController@viewLogin")->name('login');
|
||||
//Route::get('/forgot/password', "SecurityController@viewForgotPassword");
|
||||
Route::get('/forgot/password', "SecurityController@viewForgotPassword");
|
||||
Route::get('/register', "SecurityController@viewRegister");
|
||||
|
||||
Route::middleware('auth.web')->group(function () {
|
||||
@ -43,5 +43,6 @@ Route::middleware('auth.web')->group(function () {
|
||||
});
|
||||
|
||||
Route::post('/web/login', "SecurityController@formLogin");
|
||||
Route::post('/web/forgot', "SecurityController@formForgotPassword");
|
||||
Route::post('/web/register', "SecurityController@formRegister");
|
||||
Route::get('/web/logout', "SecurityController@formLogout");
|
||||
|
Loading…
Reference in New Issue
Block a user