-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvite.php
159 lines (135 loc) · 5.26 KB
/
invite.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
// We need to use sessions, so you should always start sessions using the below code.
session_start();
// If the user is not logged in redirect to the login page...
if (!isset($_SESSION['loggedin'])) {
header('Location: index.php');
exit;
}
if ($_SESSION['type'] != 'coach') {
header('Location: index.php');
exit;
}
require 'db/db_connect.php';
$conn = $con;
// Assuming coach is logged in and has a session
$coach_id = $_SESSION['coach_id']; // Coach's user ID
$coach_name = $_SESSION['name'];
if (!filter_var($_POST['player_email'], FILTER_VALIDATE_EMAIL)) {
exit("Invalid email format."); //ADD ERROR PAGE
}
if (strlen($_POST['player_name']) > 20 || strlen($_POST['player_name']) < 2) {
exit('Username must be between 2 and 50 characters long!');
}
if (strlen($_POST['player_email']) > 200) {
exit('Email must be less than 200 characters long!');
}
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: Shotstreak <shotstreak@shotstreak.ca> \r\n";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$player_email = $_POST['player_email'];
$player_name = $_POST['player_name'];
// Generate a random token for the invitation link
$token = bin2hex(random_bytes(16));
// Insert the invitation into the database
$query = "INSERT INTO invitations (coach_id, player_name, player_email, token) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($query);
$stmt->bind_param("isss", $coach_id, $player_name, $player_email, $token);
if ($stmt->execute()) {
// Send an email with the invitation link (Pseudo-code)
$invite_link = "https://localhost/shotstreak/acceptinvite.php?token=" . $token;
$message = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>Invitation to Join Shotstreak</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.email-container {
max-width: 600px;
margin: 0 auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.email-header {
text-align: center;
padding-bottom: 20px;
}
.email-header h1 {
color: #ff6b6b;
}
.email-body {
color: #333;
line-height: 1.6;
}
.email-body p {
margin: 10px 0;
}
.cta-button {
display: inline-block;
padding: 10px 20px;
background-color: #ff6b6b;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
margin-top: 20px;
margin-bottom: 20px;
font-size: 16px;
}
.cta-button:hover {
background-color: #e65a5a;
}
.footer {
text-align: center;
color: #999;
font-size: 12px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class='email-container'>
<div class='email-header'>
<h1>Join Shotstreak!</h1>
<img title='logo' src='https://shotstreak.simonsites.com/assets/isoLogo.svg' alt='Logo' height='200' width='200'>
</div>
<div class='email-body'>
<p><b>Hello, $player_name</b></p>
<p>You’ve been invited by <b>$coach_name</b> to join Shotstreak, a basketball shot tracking platform that helps you monitor your daily shot goals and performance.</p>
<p>To get started, simply click the link below to register and join your coach's team:</p>
<a href='$invite_link' class='cta-button'>Join Shotstreak</a>
<p>If you did not expect this email, feel free to ignore it.</p>
<p>Looking forward to seeing you on the court!</p>
</div>
<div class='footer'>
<p>© 2024 Shotstreak. All rights reserved.</p>
</div>
</div>
</body>
</html>
";
if (mail($player_email, "You've been invited to join Shotstreak!", $message, $headers)) {
header("Location: coach_dashboard.php");
}
else {
header('Location: error.php?a=Email failed to send&b=inviteplayer.php');
exit();
}
} else {
header('Location: error.php?a=An error occurred&b=coach_dashboard.php');
exit();
}
}
?>