-
Notifications
You must be signed in to change notification settings - Fork 0
/
editUser.php
executable file
·54 lines (44 loc) · 1.49 KB
/
editUser.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
<?php require('core/init.php'); ?>
<?php
if (isset($_SESSION['user_name'])) {
// Create User Object
$user = new User;
//Create Validator object
$validate = new Validator;
//Get Template & Assing Vars
$template = new Template('templates/editUser.php');
if (isset($_POST['changePassword'])) {
// Sanitize POST data
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
//Get Vars
$data = [
'id' => $_SESSION['user_id'],
'name' => $_SESSION['user_name'],
'oldPassword' => md5(trim($_POST['oldPassword'])),
'password' => md5(trim($_POST['password'])),
'confirmPassword' => md5(trim($_POST['confirmPassword']))
];
$field_array = array('oldPassword', 'password', 'confirmPassword');
if($validate->isRequired($field_array)){
if ($validate->oldPasswordCheck($data['name'], $data['oldPassword'])){
if($validate->passwordsMatch($data['password'], $data['confirmPassword'])){
if($user->changePassword($data)){
redirect('editUser.php', 'Uspešno ste izmenili lozinku', 'success');
} else {
redirect('editUser.php', 'Desilo se ne objašnjivo', 'error');
}
} else {
redirect('editUser.php', 'Kontrolna lozinka se razlikuje', 'error');
}
} else {
redirect('editUser.php', 'Nije ispravna star lozinka', 'error');
}
} else {
redirect('editUser.php', 'Molim vas popunite sva obavezna polja', 'error');
}
}
// Display template
echo $template;
} else {
redirect('index.php', 'Niste prijavljeni na sistem', 'error');
}