Merge pull request #273 from mporcheron/master

Automatic login with ownCloud user credentials
This commit is contained in:
RainLoop Team 2014-08-11 00:06:22 +04:00
commit 7d030583c5
21 changed files with 259 additions and 152 deletions

0
build/owncloud/rainloop-app/INSTALL Normal file → Executable file
View file

2
build/owncloud/rainloop-app/VERSION Normal file → Executable file
View file

@ -1 +1 @@
0.0 2.0

View file

@ -16,4 +16,5 @@ OCP\Util::addScript('rainloop', 'admin');
$oTemplate = new OCP\Template('rainloop', 'admin'); $oTemplate = new OCP\Template('rainloop', 'admin');
$oTemplate->assign('rainloop-url', OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); $oTemplate->assign('rainloop-url', OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$oTemplate->assign('rainloop-path', OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); $oTemplate->assign('rainloop-path', OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
$oTemplate->assign('rainloop-autologin', OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false));
return $oTemplate->fetchPage(); return $oTemplate->fetchPage();

View file

@ -15,14 +15,17 @@ OCP\JSON::callCheck();
$sUrl = ''; $sUrl = '';
$sPath = ''; $sPath = '';
$bAutologin = false;
if (isset($_POST['appname'], $_POST['rainloop-url'], $_POST['rainloop-path']) && 'rainloop' === $_POST['appname']) if (isset($_POST['appname'], $_POST['rainloop-url'], $_POST['rainloop-path']) && 'rainloop' === $_POST['appname'])
{ {
OCP\Config::setAppValue('rainloop', 'rainloop-url', $_POST['rainloop-url']); OCP\Config::setAppValue('rainloop', 'rainloop-url', $_POST['rainloop-url']);
OCP\Config::setAppValue('rainloop', 'rainloop-path', $_POST['rainloop-path']); OCP\Config::setAppValue('rainloop', 'rainloop-path', $_POST['rainloop-path']);
OCP\Config::setAppValue('rainloop', 'rainloop-autologin', $_POST['rainloop-autologin']);
$sUrl = OCP\Config::getAppValue('rainloop', 'rainloop-url', ''); $sUrl = OCP\Config::getAppValue('rainloop', 'rainloop-url', '');
$sPath = OCP\Config::getAppValue('rainloop', 'rainloop-path', ''); $sPath = OCP\Config::getAppValue('rainloop', 'rainloop-path', '');
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
} }
else else
{ {

0
build/owncloud/rainloop-app/ajax/personal.php Normal file → Executable file
View file

View file

@ -9,9 +9,19 @@
* https://github.com/RainLoop/owncloud * https://github.com/RainLoop/owncloud
*/ */
OC::$CLASSPATH['OC_RainLoop_Helper'] = OC_App::getAppPath('rainloop') . '/lib/RainLoopHelper.php';
OCP\App::registerAdmin('rainloop', 'admin'); OCP\App::registerAdmin('rainloop', 'admin');
OCP\App::registerPersonal('rainloop', 'personal'); OCP\App::registerPersonal('rainloop', 'personal');
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
if ('on' === $bAutologin)
{
OCP\Util::connectHook('OC_User', 'post_login', 'OC_RainLoop_Helper', 'login');
OCP\Util::connectHook('OC_User', 'logout', 'OC_RainLoop_Helper', 'logout');
OCP\Util::connectHook('OC_User', 'post_setPassword', 'OC_RainLoop_Helper', 'changePassword');
}
OCP\Util::addScript('rainloop', 'rainloop'); OCP\Util::addScript('rainloop', 'rainloop');
OCP\App::addNavigationEntry(array( OCP\App::addNavigationEntry(array(
@ -19,5 +29,5 @@ OCP\App::addNavigationEntry(array(
'order' => 10, 'order' => 10,
'href' => OCP\Util::linkTo('rainloop', 'index.php'), 'href' => OCP\Util::linkTo('rainloop', 'index.php'),
'icon' => OCP\Util::imagePath('rainloop', 'mail.png'), 'icon' => OCP\Util::imagePath('rainloop', 'mail.png'),
'name' => 'RainLoop' 'name' => 'Email'
)); ));

2
build/owncloud/rainloop-app/appinfo/info.xml Normal file → Executable file
View file

@ -3,7 +3,7 @@
<id>rainloop</id> <id>rainloop</id>
<name>RainLoop</name> <name>RainLoop</name>
<description>RainLoop Webmail</description> <description>RainLoop Webmail</description>
<version>0.0</version> <version>2.0</version>
<licence>CC BY-NC-SA 3.0</licence> <licence>CC BY-NC-SA 3.0</licence>
<author>RainLoop Team</author> <author>RainLoop Team</author>
<require>6.0</require> <require>6.0</require>

0
build/owncloud/rainloop-app/img/logo-64x64.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 832 B

Before After
Before After

0
build/owncloud/rainloop-app/img/mail.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 478 B

After

Width:  |  Height:  |  Size: 478 B

Before After
Before After

View file

@ -15,6 +15,8 @@ OCP\App::setActiveNavigationEntry('rainloop_index');
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
if ('' === $sUrl || '' === $sPath) if ('' === $sUrl || '' === $sPath)
{ {
@ -22,18 +24,28 @@ if ('' === $sUrl || '' === $sPath)
} }
else else
{ {
include_once OC_App::getAppPath('rainloop').'/lib/RainLoopHelper.php';
OC_Config::setValue('xframe_restriction', false); OC_Config::setValue('xframe_restriction', false);
$sUser = OCP\User::getUser(); $sUser = OCP\User::getUser();
$sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', ''); if ($bAutologin)
{
$sEmail = $sUser;
}
else
{
$sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', '');
}
$sPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', ''); $sPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', '');
include_once OC_App::getAppPath('rainloop').'/lib/RainLoopHelper.php';
$sPassword = OC_RainLoop_Helper::decodePassword($sPassword, md5($sEmail)); $sPassword = OC_RainLoop_Helper::decodePassword($sPassword, md5($sEmail));
$sSsoHash = OC_RainLoop_Helper::getSsoHash($sPath, $sEmail, $sPassword); $sSsoHash = OC_RainLoop_Helper::getSsoHash($sPath, $sEmail, $sPassword);
OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-ssohash', $sSsoHash);
$sUrl = OC_RainLoop_Helper::normalizeUrl($sUrl); $sUrl = OC_RainLoop_Helper::normalizeUrl($sUrl);
$sResultUrl = empty($sSsoHash) ? $sUrl.'?sso' : $sUrl.'?sso&hash='.$sSsoHash; $sResultUrl = empty($sSsoHash) ? $sUrl.'?sso' : $sUrl.'?sso&hash='.$sSsoHash;

0
build/owncloud/rainloop-app/js/admin.js Normal file → Executable file
View file

0
build/owncloud/rainloop-app/js/personal.js Normal file → Executable file
View file

0
build/owncloud/rainloop-app/js/rainloop.js Normal file → Executable file
View file

0
build/owncloud/rainloop-app/js/resize.js Normal file → Executable file
View file

View file

@ -28,6 +28,30 @@ class OC_RainLoop_Helper
return $SsoHash; return $SsoHash;
} }
/**
* @param string $sSsoHash
*
* @return boolean
*/
public static function clearUserSsoHash($sSsoHash)
{
$result = false;
$sPath = rtrim(trim($sPath), '\\/').'/index.php';
if (file_exists($sPath))
{
$_ENV['RAINLOOP_INCLUDE_AS_API'] = true;
include $sPath;
if (class_exists('\\RainLoop\\Api'))
{
$result = \RainLoop\Api::ClearUserSsoHash($sSsoHash);
}
}
return $result;
}
/** /**
* @param string $sUrl * @param string $sUrl
* *
@ -67,4 +91,57 @@ class OC_RainLoop_Helper
return @base64_decode(trim($sPassword)); return @base64_decode(trim($sPassword));
} }
public static function login($params)
{
$sUser = $params['uid'];
$sEmail = $sUser;
$sPassword = $params['password'];
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
if ('' !== $sUrl && '' !== $sPath)
{
$sPassword = self::encodePassword($sPassword, md5($sEmail));
return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword);
}
return false;
}
public static function logout($params)
{
$sUser = OCP\User::getUser();
$sSsoHash = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-ssohash', '');
$a = OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', null);
$b = OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-ssohash', null);
if('' !== $sSsoHash) {
self::clearUserSsoHash($sSsoHash);
}
return $a && $b;
}
public static function changePassword($params)
{
$sUser = $params['uid'];
$sEmail = $sUser;
$sPassword = $params['password'];
OCP\Util::writeLog('rainloop', 'rainloop|login: Setting new RainLoop password for '. $sEmail, OCP\Util::DEBUG);
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
if ('' !== $sUrl && '' !== $sPath)
{
$sPassword = self::encodePassword($sPassword, md5($sEmail));
return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword);
}
return false;
}
} }

View file

@ -16,8 +16,9 @@ OCP\Util::addScript('rainloop', 'personal');
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', '')); $sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', '')); $sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
if ('' === $sUrl || '' === $sPath) if ('on' === $bAutologin || '' === $sUrl || '' === $sPath)
{ {
$oTemplate = new OCP\Template('rainloop', 'empty'); $oTemplate = new OCP\Template('rainloop', 'empty');
} }

View file

@ -17,6 +17,9 @@
<input type="text" style="width:300px;" id="rainloop-path" name="rainloop-path" value="<?php echo $_['rainloop-path']; ?>" /> <input type="text" style="width:300px;" id="rainloop-path" name="rainloop-path" value="<?php echo $_['rainloop-path']; ?>" />
<br /> <br />
<br /> <br />
<input type="checkbox" id="rainloop-autologin" name="rainloop-autologin" <?php if(true == $_['rainloop-autologin']): ?>checked="checked"<?php endif; ?> /><?php p($l->t('Automatically login with ownCloud user credentials')); ?>
<br />
<br />
<input type="button" id="rainloop-save-button" name="rainloop-save-button" value="<?php p($l->t('Save')); ?>" /> <input type="button" id="rainloop-save-button" name="rainloop-save-button" value="<?php p($l->t('Save')); ?>" />
&nbsp;&nbsp;<span class="rainloop-result-desc"></span> &nbsp;&nbsp;<span class="rainloop-result-desc"></span>
</p> </p>

0
build/owncloud/rainloop-app/templates/empty.php Normal file → Executable file
View file

0
build/owncloud/rainloop-app/templates/index-empty.php Normal file → Executable file
View file

0
build/owncloud/rainloop-app/templates/index.php Normal file → Executable file
View file