Fixed deletion of password when editing user fixing #112

This commit is contained in:
Lukas Metzger 2019-12-25 18:17:44 +01:00
parent 36b6bf5b88
commit aa2a5906f9
2 changed files with 26 additions and 4 deletions

View file

@ -283,12 +283,12 @@ class Users
}
if ($record['backend'] === 'native' && $name !== null) {
//Check if user already exists
//Check if user with new name already exists
$query = $this->db->prepare('SELECT id FROM users WHERE name=:name AND backend=\'native\'');
$query->bindValue(':name', $name);
$query->execute();
$record = $query->fetch();
if ($record !== false && intval($record['id']) !== $userId) {
$recordTest = $query->fetch();
if ($recordTest !== false && intval($recordTest['id']) !== $userId) {
throw new \Exceptions\AlreadyExistentException();
}
}

View file

@ -90,13 +90,35 @@ test.run(async function () {
url: '/users/4',
method: 'put',
data: {
name: 'foo',
name: 'foo1',
password: 'bar',
type: 'user'
}
});
assert.equal(res.status, 204, 'Update should succeed.');
//Test if updated user can log in
var res = await req({
url: '/sessions',
method: 'post',
data: {
username: 'foo1',
password: 'bar'
}
});
assert.equal(res.status, 201, 'Login with updated user should succeed.');
//Test user update without password
var res = await req({
url: '/users/4',
method: 'put',
data: {
name: 'foo',
type: 'user'
}
});
assert.equal(res.status, 204, 'Update should succeed.');
//Test if updated user can log in
var res = await req({
url: '/sessions',