This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
members_manage.php
63 lines (57 loc) · 2.22 KB
/
members_manage.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
<?php
session_start();
include_once(dirname(__FILE__).'/Controller/UserController.php');
include_once(dirname(__FILE__).'/Utils/Mailer.php');
include_once(dirname(__FILE__).'/Utils/Constants.php');
if(!isset($_SESSION['user_id']) || !isset($_SESSION['user_name'])){
header("Location: login");
exit;
}
$user_controller = UserController::getInstance();
if(!$user_controller->isAdmin($_SESSION['user_id'])){
header("Location: index");
exit;
}
function generateRandomString($length = 8) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
if(isset($_POST['delete_user'])){
$len = count($_POST['users']);
for($i = 0; $i < $len; $i++){
$user_controller->removeUser($_POST['users'][$i]);
}
$_SESSION['success'] = "User Deleted!";
header("Location: members");
exit;
}
if(isset($_POST['reset_password'])){
$len = count($_POST['users']);
for($i = 0; $i < $len; $i++){
$new_password = generateRandomString();
$user_controller->resetPassword($_POST['users'][$i], $new_password);
$user[] = $user_controller->getUserInfo($_POST['users'][$i]);
$mailSubject = "NUSSU commIT Account Password Reset";
$mailBody = "Your password has been reset to: ".$new_password.".\nPlease login and change your password immediately".FOOTER_MESSAGE;
sendMail($mailSubject, $mailBody, $user);
}
$_SESSION['success'] = "Password reset!";
//TODO: resend email
header("Location: members");
exit;
}
if(isset($_POST['change_status'])){
$len = count($_POST['users']);
for($i = 0; $i < $len; $i++){
$user_controller->changeUserStatus($_POST['users'][$i]);
}
$_SESSION['success'] = "Status Updated";
header("Location: members");
exit;
}
?>