Create User fixed
This commit is contained in:
parent
fc1e086bbe
commit
c369a6aec1
@ -28,10 +28,11 @@ class Create extends Request {
|
|||||||
$username = $this->getParam('username');
|
$username = $this->getParam('username');
|
||||||
$email = $this->getParam('email');
|
$email = $this->getParam('email');
|
||||||
|
|
||||||
if(!$this->userExists($username, $email)) {
|
if(!$this->userExists($username, $email) || !$this->success) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$password = $this->getParam('password');
|
$password = $this->getParam('password');
|
||||||
$confirmPassword = $this->getParam('confirmPassword');
|
$confirmPassword = $this->getParam('confirmPassword');
|
||||||
|
|
||||||
@ -40,7 +41,6 @@ class Create extends Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql = $this->user->getSQL();
|
$sql = $this->user->getSQL();
|
||||||
$this->lastError = $sql->getLastError();
|
|
||||||
|
|
||||||
$this->success = $this->createUser($username, $email, $password);
|
$this->success = $this->createUser($username, $email, $password);
|
||||||
|
|
||||||
@ -49,12 +49,30 @@ class Create extends Request {
|
|||||||
|
|
||||||
private function userExists($username, $email){
|
private function userExists($username, $email){
|
||||||
$sql = $this->user->getSQL();
|
$sql = $this->user->getSQL();
|
||||||
$res = $sql->select("User.uid", "User.password", "User.salt")
|
$res = $sql->select("User.name", "User.email")
|
||||||
->from("User")
|
->from("User")
|
||||||
->where(new Compare("User.name", $username), new Compare("User.email",$email))
|
->where(new Compare("User.name", $username), new Compare("User.email",$email))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
return count($res) !== 0;
|
$this->success = ($res !== FALSE);
|
||||||
|
$this->lastError = $sql->getLastError();
|
||||||
|
|
||||||
|
if($res !== 0) {
|
||||||
|
$this->success = false;
|
||||||
|
$row = $res[0];
|
||||||
|
$message = "";
|
||||||
|
if (strcmp($username,row['name']) != 0 && strcmp($email, row['email']) != 0) {
|
||||||
|
$message = "Username and email are already taken";
|
||||||
|
}else if (strcmp($username,row['name']) != 0) {
|
||||||
|
$message = "Username is already taken";
|
||||||
|
}else{
|
||||||
|
$message = "Email is already taken";
|
||||||
|
}
|
||||||
|
$this->lastError = $message;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createUser($username, $email, $password){
|
private function createUser($username, $email, $password){
|
||||||
@ -65,7 +83,8 @@ class Create extends Request {
|
|||||||
'username' => $username,
|
'username' => $username,
|
||||||
'password' => $hash,
|
'password' => $hash,
|
||||||
'email' => $email
|
'email' => $email
|
||||||
));
|
))->execute();
|
||||||
|
$this->lastError = $sql->getLastError();
|
||||||
return $res === TRUE;
|
return $res === TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user