Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 9c5cbe8e authored by Akhil's avatar Akhil
Browse files

Basic error handling for autologin webmail

parent 7b98753b
Loading
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ declare(strict_types=1);

namespace OCA\EcloudAccounts\Listeners;

use Exception;
use OCP\EventDispatcher\Event;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use \OCP\EventDispatcher\IEventListener;
@@ -11,6 +12,7 @@ use OCP\IUserSession;
use OCP\ISession;
use OCP\IConfig;
use OCP\IRequest;
use OCP\ILogger;
use OCP\App\IAppManager;

class BeforeTemplateRenderedListener implements IEventListener {
@@ -20,13 +22,15 @@ class BeforeTemplateRenderedListener implements IEventListener {
	private $session;
	private $config;
	private $appManager;
	private ILogger $logger;

	private const SNAPPYMAIL_APP_ID = 'snappymail';
	private const SNAPPYMAIL_URL = '/apps/snappymail/';
	private const SNAPPYMAIL_AUTOLOGIN_PWD = '1';

	public function __construct($appName, IUserSession $userSession, IRequest $request, ISession $session, IConfig $config, IAppManager $appManager) {
	public function __construct($appName, ILogger $logger, IUserSession $userSession, IRequest $request, ISession $session, IConfig $config, IAppManager $appManager) {
		$this->appName = $appName;
		$this->logger = $logger;
		$this->userSession = $userSession;
		$this->request = $request;
		$this->session = $session;
@@ -50,8 +54,8 @@ class BeforeTemplateRenderedListener implements IEventListener {
			return;
		}
		$accountId = $this->getAccountId();
		try {
			$actions = \RainLoop\Api::Actions();	
		
			if (empty($accountId) || $actions->getMainAccountFromToken(false)) {
				return;
			}
@@ -63,6 +67,10 @@ class BeforeTemplateRenderedListener implements IEventListener {
				$actions->Plugins()->RunHook('login.success', array($account));
				$actions->SetAuthToken($account);
			}
		} catch(Exception $e) {
			$this->logger->logException($e);
			return;
		}
	}

	private function getAccountId() : string {