-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgotPassword.php
81 lines (59 loc) · 1.78 KB
/
forgotPassword.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
<?php
include('header.php');
if(logged_in()) echo "<script>window.location = 'admin.php';</script>";
?>
<h1>Forgot Password</h1>
<hr class="short-fat" />
<?php
if(!empty($_POST)){
$pw = substr(md5(uniqid()), 0, 8);
$type = 'teacher';
$id = get_teacher_id_by_email($_POST['email']);
if(!$id){
$type = student;
$id = get_student_id_by_email($_POST['email']);
}
if($id) {
if($type == 'teacher') update_teacher($id, ['password' => $pw]);
else update_student($id, ['password' => $pw] );
$to = $_POST['email'];
$subject = 'ELH Password Reset';
$message = "Hello {$type},
<p>Your new password is: {$pw}</p>
<p>Feel free to contact us if you have any problems: <a href='".BASE_URL."/contact.php'>Contact Form</a></p>";
send_mail($to, $subject, $message);
}
echo "<div class='alert alert-success' role='alert'><b>Password Changed</b> Please check your email address.</div>";
}
else{
?>
<form method="post">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="sr-only" for="email" required>Email Address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>Entering your email and pressing Reset Password will cause a new password to be generated and emailed to your email address.</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group text-right">
<input type="submit" class="btn btn-primary" value="Reset Password">
</div>
</div>
</div>
</div>
</div>
</form>
<?php
}
?>
<?php include('footer.php'); ?>