Skip to content

Commit

Permalink
Initial Security Module v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
haitv282 committed Mar 14, 2018
1 parent 2056ede commit d1633e7
Show file tree
Hide file tree
Showing 51 changed files with 3,312 additions and 0 deletions.
137 changes: 137 additions & 0 deletions Block/Adminhtml/Dashboard/LoginLog/Grid.php
@@ -0,0 +1,137 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Security
* @copyright Copyright (c) 2018 Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Security\Block\Adminhtml\Dashboard\LoginLog;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Helper\Data;
use Mageplaza\Security\Model\ResourceModel\LoginLog\CollectionFactory;

/**
* Class Grid
* @package Mageplaza\Security\Block\Adminhtml\Dashboard\LoginLog
*/
class Grid extends \Magento\Backend\Block\Dashboard\Grid
{
/**
* @var CollectionFactory
*/
protected $_collectionFactory;

/**
* @var string
*/
protected $_template = 'Mageplaza_Security::dashboard/grid.phtml';

/**
* Grid constructor.
* @param Context $context
* @param Data $backendHelper
* @param CollectionFactory $collectionFactory
* @param array $data
*/
public function __construct(
Context $context,
Data $backendHelper,
CollectionFactory $collectionFactory,
array $data = []
)
{
$this->_collectionFactory = $collectionFactory;
parent::__construct($context, $backendHelper, $data);
}

/**
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('loginLogGrid');
}

/**
* @return $this
*/
protected function _prepareCollection()
{
$collection = $this->_collectionFactory->create()->setOrder('time', 'DESC');
$this->setCollection($collection);

return parent::_prepareCollection();
}

/**
* Prepares page sizes for dashboard grid with las 5 login log
*
* @return void
*/
protected function _preparePage()
{
$this->getCollection()
->setPageSize($this->getParam($this->getVarNameLimit(), $this->_defaultLimit));
}

/**
* @inheritdoc
*/
protected function _prepareColumns()
{
$this->addColumn('search-query', [
'header' => __('User Name'),
'sortable' => false,
'index' => 'user_name',
'default' => __('User Name')
]
);

$this->addColumn('num-result', [
'header' => __('Status'),
'type' => 'bool',
'renderer' => \Mageplaza\Security\Block\Widget\Grid\Column\Renderer\Status::class,
'sortable' => false,
'index' => 'status'
]
);

$this->addColumn('popularity', [
'header' => __('Time'),
'sortable' => false,
'renderer' => \Mageplaza\Security\Block\Widget\Grid\Column\Renderer\Time::class,
'type' => 'datetime',
'index' => 'time'
]
);

$this->setFilterVisibility(false);
$this->setPagerVisibility(false);

return parent::_prepareColumns();
}

/**
* {@inheritdoc}
*/
public function getRowUrl($row)
{
return $this->getUrl('mageplaza_security/loginlog/edit', ['id' => $row->getId()]);
}
}
42 changes: 42 additions & 0 deletions Block/Adminhtml/LoginLog.php
@@ -0,0 +1,42 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Security
* @copyright Copyright (c) 2018 Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Security\Block\Adminhtml;

use Magento\Backend\Block\Widget\Grid\Container;

/**
* Class LoginLog
* @package Mageplaza\Security\Block\Adminhtml
*/
class LoginLog extends Container
{
/**
* LoginLog constructor.
*/
protected function _construct()
{
$this->_controller = 'adminhtml_loginlog';
$this->_blockGroup = 'Mageplaza_Security';
$this->_headerText = __('Login Log');
parent::_construct();
}
}
48 changes: 48 additions & 0 deletions Block/Adminhtml/Loginlog/Edit.php
@@ -0,0 +1,48 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Security
* @copyright Copyright (c) 2018 Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Security\Block\Adminhtml\Loginlog;

use Magento\Backend\Block\Widget\Form\Container;

/**
* Class Edit
* @package Mageplaza\Security\Block\Adminhtml\Loginlog
*/
class Edit extends Container
{
/**
* Edit Form constructor.
*/
protected function _construct()
{
$this->_controller = 'adminhtml_loginlog';
$this->_blockGroup = 'Mageplaza_Security';
$this->_headerText = __('Login Log');
$this->_headerText = __('Login Log');

parent::_construct();

$this->buttonList->remove('save');
$this->buttonList->remove('reset');
$this->buttonList->remove('delete');
}
}
166 changes: 166 additions & 0 deletions Block/Adminhtml/Loginlog/Edit/Form.php
@@ -0,0 +1,166 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Security
* @copyright Copyright (c) 2018 Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Security\Block\Adminhtml\Loginlog\Edit;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Registry;
use Mageplaza\Security\Helper\Data;

/**
* Class Form
* @package Mageplaza\Security\Block\Adminhtml\Loginlog\Edit
*/
class Form extends Generic
{
/**
* @var Data
*/
protected $_helper;

/**
* Form constructor.
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Data $helper
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
FormFactory $formFactory,
Data $helper,
array $data = [])
{
$this->_helper = $helper;
parent::__construct($context, $registry, $formFactory, $data);
}

/**
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function _prepareForm()
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getData('action'),
'method' => 'post',
'enctype' => 'multipart/form-data'
]
]
);
$log = $this->_coreRegistry->registry('mageplaza_security_loginlog');

/** @var \Magento\Framework\Data\Form $form */
$form->setHtmlIdPrefix('log_');
$form->setFieldNameSuffix('log');

$fieldset = $form->addFieldset('base_fieldset', [
'legend' => __('Login information'),
'class' => 'fieldset-wide'
]
);
$fieldset->addField('id', 'label', [
'name' => 'id',
'label' => __('ID'),
]);
$fieldset->addField('time', 'label', [
'name' => 'time',
'label' => __('Time'),
'title' => __('Time'),
]
);
$fieldset->addField('user_name', 'label', [
'name' => 'user_name',
'label' => __('User Name'),
'title' => __('User Name'),
]
);
$fieldset->addField('ip', 'label', [
'name' => 'ip',
'label' => __('IP'),
'title' => __('IP'),
]
);
$fieldset->addField('url', 'label', [
'name' => 'url',
'label' => __('URL'),
'title' => __('URL'),
]
);
$fieldset->addField('referer', 'label', [
'name' => 'referer',
'label' => __('Referer URL'),
'title' => __('Referer URL'),
]
);
$fieldset->addField('stt', 'label', [
'label' => __('Status'),
'title' => __('Status'),
'value' => $log->getStatus() ? __('Success') : __('Failed')
]
);

$browserFieldset = $form->addFieldset('browser_fieldset', [
'legend' => __('Browser Information'),
'class' => 'fieldset-wide'
]
);
$userAgent = $log->getBrowserAgent();
$userAgent = explode('--', $userAgent);
$userAgent = $userAgent[1];
$browser = $this->_helper->getBrowser($userAgent, 1);

$browserFieldset->addField('browser', 'label', [
'label' => __('Brower'),
'title' => __('Brower'),
'value' => $browser['browser']
]);
$browserFieldset->addField('browser_version', 'label', [
'label' => __('Brower Version'),
'title' => __('Brower Version'),
'value' => $browser['browser_version']
]);
$browserFieldset->addField('plat_form', 'label', [
'label' => __('Platform'),
'title' => __('Platform'),
'value' => $browser['plat_form']
]);
$browserFieldset->addField('plat_form_version', 'label', [
'label' => __('Platform Version'),
'title' => __('Platform Version'),
'value' => $browser['plat_form_version']
]);

$form->addValues($log->getData());
$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();
}
}

0 comments on commit d1633e7

Please sign in to comment.