Added function of password.php
This commit is contained in:
parent
d045aa8c80
commit
ea9868f908
38
api/password.php
Normal file
38
api/password.php
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once '../config/config-default.php';
|
||||||
|
require_once '../lib/database.php';
|
||||||
|
require_once '../lib/session.php';
|
||||||
|
|
||||||
|
$input = json_decode(file_get_contents('php://input'));
|
||||||
|
|
||||||
|
if(isset($input->action) && $input->action == "changePassword") {
|
||||||
|
$passwordHash = password_hash($input->password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
$stmt = $db->prepare("UPDATE user SET password=? WHERE id=?");
|
||||||
|
$stmt->bind_param("si", $passwordHash, $_SESSION['id']);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($retval)) {
|
||||||
|
echo json_encode($retval);
|
||||||
|
} else {
|
||||||
|
echo "{}";
|
||||||
|
}
|
62
js/password.js
Normal file
62
js/password.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
$('#saveChanges').click(function(evt){
|
||||||
|
evt.preventDefault();
|
||||||
|
savePassword();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#user-password').unbind().bind("paste keyup change", function() {
|
||||||
|
$('#user-password').parent().removeClass("has-error");
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#user-password2').unbind().bind("paste keyup change", function() {
|
||||||
|
if($('#user-password').val() != $('#user-password2').val()) {
|
||||||
|
$('#user-password2').parent().addClass("has-error");
|
||||||
|
} else {
|
||||||
|
$('#user-password2').parent().removeClass("has-error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function savePassword() {
|
||||||
|
|
||||||
|
if($('#user-password').val().length <= 0) {
|
||||||
|
$('#user-password').parent().addClass("has-error");
|
||||||
|
$('#user-password2').parent().addClass("has-error");
|
||||||
|
}
|
||||||
|
if($('#user-password2').parent().hasClass("has-error")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
password: $('#user-password').val(),
|
||||||
|
action: "changePassword"
|
||||||
|
};
|
||||||
|
|
||||||
|
$.post(
|
||||||
|
"api/password.php",
|
||||||
|
JSON.stringify(data),
|
||||||
|
function(data) {
|
||||||
|
$('#user-password').val("");
|
||||||
|
$('#user-password2').val("");
|
||||||
|
},
|
||||||
|
"json"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ limitations under the License.
|
||||||
<script src="include/bootstrap/js/bootstrap.min.js"></script>
|
<script src="include/bootstrap/js/bootstrap.min.js"></script>
|
||||||
<script src="include/select2/select2.min.js"></script>
|
<script src="include/select2/select2.min.js"></script>
|
||||||
|
|
||||||
<script src="js/edit-user.js"></script>
|
<script src="js/password.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-inverse navbar-static-top">
|
<nav class="navbar navbar-inverse navbar-static-top">
|
||||||
|
@ -61,13 +61,13 @@ limitations under the License.
|
||||||
<form>
|
<form>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="user-password" class="control-label">Password</label>
|
<label for="user-password" class="control-label">Password</label>
|
||||||
<input type="password" class="form-control" id="user-password" placeholder="(Unchanged)" autocomplete="off" tabindex="2">
|
<input type="password" class="form-control" id="user-password" placeholder="Password" autocomplete="off" tabindex="2">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="user-password2" class="control-label">Password repeated</label>
|
<label for="user-password2" class="control-label">Password repeated</label>
|
||||||
<input type="password" class="form-control" id="user-password2" placeholder="(Unchanged)" autocomplete="off" tabindex="3">
|
<input type="password" class="form-control" id="user-password2" placeholder="Password repeated" autocomplete="off" tabindex="3">
|
||||||
</div>
|
</div>
|
||||||
<button id="user-button-add" class="btn btn-primary" tabindex="5">Change</button>
|
<button id="saveChanges" class="btn btn-primary" tabindex="5">Change</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</row>
|
</row>
|
||||||
|
|
Loading…
Reference in a new issue