* @param string $email
* @return DataResponse
*/
- public function create($username, $password, array $groups=array(), $email='') {
+ public function create($username, $password, array $groups=[], $email='') {
if($email !== '' && !$this->mailer->validateMailAddress($email)) {
return new DataResponse(
- array(
+ [
'message' => (string)$this->l10n->t('Invalid mail address')
- ),
+ ],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
if (empty($groups)) {
return new DataResponse(
- array(
+ [
'message' => $this->l10n->t('No valid group selected'),
- ),
+ ],
Http::STATUS_FORBIDDEN
);
}
if ($this->userManager->userExists($username)) {
return new DataResponse(
- array(
+ [
'message' => (string)$this->l10n->t('A user with that name already exists.')
- ),
+ ],
Http::STATUS_CONFLICT
);
}
if ($password === '') {
if ($email === '') {
return new DataResponse(
- array(
+ [
'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
- ),
+ ],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
$message = $this->l10n->t('Unable to create user.');
}
return new DataResponse(
- array(
+ [
'message' => (string) $message,
- ),
+ ],
Http::STATUS_FORBIDDEN
);
}
$emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken);
$this->newUserMailHelper->sendMail($user, $emailTemplate);
} catch(\Exception $e) {
- $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
+ $this->log->error("Can't send new user mail to $email: " . $e->getMessage(), ['app' => 'settings']);
}
}
// fetch users groups
}
return new DataResponse(
- array(
- 'message' => (string)$this->l10n->t('Unable to create user.')
- ),
+ [
+ 'message' => (string) $this->l10n->t('Unable to create user.')
+ ],
Http::STATUS_FORBIDDEN
);
if($userId === $id) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Unable to delete user.')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Unable to delete user.')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
+ 'data' => [
'message' => (string)$this->l10n->t('Authentication error')
- )
- ),
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
if($user) {
if($user->delete()) {
return new DataResponse(
- array(
+ [
'status' => 'success',
- 'data' => array(
+ 'data' => [
'username' => $id
- )
- ),
+ ]
+ ],
Http::STATUS_NO_CONTENT
);
}
}
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
+ 'data' => [
'message' => (string)$this->l10n->t('Unable to delete user.')
- )
- ),
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
- if($userId === $id) {
+ if ($userId === $id) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Error while disabling user.')
- )
- ),
- Http::STATUS_FORBIDDEN
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Error while disabling user.')
+ ]
+ ], Http::STATUS_FORBIDDEN
);
}
- if($user) {
+ if ($user) {
if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Authentication error')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Authentication error')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
$user->setEnabled(false);
return new DataResponse(
- array(
+ [
'status' => 'success',
- 'data' => array(
+ 'data' => [
'username' => $id,
'enabled' => 0
- )
- )
+ ]
+ ]
);
} else {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Error while disabling user.')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Error while disabling user.')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
$userId = $this->userSession->getUser()->getUID();
$user = $this->userManager->get($id);
- if($userId === $id) {
+ if ($userId === $id) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Error while enabling user.')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Error while enabling user.')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
if($user) {
- if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
+ if (!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Authentication error')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Authentication error')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
$user->setEnabled(true);
return new DataResponse(
- array(
+ [
'status' => 'success',
- 'data' => array(
+ 'data' => [
'username' => $id,
'enabled' => 1
- )
- )
+ ]
+ ]
);
} else {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Error while enabling user.')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Error while enabling user.')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
* @return DataResponse
*/
public function setEnabled($id, $enabled) {
- if((bool)$enabled) {
+ if ((bool) $enabled) {
return $this->enable($id);
} else {
return $this->disable($id);
$twitterScope
) {
- if(!empty($email) && !$this->mailer->validateMailAddress($email)) {
+ if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Invalid mail address')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Invalid mail address')
+ ]
+ ],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
try {
$this->saveUserSettings($user, $data);
return new DataResponse(
- array(
+ [
'status' => 'success',
- 'data' => array(
+ 'data' => [
'userId' => $user->getUID(),
'avatarScope' => $avatarScope,
'displayname' => $displayname,
'websiteScope' => $websiteScope,
'address' => $address,
'addressScope' => $addressScope,
- 'message' => (string)$this->l10n->t('Settings saved')
- )
- ),
+ 'message' => (string) $this->l10n->t('Settings saved')
+ ]
+ ],
Http::STATUS_OK
);
} catch (ForbiddenException $e) {
&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Forbidden')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Forbidden')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Invalid mail address')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Invalid mail address')
+ ]
+ ],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
if (!$user) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Invalid user')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Invalid user')
+ ]
+ ],
Http::STATUS_UNPROCESSABLE_ENTITY
);
}
// for the permission of setting a email address
if (!$user->canChangeDisplayName()) {
return new DataResponse(
- array(
+ [
'status' => 'error',
- 'data' => array(
- 'message' => (string)$this->l10n->t('Unable to change mail address')
- )
- ),
+ 'data' => [
+ 'message' => (string) $this->l10n->t('Unable to change mail address')
+ ]
+ ],
Http::STATUS_FORBIDDEN
);
}
try {
$this->saveUserSettings($user, $userData);
return new DataResponse(
- array(
+ [
'status' => 'success',
- 'data' => array(
+ 'data' => [
'username' => $id,
'mailAddress' => $mailAddress,
- 'message' => (string)$this->l10n->t('Email saved')
- )
- ),
+ 'message' => (string) $this->l10n->t('Email saved')
+ ]
+ ],
Http::STATUS_OK
);
} catch (ForbiddenException $e) {