-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc.php
159 lines (143 loc) · 6.36 KB
/
abc.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
include('database.php');
include('function.php');
require 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include('header.php');
check_auth();
check_admin_auth();
$msg = "";
$name = "";
$email = "";
$password = "";
$total_qr = "";
$total_hit = "";
$id = 0;
$password_required = "required";
if (isset($_GET['id']) && $_GET['id'] > 0) {
$id = get_safe_value($_GET['id']);
$res = mysqli_query($con, "select * from users where id='$id'");
if (mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
$name = $row['name'];
$email = $row['email'];
$password = $row['password'];
$total_qr = $row['total_qr'];
$total_hit = $row['total_hit'];
$password_required = "";
} else {
redirect('users.php');
}
}
if (isset($_POST['submit'])) {
$name = get_safe_value($_POST['name']);
$email = get_safe_value($_POST['email']);
$password = password_hash(get_safe_value($_POST['password']), PASSWORD_DEFAULT);
$total_qr = get_safe_value($_POST['total_qr']);
$total_hit = get_safe_value($_POST['total_hit']);
$role = 1;
$status = 1;
$added_on = date('Y-m-d h:i:s');
$email_sql = "";
if ($id > 0) {
$email_sql = " and id!='$id'";
}
if (mysqli_num_rows(mysqli_query($con, "select * from users where email='$email' $email_sql")) > 0) {
$msg = "Email id already used";
} else {
if ($id > 0) {
$password_sql = "";
if ($password != '') {
$password_sql = ",password='$password'";
}
mysqli_query($con, "update users set name='$name',email='$email',total_qr='$total_qr',total_hit='$total_hit' $password_sql where id='$id'");
} else {
mysqli_query($con, "insert into users(name,email,password,total_qr,total_hit,role,status,added_on) values('$name','$email','$password','$total_qr','$total_hit','$role','$status','$added_on')");
}
// Sending password to the user's email
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'jkcvlyhixghtnazd';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
//Recipients
// Sender and recipient
$mail->setFrom('[email protected]', 'SecureQRX');
$mail->addAddress($email);
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Your Password';
$mail->Body = 'Your password is: ' . $_POST['password']; // Retrieve the password from the form field
$mail->send();
$msg .= '<br>Password sent successfully to ' . $email;
} catch (Exception $e) {
$msg .= '<br>Password could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
redirect('users.php');
}
}
?>
<div class="page-wrapper">
<div class="page-breadcrumb">
<div class="row align-items-center">
<div class="col-md-6 col-8 align-self-center">
<h3 class="page-title mb-0 p-0">Manage User</h3>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<form class="form-horizontal form-material" method="post">
<div class="form-group">
<label for="example-email" class="col-md-12">Name</label>
<div class="col-md-12">
<input type="name" placeholder="Enter Name" class="form-control pl-0 form-control-line" name="name" required value="<?php echo $name?>">
</div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">Email</label>
<div class="col-md-12">
<input type="email" placeholder="Email" class="form-control pl-0 form-control-line" name="email" required value="<?php echo $email?>">
</div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">Password</label>
<div class="col-md-12">
<input type="password" placeholder="Password" class="form-control pl-0 form-control-line" name="password" <?php echo $password_required?>>
</div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">Total QR Codes</label>
<div class="col-md-12">
<input type="text" placeholder="Total QR Codes" class="form-control pl-0 form-control-line" name="total_qr" value="<?php echo $total_qr?>">
</div>
</div>
<div class="form-group">
<label for="example-email" class="col-md-12">Total QR Hits</label>
<div class="col-md-12">
<input type="text" placeholder="Total QR Hits" class="form-control pl-0 form-control-line" name="total_hit" value="<?php echo $total_hit?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-12 d-flex">
<button class="btn btn-success mx-auto mx-md-0 text-white" name="submit">Submit</button>
</div>
</div>
</form>
<div id="result"><?php echo $msg?></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include('footer.php')?>