Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/BackgroundJob/ExpireUnverifiedAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\Preferred_Providers\BackgroundJob;

use OCA\Preferred_Providers\AppInfo\Application;
use OCA\Preferred_Providers\Helper\ExpireUserTrait;
use OCA\Preferred_Providers\Mailer\VerifyMailHelper;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -20,15 +21,13 @@
class ExpireUnverifiedAccounts extends TimedJob {
use ExpireUserTrait;

private string $appName = 'preferred_providers';

public function __construct(
ITimeFactory $timeFactory,
private IConfig $config,
private LoggerInterface $logger,
private IDBConnection $connection,
private VerifyMailHelper $mailHelper,
private IUserManager $userManager,
private readonly IConfig $config,
private readonly LoggerInterface $logger,
private readonly IDBConnection $connection,
private readonly VerifyMailHelper $mailHelper,
private readonly IUserManager $userManager,
) {
parent::__construct($timeFactory);

Expand All @@ -42,7 +41,7 @@ public function __construct(
#[\Override]
public function run($argument) {
// process if token is 5min old
$users = $this->getUsersForUserLowerThanValue($this->appName, 'disable_user_after', strval(time()));
$users = $this->getUsersForUserLowerThanValue(Application::APP_ID, 'disable_user_after', strval(time()));
foreach ($users as $userId) {
$this->expireUser($userId);
}
Expand Down
21 changes: 5 additions & 16 deletions lib/BackgroundJob/NotifyUnsetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Preferred_Providers\BackgroundJob;

use Exception;
use OCA\Preferred_Providers\AppInfo\Application;
use OCA\Preferred_Providers\Mailer\SetPasswordMailHelper;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
Expand All @@ -18,26 +19,14 @@

class NotifyUnsetPassword extends TimedJob {

/** @var string */
private $appName;

/** @var IDBConnection */
private $connection;

/** @var IConfig */
private $config;

public function __construct(
ITimeFactory $timeFactory,
private readonly LoggerInterface $logger,
IDBConnection $connection,
private readonly IDBConnection $connection,
private readonly SetPasswordMailHelper $mailHelper,
IConfig $config,
private readonly IConfig $config,
) {
parent::__construct($timeFactory);
$this->appName = 'preferred_providers';
$this->connection = $connection;
$this->config = $config;

// Run once per 5 minutes
$this->setInterval(5 * 60);
Expand All @@ -49,13 +38,13 @@ public function __construct(
#[\Override]
public function run($argument) {
// process if token is 5min old
$users = $this->getUsersForUserLowerThanValue($this->appName, 'remind_password', strval(time() - 5 * 60));
$users = $this->getUsersForUserLowerThanValue(Application::APP_ID, 'remind_password', strval(time() - 5 * 60));
foreach ($users as $userId) {
$emailTemplate = $this->mailHelper->generateTemplate($userId);
try {
$this->mailHelper->sendMail($userId, $emailTemplate);
// only send one mail
$this->config->deleteUserValue($userId, $this->appName, 'remind_password');
$this->config->deleteUserValue($userId, Application::APP_ID, 'remind_password');
$this->logger->debug('Password definition mail sent to ' . $userId);
} catch (Exception) {
$this->logger->debug('Error while sending the password definition mail to ' . $userId);
Expand Down
7 changes: 4 additions & 3 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\Preferred_Providers\Controller;

use OCA\Preferred_Providers\AppInfo\Application;
use OCA\Preferred_Providers\Mailer\VerifyMailHelper;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\Attribute\ApiRoute;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function __construct(
#[ApiRoute(verb: 'GET', url: '/api/v1/token/new')]
public function resetToken(): DataResponse {
$provider_token = md5($this->secureRandom->generate(10));
$this->appConfig->setValueString('preferred_providers', 'provider_token', $provider_token);
$this->appConfig->setValueString(Application::APP_ID, 'provider_token', $provider_token);

return new DataResponse(['token' => $provider_token]);
}
Expand All @@ -81,9 +82,9 @@ public function setGroups(array $groups = [], string $for = 'all'): DataResponse
}

if ($for === 'all') {
$this->appConfig->setValueString('preferred_providers', 'provider_groups', implode(',', $groups));
$this->appConfig->setValueString(Application::APP_ID, 'provider_groups', implode(',', $groups));
} elseif ($for === 'confirmed' || $for === 'unconfirmed') {
$this->appConfig->setValueString('preferred_providers', 'provider_groups_' . $for, implode(',', $groups));
$this->appConfig->setValueString(Application::APP_ID, 'provider_groups_' . $for, implode(',', $groups));
} else {
throw new OCSBadRequestException();
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Helper/ExpireUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\Preferred_Providers\Helper;

use Exception;
use OCA\Preferred_Providers\AppInfo\Application;

trait ExpireUserTrait {

Expand All @@ -29,7 +30,7 @@ private function expireUser(string $userId) {
$user->setEnabled(false);

// removing token to avoid conflict with further manual manipulation of the user
$this->config->deleteUserValue($userId, $this->appName, 'disable_user_after');
$this->config->deleteUserValue($userId, Application::APP_ID, 'disable_user_after');
$this->logger->info('User ' . $userId . ' failed to verify email in time and has been disabled');

// send email
Expand All @@ -38,7 +39,7 @@ private function expireUser(string $userId) {
try {
$this->mailHelper->sendMail($user, $emailTemplate);
// only send one mail
$this->config->deleteUserValue($userId, $this->appName, 'remind_password');
$this->config->deleteUserValue($userId, Application::APP_ID, 'remind_password');
$this->logger->debug('Unverified warning mail sent to ' . $userId);
} catch (Exception) {
$this->logger->error('Error while sending the failed to verify warning mail to ' . $userId);
Expand Down
3 changes: 2 additions & 1 deletion lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\Preferred_Providers\Settings;

use OCA\Preferred_Providers\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function getForm() {
*/
#[\Override]
public function getSection() {
return 'preferred_providers';
return Application::APP_ID;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/Settings/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\Preferred_Providers\Settings;

use OCA\Preferred_Providers\AppInfo\Application;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIconSection;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function __construct(IURLGenerator $url, IL10N $l) {
*/
#[\Override]
public function getID() {
return 'preferred_providers';
return Application::APP_ID;
}

/**
Expand Down Expand Up @@ -66,6 +67,6 @@ public function getPriority() {
*/
#[\Override]
public function getIcon() {
return $this->url->imagePath('preferred_providers', 'app-dark.svg');
return $this->url->imagePath(Application::APP_ID, 'app-dark.svg');
}
}
4 changes: 2 additions & 2 deletions templates/flow-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

\OCP\Util::addScript('preferred_providers', 'flow-login');
\OCP\Util::addStyle('preferred_providers', 'password-public');
\OCP\Util::addScript(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'flow-login');
\OCP\Util::addStyle(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'password-public');

?>
<div class="guest-box login-box" id="flow-login"
Expand Down
4 changes: 2 additions & 2 deletions templates/password-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

\OCP\Util::addScript('preferred_providers', 'password-public');
\OCP\Util::addStyle('preferred_providers', 'password-public');
\OCP\Util::addScript(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'password-public');
\OCP\Util::addStyle(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'password-public');

?>
<div class="guest-box login-box">
Expand Down
4 changes: 2 additions & 2 deletions templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

\OCP\Util::addScript('preferred_providers', 'admin-settings');
\OCP\Util::addStyle('preferred_providers', 'admin-settings');
\OCP\Util::addScript(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'admin-settings');
\OCP\Util::addStyle(\OCA\Preferred_Providers\AppInfo\Application::APP_ID, 'admin-settings');
?>

<div id="token-section" class="section">
Expand Down
Loading