diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Model/User.php | 35 | ||||
-rw-r--r-- | app/Schema/Mysql.php | 7 | ||||
-rw-r--r-- | app/Schema/Postgres.php | 7 | ||||
-rw-r--r-- | app/Schema/Sqlite.php | 7 |
4 files changed, 48 insertions, 8 deletions
diff --git a/app/Model/User.php b/app/Model/User.php index b8411533..c1a9dcc9 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -224,12 +224,12 @@ class User extends Base $this->db->startTransaction(); // All tasks assigned to this user will be unassigned - $this->db->table(Task::TABLE)->eq('owner_id', $user_id)->update(array('owner_id' => '')); - $this->db->table(self::TABLE)->eq('id', $user_id)->remove(); + $this->db->table(Task::TABLE)->eq('owner_id', $user_id)->update(array('owner_id' => 0)); + $result = $this->db->table(self::TABLE)->eq('id', $user_id)->remove(); $this->db->closeTransaction(); - return true; + return $result; } /** @@ -265,7 +265,6 @@ class User extends Base private function commonValidationRules() { return array( - new Validators\Required('username', t('The username is required')), new Validators\MaxLength('username', t('The maximum length is %d characters', 50), 50), new Validators\Unique('username', t('The username must be unique'), $this->db->getConnection(), self::TABLE, 'id'), new Validators\Email('email', t('Email address invalid')), @@ -299,7 +298,11 @@ class User extends Base */ public function validateCreation(array $values) { - $v = new Validator($values, array_merge($this->commonValidationRules(), $this->commonPasswordValidationRules())); + $rules = array( + new Validators\Required('username', t('The username is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules(), $this->commonPasswordValidationRules())); return array( $v->execute(), @@ -318,6 +321,28 @@ class User extends Base { $rules = array( new Validators\Required('id', t('The user id is required')), + new Validators\Required('username', t('The username is required')), + ); + + $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); + + return array( + $v->execute(), + $v->getErrors() + ); + } + + /** + * Validate user API modification + * + * @access public + * @param array $values Form values + * @return array $valid, $errors [0] = Success or not, [1] = List of errors + */ + public function validateApiModification(array $values) + { + $rules = array( + new Validators\Required('id', t('The user id is required')), ); $v = new Validator($values, array_merge($rules, $this->commonValidationRules())); diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 86685067..196fb856 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -4,7 +4,12 @@ namespace Schema; use Core\Security; -const VERSION = 26; +const VERSION = 27; + +function version_27($pdo) +{ + $pdo->exec('CREATE UNIQUE INDEX users_username_idx ON users(username)'); +} function version_26($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index a7e57d66..3341d4a1 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -4,7 +4,12 @@ namespace Schema; use Core\Security; -const VERSION = 7; +const VERSION = 8; + +function version_8($pdo) +{ + $pdo->exec('CREATE UNIQUE INDEX users_username_idx ON users(username)'); +} function version_7($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index cab69fa0..108c07f2 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -4,7 +4,12 @@ namespace Schema; use Core\Security; -const VERSION = 26; +const VERSION = 27; + +function version_27($pdo) +{ + $pdo->exec('CREATE UNIQUE INDEX users_username_idx ON users(username)'); +} function version_26($pdo) { |