Skip to content

Commit

Permalink
* [ADD] Add Public Link notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxsmin committed Jan 12, 2017
1 parent 64efdd7 commit 75e6be4
Show file tree
Hide file tree
Showing 11 changed files with 1,269 additions and 1,010 deletions.
21 changes: 15 additions & 6 deletions inc/Plugins/Authenticator/LoginController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use SP\Controller\ControllerBase;
use SP\Core\Init;
use SP\Core\Messages\NoticeMessage;
use SP\Core\Plugin\PluginBase;
use SP\Core\Session as CoreSession;
use SP\DataModel\NoticeData;
Expand Down Expand Up @@ -110,10 +111,7 @@ protected function checkExpireTime()
return;
}

$NoticeData = new NoticeData();
$NoticeData->setNoticeComponent($this->Plugin->getName());
$NoticeData->setNoticeUserId($userId);
$NoticeData->setNoticeType(_t('authenticator', 'Aviso Caducidad'));


if (count(Notice::getItem($NoticeData)->getByUserCurrentDate()) > 0) {
return;
Expand All @@ -122,12 +120,23 @@ protected function checkExpireTime()
$expireTime = $data[$userId]->getDate() + ($data[$userId]->getExpireDays() * 86400);
$timeRemaining = $expireTime - time();

$NoticeData = new NoticeData();
$NoticeData->setNoticeComponent($this->Plugin->getName());
$NoticeData->setNoticeUserId($userId);
$NoticeData->setNoticeType(_t('authenticator', 'Aviso Caducidad'));

$Message = new NoticeMessage();

if ($timeRemaining <= self::WARNING_TIME) {
$NoticeData->setNoticeDescription(sprintf(_t('authenticator', 'El código 2FA se ha de restablecer en %d días'), $timeRemaining / 86400));
$Message->addDescription(sprintf(_t('authenticator', 'El código 2FA se ha de restablecer en %d días'), $timeRemaining / 86400));

$NoticeData->setNoticeDescription($Message);

Notice::getItem($NoticeData)->add();
} elseif (time() > $expireTime) {
$NoticeData->setNoticeDescription(_t('authenticator', 'El código 2FA ha caducado. Es necesario restablecerlo desde las preferencias'));
$Message->addDescription(_t('authenticator', 'El código 2FA ha caducado. Es necesario restablecerlo desde las preferencias'));

$NoticeData->setNoticeDescription($Message);

Notice::getItem($NoticeData)->add();
}
Expand Down
1 change: 1 addition & 0 deletions inc/SP/Controller/AccountController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ public function getRequestAccountAccess()
*
* @param PublicLinkData $PublicLinkData
* @return bool
*
*/
public function getAccountFromLink(PublicLinkData $PublicLinkData)
{
Expand Down
46 changes: 34 additions & 12 deletions inc/SP/Controller/MainController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
Expand Down Expand Up @@ -33,10 +33,12 @@
use SP\Core\Exceptions\SPException;
use SP\Core\Init;
use SP\Core\Language;
use SP\Core\Messages\NoticeMessage;
use SP\Core\Plugin\PluginUtil;
use SP\Core\Session;
use SP\Core\SessionUtil;
use SP\Core\Template;
use SP\DataModel\NoticeData;
use SP\Html\DataGrid\DataGridAction;
use SP\Html\Html;
use SP\Http\Request;
Expand Down Expand Up @@ -72,6 +74,16 @@ public function __construct(Template $template = null, $page = '', $initialize =
}
}

/**
* Establecer la variable de página de la vista
*
* @param $page
*/
protected function setPage($page)
{
$this->view->assign('page', $page);
}

/**
* Inicializar las variables para la vista principal de la aplicación
*
Expand Down Expand Up @@ -478,6 +490,8 @@ public function getPassReset()
* Obtener la vista para mostrar un enlace publicado
*
* @return bool
* @throws \SP\Core\Exceptions\FileNotFoundException
* @throws \SP\Core\Exceptions\InvalidClassException
* @throws \SP\Core\Exceptions\SPException
*/
public function getPublicLink()
Expand All @@ -499,6 +513,24 @@ public function getPublicLink()
} else {
PublicLink::getItem($PublicLink)->addLinkView();

if ($PublicLink->isNotify()) {
$Message = new NoticeMessage();
$Message->setTitle(_('Enlace visualizado'));
$Message->addDescription(sprintf('%s : %s', _('Cuenta'), $PublicLink->getItemId()));
$Message->addDescription(sprintf('%s : %s', _('Origen'), $_SERVER['REMOTE_ADDR']));
$Message->addDescription(sprintf('%s : %s', _('Agente'), $_SERVER['HTTP_USER_AGENT']));
$Message->addDescription(sprintf('HTTPS : %s', $_SERVER['HTTPS'] ? 'ON' : 'OFF'));


$NoticeData = new NoticeData();
$NoticeData->setNoticeComponent(_('Cuentas'));
$NoticeData->setNoticeDescription($Message);
$NoticeData->setNoticeType(_('Información'));
$NoticeData->setNoticeUserId($PublicLink->getUserId());

Notice::getItem($NoticeData)->add();
}

$controller = new AccountController($this->view, $PublicLink->getItemId());
$controller->getAccountFromLink($PublicLink);
}
Expand All @@ -514,14 +546,4 @@ public function getPublicLink()
$this->view();
exit();
}

/**
* Establecer la variable de página de la vista
*
* @param $page
*/
protected function setPage($page)
{
$this->view->assign('page', $page);
}
}
102 changes: 102 additions & 0 deletions inc/SP/Core/Messages/MessageBase.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/

namespace SP\Core\Messages;

/**
* Class MessageBase
*
* @package SP\Core\Messages
*/
abstract class MessageBase implements MessageInterface
{
/**
* @var string
*/
protected $title;
/**
* @var string
*/
protected $footer;
/**
* @var array
*/
protected $description = [];

/**
* @return string
*/
public function getTitle()
{
return $this->title;
}

/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}

/**
* @return array
*/
public function getDescription()
{
return $this->description;
}

/**
* @param array $description
*/
public function setDescription(array $description)
{
$this->description = $description;
}

/**
* @param string $description
*/
public function addDescription($description)
{
$this->description[] = $description;
}

/**
* @return string
*/
public function getFooter()
{
return $this->footer;
}

/**
* @param string $footer
*/
public function setFooter($footer)
{
$this->footer = $footer;
}
}
47 changes: 47 additions & 0 deletions inc/SP/Core/Messages/MessageInterface.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/

namespace SP\Core\Messages;

/**
* Interface MessageInterface
*
* @package SP\Core\Messages
*/
interface MessageInterface
{
/**
* Componer un mensaje en formato texto
*
* @return string
*/
public function composeText();

/**
* Componer un mensaje en formato HTML
*
* @return mixed
*/
public function composeHtml();
}
63 changes: 63 additions & 0 deletions inc/SP/Core/Messages/NoticeMessage.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2017, Rubén Domínguez nuxsmin@$syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/

namespace SP\Core\Messages;

/**
* Class NoticeMessage
*
* @package SP\Core\Messages
*/
class NoticeMessage extends MessageBase
{
/**
* Componer un mensaje en formato HTML
*
* @return string
*/
public function composeHtml()
{
$message[] = '<div class="notice-message">';
$message[] = '<h1>' . $this->title . '</h1>';
$message[] = '<p>' . implode('<br>', $this->description) . '</p>';
$message[] = '<footer>' . $this->footer . '</footer>';
$message[] = '</div>';

return implode($message);
}

/**
* Componer un mensaje en formato texto
*
* @return string
*/
public function composeText()
{
$message[] = $this->title;
$message[] = implode(PHP_EOL, $this->description);
$message[] = $this->footer;

return implode(PHP_EOL, $message);
}
}
8 changes: 5 additions & 3 deletions inc/SP/DataModel/NoticeData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace SP\DataModel;

use SP\Core\Messages\MessageInterface;

/**
* Class NoticeData
*
Expand Down Expand Up @@ -125,11 +127,11 @@ public function getNoticeDescription()
}

/**
* @param string $notice_description
* @param MessageInterface $message
*/
public function setNoticeDescription($notice_description)
public function setNoticeDescription(MessageInterface $message)
{
$this->notice_description = $notice_description;
$this->notice_description = $message->composeText();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion inc/SP/DataModel/PublicLinkData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function setTypeId($typeId)
*/
public function isNotify()
{
return $this->notify;
return (bool)$this->notify;
}

/**
Expand Down
Loading

0 comments on commit 75e6be4

Please sign in to comment.