-
Notifications
You must be signed in to change notification settings - Fork 0
/
signUp.php
289 lines (255 loc) · 8.4 KB
/
signUp.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Clinet;
use Aws\Exception\AwsException;
$message = "";
$sumName = "";
$userName = "";
if(isset($_POST['submit'])){
$userName = $_POST['ign'];
$pswd = $_POST['pswd'];
$email = $_POST['email'];
$server = $_POST['server'];
$sumName = str_replace(' ', '', $_POST['sumName']);
$apiKey = getenv('RIOT_API');
$summonerInfo = "https://";
$serverStr = "";
switch($server){
case "NA":
$serverStr = "na1";
break;
/*
case "KR":
$serverStr = "kr";
break;
case "EUNE":
$serverStr = "eun1";
break;
case "EUW":
$serverStr = "euw1";
break;
case "BR":
$serverStr = "br1";
break;
case "JP":
$serverStr = "jp1";
break;
case "LAN":
$serverStr = "la1";
break;
case "LAS":
$serverStr = "la2";
break;
case "OCE":
$serverStr = "oc1";
break;
case "TR":
$serverStr = "tr1";
break;
case "RU":
$serverStr = "ru";
break;
*/
}
//curl request url
$summonerInfo .= $serverStr;
$summonerInfo .= ".api.riotgames.com/lol/summoner/v3/summoners/by-name/".$sumName."?api_key=".$apiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $summonerInfo);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
$pswd = password_hash($pswd, PASSWORD_DEFAULT);
$dbHost = getenv('RDS_HOSTNAME');
$dbUser = getenv('RDS_USERNAME');
$dbPass = getenv('RDS_PASSWORD');
$dbConn = 'mysql:host='.$dbHost.';dbname='.$serverStr.';charset=utf8mb4';
try{
$conn = new \PDO( $dbConn,
$dbUser,
$dbPass,
array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => false
)
);
//valid only if entered summoner name exist in League of Legends
if(property_exists($obj, 'id')){
$sumId = $obj->{'id'};
//query to check if user with the summoner id is already registered in LeagueLights
$idHandle = $conn->prepare("SELECT SummonerId from user where SummonerId = ?");
$idHandle->bindParam(1, $sumId, PDO::PARAM_INT);
$idHandle->execute();
//query to check if user with the name is already registered in LeagueLights
$nameHandle = $conn->prepare("SELECT Name from user where Name = ?");
$nameHandle->bindParam(1, $userName, PDO::PARAM_STR);
$nameHandle->execute();
if($idHandle->rowCount()>0){
$message = "The summoner name is already registered in LeagueLights";
}else if($idHandle->rowCount()<=0 && $nameHandle->rowCount()>0){
$message = "The user name is already used";
}else if($idHandle->rowCount()<=0 && $nameHandle->rowCount()<=0){
//if the user information is not registered and valid, register user with provided inputs
$registerHandle = $conn->prepare("INSERT INTO user (SummonerId, Name, Password, Email) VALUES (?, ?, ?, ?)");
$registerHandle->bindParam(1, $sumId, PDO::PARAM_INT);
$registerHandle->bindParam(2, $userName, PDO::PARAM_STR);
$registerHandle->bindParam(3, $pswd, PDO::PARAM_STR);
$registerHandle->bindParam(4, $email, PDO::PARAM_STR);
$registerHandle->execute();
$bucketName = $serverStr.'-vid';
$folderName = $sumId.'/';
//s3 bucket access with AWS S3Client
$s3Client = new Aws\S3\S3Client([
'version' => 'latest',
'region' => 'ca-central-1'
]);
try{
//create directory for the user
$s3Client->putObject([
'Bucket' => $bucketName,
'Key' => $folderName,
'Body' => '',
'ACL' => 'public-read-write',
]);
}catch(Aws\Exception\S3Exception $e){
echo "There was an error creating user directory.\n";
}
//once completion of the sign up, user will be redirect to main page of LeagueLights
header("Location:index.php");
exit;
}
}else{
$message = "Seems like Summoner name is not registered, please check it again";
}
}catch(\PDOException $ex){
print($ex->getMessage());
}
}
?>
<script language='javascript' type='text/javascript'>
var message = '<?php echo $message;?>';
window.onload = function() {
//display error message
var msg = document.getElementById("errorMsg");
msg.innerHTML = message;
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>LeagueLights</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/shop-homepage.css" rel="stylesheet">
<link href="css/leaguelights.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="/">LeagueLights</a>
</div>
</nav>
<div class="container py-5">
<div class="row my-4">
<form method="post" id="userInfo" class="col-lg-12">
<div class="row">
<div class="col-lg-3"></div>
<h4 class="col-lg-2 text-center">Username:</h4>
<!--user name must be at least 6 characters-->
<input class="col-lg-4" type="text" name="ign" minlength=6 maxlength=16 required>
<div class="col-lg-3"></div>
</div>
<br>
<div class="row">
<div class="col-lg-3"></div>
<!--password must be at least 5 characters-->
<h4 class="col-lg-2 text-center">Password:</h4>
<input class="col-lg-4" type="password" id="password" name="pswd" minlength=6 maxlength=64 required>
<div class="col-lg-3"></div>
</div>
<br>
<div class="row">
<div class="col-lg-3"></div>
<h4 class="col-lg-2 text-center">Confirm Password:</h4>
<input class="col-lg-4" type="password" name="pswdConf" oninput="check(this)" required>
<div class="col-lg-3"></div>
</div>
<script language='javascript' type='text/javascript'>
// function to check if password and confirmed password are equal
function check(input) {
if (input.value != document.getElementById('password').value) {
input.setCustomValidity('Password Must be Matching.');
} else {
// input is valid -- reset the error message
input.setCustomValidity('');
}
}
</script>
<br>
<div class ="row">
<div class="col-lg-3"></div>
<h4 class="col-lg-2 text-center">Summoner Name:</h4>
<!--user must register to LeagueLights with vaild summoner name-->
<input class="col-lg-4" type="text" name="sumName" placeholder="Your League of Legends' name" required>
<div class="col-lg-3"></div>
</div>
<br>
<div class="row">
<div class="col-lg-3"></div>
<!-- sns will be implemented soon to confirm user-->
<h4 class="col-lg-2 text-center">Email:</h4>
<input class="col-lg-4" type="email" name="email" required>
<div class="col-lg-3"></div>
</div>
<br>
<div class="row">
<div class="col-lg-5"></div>
<select class="col-lg-2" name="server">
<option>NA</option>
<!--<option>KR</option>
<option>BR</option>
<option>JP</option>
<option>EUNE</option>
<option>EUW</option>
<option>LAN</option>
<option>LAS</option>
<option>OCE</option>
<option>TR</option>
<option>RU</option>-->
</select><br />
<div class="col-lg-5"></div>
</div>
<br>
<div class="row">
<div class="col-lg-5"></div>
<button class="col-lg-2" type="submit" name="submit" value="submit">Register</button>
<div class="col-lg-5"></div>
</div>
<br>
<div class="row">
<div class="col-lg-3"></div>
<div class="col-lg-6">
<h3 class="text-center" id="errorMsg" style="color:#8b0000"></h3>
</div>
<div class="col-lg-3"></div>
</div>
</form>
</div>
</div>
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">Copyright © LeagueLights 2018</p>
</div>
<!-- /.container -->
</footer>
</body>
</html>