1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* The MIT License (MIT) |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
15
|
|
|
* copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param $url |
28
|
|
|
* @param $user |
29
|
|
|
* @param $pass |
30
|
|
|
* @param $dbName |
31
|
|
|
* @param $userID |
32
|
|
|
* @param $characterID |
33
|
|
|
* @param $eveName |
34
|
|
|
* @param $type |
35
|
|
|
* @return null |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
|
39
|
|
View Code Duplication |
function insertUser($url, $user, $pass, $dbName, $userID, $characterID, $eveName, $type) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$host = $url; |
42
|
|
|
$username = $user; |
43
|
|
|
$password = $pass; |
44
|
|
|
$database = $dbName; |
45
|
|
|
$mysqli = mysqli_connect($host, $username, $password, $database); |
46
|
|
|
|
47
|
|
|
if ($stmt = $mysqli->prepare("REPLACE into authUsers (characterID, discordID, eveName, active, role) values(?,?,?,'yes',?)")) { |
48
|
|
|
|
49
|
|
|
// Bind the variables to the parameter as strings. |
50
|
|
|
$stmt->bind_param('ssss', $characterID, $userID, $eveName, $type); |
51
|
|
|
|
52
|
|
|
// Execute the statement. |
53
|
|
|
$stmt->execute(); |
54
|
|
|
|
55
|
|
|
// Close the prepared statement. |
56
|
|
|
$stmt->close(); |
57
|
|
|
return null; |
58
|
|
|
} |
59
|
|
|
return null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param $url |
64
|
|
|
* @param $user |
65
|
|
|
* @param $pass |
66
|
|
|
* @param $dbName |
67
|
|
|
* @param $authCode |
68
|
|
|
* @return null |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
function disableReg($url, $user, $pass, $dbName, $authCode) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$host = $url; |
73
|
|
|
$username = $user; |
74
|
|
|
$password = $pass; |
75
|
|
|
$database = $dbName; |
76
|
|
|
$mysqli = mysqli_connect($host, $username, $password, $database); |
77
|
|
|
|
78
|
|
|
if ($stmt = $mysqli->prepare("UPDATE pendingUsers SET active='0' WHERE authString= ?")) { |
79
|
|
|
|
80
|
|
|
// Bind the variables to the parameter as strings. |
81
|
|
|
$stmt->bind_param('s', $authCode); |
82
|
|
|
|
83
|
|
|
// Execute the statement. |
84
|
|
|
$stmt->execute(); |
85
|
|
|
|
86
|
|
|
// Close the prepared statement. |
87
|
|
|
$stmt->close(); |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
return null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param $url |
95
|
|
|
* @param $user |
96
|
|
|
* @param $pass |
97
|
|
|
* @param $dbName |
98
|
|
|
* @param $authCode |
99
|
|
|
* @return bool|null |
100
|
|
|
*/ |
101
|
|
View Code Duplication |
function selectPending($url, $user, $pass, $dbName, $authCode) |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
$host = $url; |
104
|
|
|
$username = $user; |
105
|
|
|
$password = $pass; |
106
|
|
|
$database = $dbName; |
107
|
|
|
$mysqli = mysqli_connect($host, $username, $password, $database); |
108
|
|
|
|
109
|
|
|
if ($stmt = $mysqli->prepare("SELECT * FROM pendingUsers WHERE authString= ? AND active='1'")) { |
110
|
|
|
|
111
|
|
|
// Bind the variables to the parameter as strings. |
112
|
|
|
$stmt->bind_param('s', $authCode); |
113
|
|
|
|
114
|
|
|
// Execute the statement. |
115
|
|
|
$stmt->execute(); |
116
|
|
|
|
117
|
|
|
// Return Row |
118
|
|
|
$result = $stmt->get_result(); |
119
|
|
|
|
120
|
|
|
// Close the prepared statement. |
121
|
|
|
$stmt->close(); |
122
|
|
|
return $result; |
123
|
|
|
} |
124
|
|
|
return null; |
125
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.