aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/User/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/User/User.php')
-rw-r--r--lib/private/User/User.php70
1 files changed, 55 insertions, 15 deletions
diff --git a/lib/private/User/User.php b/lib/private/User/User.php
index 4b1ec4366d0..1f908918b20 100644
--- a/lib/private/User/User.php
+++ b/lib/private/User/User.php
@@ -11,7 +11,6 @@ use InvalidArgumentException;
use OC\Accounts\AccountManager;
use OC\Avatar\AvatarManager;
use OC\Hooks\Emitter;
-use OC_Helper;
use OCP\Accounts\IAccountManager;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
@@ -65,8 +64,8 @@ class User implements IUser {
/** @var string */
private $home;
- /** @var int|null */
- private $lastLogin;
+ private ?int $lastLogin = null;
+ private ?int $firstLogin = null;
/** @var IAvatarManager */
private $avatarManager;
@@ -155,6 +154,7 @@ class User implements IUser {
*/
public function setSystemEMailAddress(string $mailAddress): void {
$oldMailAddress = $this->getSystemEMailAddress();
+ $mailAddress = mb_strtolower(trim($mailAddress));
if ($mailAddress === '') {
$this->config->deleteUserValue($this->uid, 'settings', 'email');
@@ -177,6 +177,7 @@ class User implements IUser {
* @inheritDoc
*/
public function setPrimaryEMailAddress(string $mailAddress): void {
+ $mailAddress = mb_strtolower(trim($mailAddress));
if ($mailAddress === '') {
$this->config->deleteUserValue($this->uid, 'settings', 'primary_email');
return;
@@ -202,28 +203,47 @@ class User implements IUser {
/**
* returns the timestamp of the user's last login or 0 if the user did never
* login
- *
- * @return int
*/
- public function getLastLogin() {
+ public function getLastLogin(): int {
if ($this->lastLogin === null) {
$this->lastLogin = (int)$this->config->getUserValue($this->uid, 'login', 'lastLogin', 0);
}
- return (int)$this->lastLogin;
+ return $this->lastLogin;
+ }
+
+ /**
+ * returns the timestamp of the user's last login or 0 if the user did never
+ * login
+ */
+ public function getFirstLogin(): int {
+ if ($this->firstLogin === null) {
+ $this->firstLogin = (int)$this->config->getUserValue($this->uid, 'login', 'firstLogin', 0);
+ }
+ return $this->firstLogin;
}
/**
* updates the timestamp of the most recent login of this user
*/
- public function updateLastLoginTimestamp() {
+ public function updateLastLoginTimestamp(): bool {
$previousLogin = $this->getLastLogin();
+ $firstLogin = $this->getFirstLogin();
$now = time();
$firstTimeLogin = $previousLogin === 0;
if ($now - $previousLogin > 60) {
- $this->lastLogin = time();
- $this->config->setUserValue(
- $this->uid, 'login', 'lastLogin', (string)$this->lastLogin);
+ $this->lastLogin = $now;
+ $this->config->setUserValue($this->uid, 'login', 'lastLogin', (string)$this->lastLogin);
+ }
+
+ if ($firstLogin === 0) {
+ if ($firstTimeLogin) {
+ $this->firstLogin = $now;
+ } else {
+ /* Unknown first login, most likely was before upgrade to Nextcloud 31 */
+ $this->firstLogin = -1;
+ }
+ $this->config->setUserValue($this->uid, 'login', 'firstLogin', (string)$this->firstLogin);
}
return $firstTimeLogin;
@@ -428,6 +448,11 @@ class User implements IUser {
return $this->backend->implementsActions(Backend::SET_DISPLAYNAME);
}
+ public function canChangeEmail(): bool {
+ // Fallback to display name value to avoid changing behavior with the new option.
+ return $this->config->getSystemValueBool('allow_user_to_change_email', $this->config->getSystemValueBool('allow_user_to_change_display_name', true));
+ }
+
/**
* check if the user is enabled
*
@@ -491,14 +516,16 @@ class User implements IUser {
* @inheritDoc
*/
public function getSystemEMailAddress(): ?string {
- return $this->config->getUserValue($this->uid, 'settings', 'email', null);
+ $email = $this->config->getUserValue($this->uid, 'settings', 'email', null);
+ return $email ? mb_strtolower(trim($email)) : null;
}
/**
* @inheritDoc
*/
public function getPrimaryEMailAddress(): ?string {
- return $this->config->getUserValue($this->uid, 'settings', 'primary_email', null);
+ $email = $this->config->getUserValue($this->uid, 'settings', 'primary_email', null);
+ return $email ? mb_strtolower(trim($email)) : null;
}
/**
@@ -535,6 +562,19 @@ class User implements IUser {
return $quota;
}
+ public function getQuotaBytes(): int|float {
+ $quota = $this->getQuota();
+ if ($quota === 'none') {
+ return \OCP\Files\FileInfo::SPACE_UNLIMITED;
+ }
+
+ $bytes = \OCP\Util::computerFileSize($quota);
+ if ($bytes === false) {
+ return \OCP\Files\FileInfo::SPACE_UNKNOWN;
+ }
+ return $bytes;
+ }
+
/**
* set the users' quota
*
@@ -546,11 +586,11 @@ class User implements IUser {
public function setQuota($quota) {
$oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', '');
if ($quota !== 'none' and $quota !== 'default') {
- $bytesQuota = OC_Helper::computerFileSize($quota);
+ $bytesQuota = \OCP\Util::computerFileSize($quota);
if ($bytesQuota === false) {
throw new InvalidArgumentException('Failed to set quota to invalid value ' . $quota);
}
- $quota = OC_Helper::humanFileSize($bytesQuota);
+ $quota = \OCP\Util::humanFileSize($bytesQuota);
}
if ($quota !== $oldQuota) {
$this->config->setUserValue($this->uid, 'files', 'quota', $quota);