/
change_password.php
67 lines (59 loc) · 1.67 KB
/
change_password.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
include_once "auth.inc.php";
include_once "base_site.inc.php";
class ChangePasswordSite extends BaseSite {
function title() {
parent::title();
echo " - Zmiana hasła";
}
function main_content() {
?>
<div class='dialog'>
<form id='passwd_form'>
<table>
<tr><th colspan=2>Zmiana hasła:</th></tr>
<tr><td><label for='passwd_old_password'>Stare hasło:</label></td><td><input type='text' id='passwd_old_password'></td></tr>
<tr><td><label for='passwd_new_password'>Nowe hasło:</label></td><td><input type='password' id='passwd_new_password'></td></tr>
<tr><td><label for='passwd_new_password2'>Powtórz hasło:</label></td><td><input type='password' id='passwd_new_password2'></td></tr>
<tr><td class='submit' colspan=2><input type='submit' class='submit' value='Zmień'></td></tr>
</table>
</form>
</div>
<script>
$('#passwd_form').submit(function() {
$('#error').text("");
old_password = $('#passwd_old_password').val();
new_password = $('#passwd_new_password').val();
new_password2 = $('#passwd_new_password2').val();
if (new_password != new_password2) {
$('#error').text("nowe hasła się nie zgadzają");
return false;
}
$.ajax({
dataType: 'json',
type: 'POST',
url: 'change_password_ajax.php',
data: {
'action': 'change_password',
'old_password': old_password,
'new_password': new_password,
},
}).done(function(data) {
if (data['error']) {
$('#error').text(data['error']);
} else {
location.href = 'index.php';
}
}).fail(function(data) {
$('#error').html('something gone wrong ' + data['responseText']);
});
return false;
})
</script>
<?php
}
}
assert_is_logged();
$site = new ChangePasswordSite();
$site->show();
?>