Browse Source

Merge pull request #434 from nextcloud/password-change-events

Add events and docs for password change
pull/433/head
Ivan Sein 8 years ago
committed by GitHub
parent
commit
0614fe2785
  1. 16
      docs/api-v1.md
  2. 22
      lib/Room.php

16
docs/api-v1.md

@ -124,6 +124,22 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
+ `404 Not Found` When the room could not be found for the participant
+ `405 Method Not Allowed` When the room is a one to one room
### Set password for a room
* Method: `PUT`
* Endpoint: `/room/{token}/password`
* Data:
field | type | Description
------|------|------------
`password` | string | New password for the room
* Response:
- Header:
+ `200 OK`
+ `403 Forbidden` When the current user is not a moderator/owner or the room is not a public room
+ `404 Not Found` When the room could not be found for the participant
### Delete a room
* Method: `DELETE`

22
lib/Room.php

@ -259,6 +259,10 @@ class Room {
$hash = $this->hasher->hash($password);
$this->dispatcher->dispatch(self::class . '::preSetPassword', new GenericEvent($this, [
'password' => $password,
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_rooms')
->set('password', $query->createNamedParameter($hash))
@ -266,6 +270,10 @@ class Room {
$query->execute();
$this->password = $hash;
$this->dispatcher->dispatch(self::class . '::postSetPassword', new GenericEvent($this, [
'password' => $password,
]));
return true;
}
@ -352,12 +360,22 @@ class Room {
* @param int $participantType
*/
public function setParticipantType($participant, $participantType) {
$this->dispatcher->dispatch(self::class . '::preChangeParticipantType', new GenericEvent($this, [
'user' => $participant,
'newType' => $participantType,
]));
$query = $this->db->getQueryBuilder();
$query->update('spreedme_room_participants')
->set('participantType', $query->createNamedParameter($participantType, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('userId', $query->createNamedParameter($participant)));
$query->execute();
$this->dispatcher->dispatch(self::class . '::postChangeParticipantType', new GenericEvent($this, [
'user' => $participant,
'newType' => $participantType,
]));
}
/**
@ -512,12 +530,16 @@ class Room {
}
public function cleanGuestParticipants() {
$this->dispatcher->dispatch(self::class . '::preCleanGuests', new GenericEvent($this));
$query = $this->db->getQueryBuilder();
$query->delete('spreedme_room_participants')
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->emptyString('userId'))
->andWhere($query->expr()->lte('lastPing', $query->createNamedParameter(time() - 30, IQueryBuilder::PARAM_INT)));
$query->execute();
$this->dispatcher->dispatch(self::class . '::postCleanGuests', new GenericEvent($this));
}
/**

Loading…
Cancel
Save