Fixed deletion of password when editing user fixing #112
This commit is contained in:
parent
36b6bf5b88
commit
aa2a5906f9
2 changed files with 26 additions and 4 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue