forked from jvbkw8/Group2Final
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditUser.php
58 lines (58 loc) · 2.06 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
55
56
57
58
<?php
if(!isset($_POST['id']) || !isset($_POST['action'])){
echo json_encode(array("error"=>'Required data not sent'));
exit();
}
header("Content-Type: application/json");
require "DBConn.php";
$conn = new DBConn();
if($conn->connectToDatabase()){
switch($_POST['action']){
case "resetPassword":
$newPassword = password_hash("password123", PASSWORD_DEFAULT);
$q = "UPDATE db.user SET hashedpassword = ? where id = ?";
if($conn->update($q, $newPassword, $_POST['id'])){
echo json_encode(array("success"=> 'Password is now password123'));
} else {
echo json_encode(array("error"=> 'Password not reset'));
}
break;
case "activateUser":
$q = "UPDATE db.user SET activeuserflag = ? where id = ?";
if($conn->update($q, "1", $_POST['id'])){
echo json_encode(array("success"=> 'User activated'));
} else {
echo json_encode(array("error"=> 'User activation failed'));
}
break;
case "deactivateUser":
$q = "UPDATE db.user SET activeuserflag = ? where id = ?";
if($conn->update($q, "0", $_POST['id'])){
echo json_encode(array("success"=> 'User deactivated'));
} else {
echo json_encode(array("error"=> 'User deactivation failed'));
}
break;
case "adminify":
$q = "UPDATE db.user SET isadmin = ? where id = ?";
if($conn->update($q, '1', $_POST['id'])){
echo json_encode(array("success"=> 'User is now an admin'));
} else {
echo json_encode(array("error"=> 'Adminification failed'));
}
break;
case "deadminify":
$q = "UPDATE db.user SET isadmin = ? where id = ?";
if($conn->update($q, '0', $_POST['id'])){
echo json_encode(array("success"=> 'User is no longer an admin'));
} else {
echo json_encode(array("error"=> 'De-admnification failed'));
}
break;
default:
echo json_encode(array("error"=> 'Action requested is not clear. '.$_POST['action']));
}
} else {
echo json_encode(array("error"=> 'Could not connect. Try again later'));
}
?>