Create User + Chart dependency
This commit is contained in:
@@ -65,7 +65,7 @@ class Fetch extends Request {
|
||||
foreach($res as $row) {
|
||||
$id = $row["uid"];
|
||||
if (!isset($this->notifications[$id])) {
|
||||
$this->notifications[$id] = array(
|
||||
$this->notifications[] = array(
|
||||
"uid" => $id,
|
||||
"title" => $row["title"],
|
||||
"message" => $row["message"],
|
||||
|
||||
@@ -21,70 +21,61 @@ class Create extends Request {
|
||||
}
|
||||
|
||||
public function execute($values = array()) {
|
||||
if(!parent::execute($values)) {
|
||||
if (!parent::execute($values)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $this->getParam('username');
|
||||
$email = $this->getParam('email');
|
||||
|
||||
if(!$this->userExists($username, $email) || !$this->success) {
|
||||
return false;
|
||||
if (!$this->userExists($username, $email) || !$this->success) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$password = $this->getParam('password');
|
||||
$confirmPassword = $this->getParam('confirmPassword');
|
||||
|
||||
if($password !== $confirmPassword) {
|
||||
return false;
|
||||
if ($password !== $confirmPassword) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = $this->user->getSQL();
|
||||
|
||||
$this->success = $this->createUser($username, $email, $password);
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
private function userExists($username, $email) {
|
||||
$sql = $this->user->getSQL();
|
||||
$res = $sql->select("User.name", "User.email")
|
||||
->from("User")
|
||||
->where(new Compare("User.name", $username), new Compare("User.email", $email))
|
||||
->execute();
|
||||
|
||||
$this->success = ($res !== FALSE);
|
||||
$this->lastError = $sql->getLastError();
|
||||
|
||||
if (!empty($res)) {
|
||||
$row = $res[0];
|
||||
if (strcasecmp($username, $row['name']) === 0) {
|
||||
$this->lastError = "This username is already in use.";
|
||||
$this->success = false;
|
||||
} else if (strcasecmp($username, $row['email']) === 0) {
|
||||
$this->lastError = "This email address is already taken";
|
||||
$this->success = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success;
|
||||
}
|
||||
|
||||
private function userExists($username, $email){
|
||||
$sql = $this->user->getSQL();
|
||||
$res = $sql->select("User.name", "User.email")
|
||||
->from("User")
|
||||
->where(new Compare("User.name", $username), new Compare("User.email",$email))
|
||||
->execute();
|
||||
|
||||
$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){
|
||||
$sql = $this->user->getSQL();
|
||||
$salt = generateRandomString(16);
|
||||
$hash = hash('sha256', $password . $salt);
|
||||
$res = $sql->insert("User",array(
|
||||
'username' => $username,
|
||||
'password' => $hash,
|
||||
'email' => $email
|
||||
))->execute();
|
||||
$this->lastError = $sql->getLastError();
|
||||
return $res === TRUE;
|
||||
private function createUser($username, $email, $password) {
|
||||
$sql = $this->user->getSQL();
|
||||
$salt = generateRandomString(16);
|
||||
$hash = hash('sha256', $password . $salt);
|
||||
$res = $sql->insert("User", array(
|
||||
'username' => $username,
|
||||
'password' => $hash,
|
||||
'salt' => $salt,
|
||||
'email' => $email
|
||||
))->execute();
|
||||
$this->lastError = $sql->getLastError();
|
||||
return $res === TRUE;
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ class CreateDatabase {
|
||||
->primaryKey("uid", "user_id")
|
||||
->foreignKey("user_id", "User", "uid", new CascadeStrategy());
|
||||
|
||||
$queries[] = $sql->createTable("UserInvitation")
|
||||
->addString("username",32)
|
||||
->addString("email",32)
|
||||
->addString("token",36)
|
||||
->addDateTime("valid_until");
|
||||
|
||||
$queries[] = $sql->createTable("UserToken")
|
||||
->addInt("user_id")
|
||||
->addString("token", 36)
|
||||
|
||||
Reference in New Issue
Block a user