Register first user as admin
This commit fixes #50 and is needed for the admin panel
This commit is contained in:
parent
510ce89338
commit
a2eb5cc7b3
@ -322,15 +322,23 @@ class User {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$apikey = hash("sha256",$username.$salt);
|
$apikey = hash("sha256",$username.$salt);
|
||||||
$stmt = $this->mysqli->prepare("
|
if ($this->mysqli->query("SELECT id FROM $this->table LIMIT 1")->num_rows > 0) {
|
||||||
INSERT INTO $this->table (username, pass, email, pin, api_key)
|
$stmt = $this->mysqli->prepare("
|
||||||
VALUES (?, ?, ?, ?, ?)
|
INSERT INTO $this->table (username, pass, email, pin, api_key)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
");
|
");
|
||||||
|
} else {
|
||||||
|
$stmt = $this->mysqli->prepare("
|
||||||
|
INSERT INTO $this->table (username, pass, email, pin, api_key, admin)
|
||||||
|
VALUES (?, ?, ?, ?, ?, 1)
|
||||||
|
");
|
||||||
|
}
|
||||||
if ($this->checkStmt($stmt)) {
|
if ($this->checkStmt($stmt)) {
|
||||||
$stmt->bind_param('sssss', $username, hash("sha256", $password1.$this->salt), $email1, hash("sha256", $pin.$this->salt), $apikey);
|
$stmt->bind_param('sssss', $username, hash("sha256", $password1.$this->salt), $email1, hash("sha256", $pin.$this->salt), $apikey);
|
||||||
if (!$stmt->execute()) {
|
if (!$stmt->execute()) {
|
||||||
$this->setErrorMessage( 'Unable to register' );
|
$this->setErrorMessage( 'Unable to register' );
|
||||||
if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username already exists' );
|
if ($stmt->sqlstate == '23000') $this->setErrorMessage( 'Username already exists' );
|
||||||
|
echo $this->mysqli->error;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user