mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-11-01 01:53:32 +03:00
Added NextCloud
Taken from https://github.com/pierre-alain-b/snappymail-nextcloud
This commit is contained in:
parent
2dde6c59eb
commit
65200af210
32 changed files with 1713 additions and 1 deletions
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SnappyMail\Controller;
|
||||
|
||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
||||
class AjaxController extends Controller {
|
||||
private $config;
|
||||
private $appManager;
|
||||
|
||||
public function __construct(string $appName, IRequest $request, IAppManager $appManager, IConfig $config, IL10N $l) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $config;
|
||||
$this->appManager = $appManager;
|
||||
$this->l = $l;
|
||||
}
|
||||
|
||||
public function setAdmin(): JSONResponse {
|
||||
try {
|
||||
$sUrl = '';
|
||||
$sPath = '';
|
||||
$bAutologin = false;
|
||||
|
||||
if (isset($_POST['appname']) && 'snappymail' === $_POST['appname']) {
|
||||
$this->config->setAppValue('snappymail', 'snappymail-autologin',
|
||||
isset($_POST['snappymail-autologin']) ? '1' === $_POST['snappymail-autologin'] : false);
|
||||
$this->config->setAppValue('snappymail', 'snappymail-autologin-with-email',
|
||||
isset($_POST['snappymail-autologin']) ? '2' === $_POST['snappymail-autologin'] : false);
|
||||
$bAutologin = $this->config->getAppValue('snappymail', 'snappymail-autologin', false);
|
||||
} else {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $this->l->t('Invalid argument(s)')
|
||||
]);
|
||||
}
|
||||
|
||||
return new JSONResponse([
|
||||
'status' => 'success',
|
||||
'Message' => $this->l->t('Saved successfully')
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function setPersonal(): JSONResponse {
|
||||
try {
|
||||
|
||||
if (isset($_POST['appname'], $_POST['snappymail-password'], $_POST['snappymail-email']) && 'snappymail' === $_POST['appname']) {
|
||||
$sUser = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
|
||||
$sPostEmail = $_POST['snappymail-email'];
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sPostEmail);
|
||||
|
||||
$sPass = $_POST['snappymail-password'];
|
||||
if ('******' !== $sPass && '' !== $sPass) {
|
||||
include_once $this->appManager->getAppPath('snappymail').'/lib/Util/SnappyMailHelper.php';
|
||||
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-password',
|
||||
SnappyMailHelper::encodePassword($sPass, md5($sPostEmail)));
|
||||
}
|
||||
|
||||
$sEmail = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-email', '');
|
||||
} else {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $this->l->t('Invalid argument(s)'),
|
||||
'Email' => $sEmail
|
||||
]);
|
||||
}
|
||||
|
||||
return new JSONResponse([
|
||||
'status' => 'success',
|
||||
'Message' => $this->l->t('Saved successfully'),
|
||||
'Email' => $sEmail
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
return new JSONResponse([
|
||||
'status' => 'error',
|
||||
'Message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SnappyMail\Controller;
|
||||
|
||||
use OCA\SnappyMail\Util\SnappyMailHelper;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use OCP\ISession;
|
||||
|
||||
class PageController extends Controller {
|
||||
private $userId;
|
||||
private $config;
|
||||
private $appManager;
|
||||
private $appPath;
|
||||
private $session;
|
||||
|
||||
public function __construct($AppName, IRequest $request, IAppManager $appManager, IConfig $config, ISession $session) {
|
||||
parent::__construct($AppName, $request);
|
||||
$this->appPath = $appManager->getAppPath('snappymail');
|
||||
$this->config = $config;
|
||||
$this->appManager = $appManager;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
\OC::$server->getNavigationManager()->setActiveEntry('snappymail');
|
||||
|
||||
\OCP\Util::addStyle('snappymail', 'style');
|
||||
|
||||
$sUrl = SnappyMailHelper::normalizeUrl(SnappyMailHelper::getAppUrl());
|
||||
|
||||
$params = [
|
||||
'snappymail-iframe-url' => SnappyMailHelper::normalizeUrl($sUrl).'?OwnCloudAuth'
|
||||
];
|
||||
|
||||
$response = new TemplateResponse('snappymail', 'index', $params);
|
||||
|
||||
$csp = new ContentSecurityPolicy();
|
||||
$csp->addAllowedFrameDomain("'self'");
|
||||
$response->setContentSecurityPolicy($csp);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function appGet() {
|
||||
$this->app();
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function appPost() {
|
||||
$this->app();
|
||||
}
|
||||
|
||||
public function app() {
|
||||
|
||||
SnappyMailHelper::regSnappyMailDataFunction();
|
||||
|
||||
if (isset($_GET['OwnCloudAuth'])) {
|
||||
$sEmail = '';
|
||||
$sEncodedPassword = '';
|
||||
|
||||
$sUser = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
|
||||
if ($this->config->getAppValue('snappymail', 'snappymail-autologin', false)) {
|
||||
$sEmail = $sUser;
|
||||
$sPasswordSalt = $sUser;
|
||||
$sEncodedPassword = $this->session['snappymail-autologin-password'];
|
||||
} else if ($this->config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||
$sEmail = $this->config->getUserValue($sUser, 'settings', 'email', '');
|
||||
$sPasswordSalt = $sUser;
|
||||
$sEncodedPassword = $this->session['snappymail-autologin-password'];
|
||||
}
|
||||
|
||||
// If the user has set credentials for SnappyMail in their personal
|
||||
// settings, override everything before and use those instead.
|
||||
$sIndividualEmail = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-email', '');
|
||||
if ($sIndividualEmail) {
|
||||
$sEmail = $sIndividualEmail;
|
||||
$sPasswordSalt = $sEmail;
|
||||
$sEncodedPassword = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-password', '');
|
||||
}
|
||||
|
||||
$sDecodedPassword = SnappyMailHelper::decodePassword($sEncodedPassword, md5($sPasswordSalt));
|
||||
|
||||
$_ENV['___snappymail_owncloud_email'] = $sEmail;
|
||||
$_ENV['___snappymail_owncloud_password'] = $sDecodedPassword;
|
||||
}
|
||||
|
||||
include $this->appPath . '/app/index.php';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue