mirror of
https://github.com/supanadit/todo.git
synced 2024-11-21 17:46:23 +00:00
Change password and update version 1.0.4
This commit is contained in:
parent
f805939989
commit
f0645ce412
@ -133,6 +133,38 @@ class SecurityController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function formChangePassword(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
"email" => "required",
|
||||
"password" => "required",
|
||||
"password_confirm" => "required",
|
||||
]);
|
||||
$user = \App\User::where("email", $request->input("email"))->first();
|
||||
if ($user != null) {
|
||||
if ($request->input('password') == $request->input('password_confirm')) {
|
||||
$user->password = Hash::make($request->input('password'));
|
||||
if ($user->save()) {
|
||||
return response()->json([
|
||||
"message" => "Success change password",
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
"message" => "Failed change password",
|
||||
], 400);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
"message" => "New password is not match with confirm password",
|
||||
], 400);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
"message" => "Email " . $request->input('email') . " is not exist",
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
public function formLogout(Request $request)
|
||||
{
|
||||
$request->session()->flush();
|
||||
|
@ -53,6 +53,11 @@
|
||||
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="/home">Home</a></li>
|
||||
<li>
|
||||
<a href="#" data-toggle="modal" data-target="#change-password-modal">
|
||||
Change Password
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" class="logout-button visible-xs">
|
||||
Sign Out
|
||||
@ -103,10 +108,45 @@
|
||||
<!-- /.container -->
|
||||
</div>
|
||||
<!-- /.content-wrapper -->
|
||||
|
||||
{{-- Change Password Modal --}}
|
||||
<div class="modal fade" id="change-password-modal">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form action="/" method="post" id="change-password-modal-form">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">Change Password</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>New Password</label>
|
||||
<input type="password" class="form-control" placeholder="Insert your new password"
|
||||
id="change-password-modal-form-field-password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Confirm Password</label>
|
||||
<input type="password" class="form-control" placeholder="Please confirm new password"
|
||||
id="change-password-modal-form-field-password-confirm">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="fa fa-spinner fa-spin" id="change-password-modal-save-loading-indicator"></i>
|
||||
<span id="change-password-modal-save-button-label">Save</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal-dialog -->
|
||||
</div>
|
||||
|
||||
<footer class="main-footer">
|
||||
<div class="container">
|
||||
<div class="pull-right hidden-xs">
|
||||
<b>Version</b> 1.0.3
|
||||
<b>Version</b> 1.0.4
|
||||
</div>
|
||||
<strong>Copyright © @php echo date('Y'); @endphp <b>Todo</b> <i>App</i>.</strong>
|
||||
All rights
|
||||
@ -136,6 +176,7 @@
|
||||
|
||||
<script type="application/javascript">
|
||||
$(document).ready(function () {
|
||||
$("#change-password-modal-save-loading-indicator").hide();
|
||||
$(".logout-button").on('click', function () {
|
||||
swal({
|
||||
title: "Do you want to sign out ?",
|
||||
@ -147,6 +188,49 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
$("#change-password-modal-form").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const password = $("#change-password-modal-form-field-password");
|
||||
const passwordConfirm = $("#change-password-modal-form-field-password-confirm");
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/web/change/password",
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
|
||||
},
|
||||
data: JSON.stringify({
|
||||
"email": "{{ Session::get('email') }}",
|
||||
"password": password.val(),
|
||||
"password_confirm": passwordConfirm.val(),
|
||||
}),
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
async: true,
|
||||
beforeSend: function () {
|
||||
$("#change-password-modal-save-loading-indicator").show();
|
||||
$("#change-password-modal-save-button-label").hide();
|
||||
},
|
||||
success: function (result) {
|
||||
$("#change-password-modal-save-loading-indicator").hide();
|
||||
$("#change-password-modal-save-button-label").show();
|
||||
|
||||
password.val(null);
|
||||
passwordConfirm.val(null);
|
||||
|
||||
toastr.success(result.message);
|
||||
|
||||
$("#change-password-modal").modal('hide');
|
||||
},
|
||||
error: function (result) {
|
||||
$("#change-password-modal-save-loading-indicator").hide();
|
||||
$("#change-password-modal-save-button-label").show();
|
||||
|
||||
toastr.error(result.responseJSON.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -63,7 +63,7 @@
|
||||
</div>
|
||||
</form>
|
||||
<br/>
|
||||
Version 1.0.3
|
||||
Version 1.0.4
|
||||
</div>
|
||||
<!-- /.login-box-body -->
|
||||
</div>
|
||||
|
@ -20,6 +20,7 @@ Route::get('/register', "SecurityController@viewRegister");
|
||||
|
||||
Route::middleware('auth.web')->group(function () {
|
||||
Route::get('/home', "TodoController@viewHome");
|
||||
Route::post('/web/change/password', "SecurityController@formChangePassword");
|
||||
|
||||
// This group is used for internal API provided by session
|
||||
Route::prefix('/web')->group(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user