示例#1
0
 /**
  *
  * @param unknown $poIdentity
  * @param unknown $psUrlFrom
  */
 public function authentication($poAuthService, $poIdentity, $psUrlFrom = null, $poForm = null, $psType = 'onion')
 {
     $lsStatus = null;
     if ($poIdentity->getActive() == 1) {
         $laUserContext = null;
         if ($poIdentity->get('stIpContext') !== null) {
             $lsUserAgent = '*';
             if ($poIdentity->get('stUserAgent') !== null) {
                 $lsUserAgent = $poIdentity->get('stUserAgent');
             }
             $laUserContext = array($poIdentity->get('stIpContext') => array('denied' => $poIdentity->get('isContextDenied'), $lsUserAgent => $poIdentity->get('stRegistrationToken')));
         }
         if (Context::hasContextAccess($laUserContext)) {
             $loSession = new Session();
             $loSession->clearRegister('OnionAuth');
             $loSession->clearRegister('storage', 'Zend_Auth');
             $poIdentity->getObject();
             $poIdentity->set('stPassword', 'nono');
             $poIdentity->set('stPasswordSalt', '');
             $poIdentity->set('stAnswer', '');
             $loSession->setRegister('OnionAuth', $poIdentity);
             $loIdentity = $loSession->getRegister('OnionAuth');
             $poAuthService->getStorage()->write($poIdentity);
             if ($poForm->get('rememberme')->getValue() == 1) {
                 $laOptions = Config::getAppOptions('settings');
                 $loSessionManager = new SessionManager();
                 $loSessionManager->rememberMe($laOptions['sessionLifeTime']);
             }
             Debug::debug($poIdentity->getUsername() . " [SUCCESS by {$psType}]");
             Access::log($poIdentity, "SUCCESS by " . $psType);
             if ($psUrlFrom !== null) {
                 if ('/' !== $psUrlFrom) {
                     $psUrlFrom = base64_decode($psUrlFrom);
                 }
                 Debug::debug("Redirect to: ({$psUrlFrom})");
                 $this->redirect()->toUrl($psUrlFrom);
             }
         } else {
             $poForm->get('stUsername')->setMessages(array("Permissão negada para o contexto de acesso!"));
             $lsStatus = "CONTEXT DENIED";
         }
     } else {
         $poForm->get('stUsername')->setMessages(array("Usuário desativado!"));
         $lsStatus = "USER DISABLED";
     }
     return $lsStatus;
 }
示例#2
0
 * @category   PHP
 * @package    Onion
 * @author     Humberto Lourenço <*****@*****.**>
 * @copyright  2014-2016 Humberto Lourenço <*****@*****.**>
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 * @link       http://github.com/m3uzz/onionfw
 */
namespace Access;

use Onion\Application\Application;
use Onion\Log\Debug;
use Onion\Config\Config;
use Onion\Log\Access;
$gsAccessViewPath = __DIR__ . '/../view';
if (file_exists(CLIENT_DIR . '/module/Backend/view/access')) {
    $gsAccessViewPath = CLIENT_DIR . '/module/Backend/view';
}
return array('controllers' => array('invokables' => array('Access\\Controller\\Access' => 'Access\\Controller\\AccessController')), 'router' => array('routes' => array('access' => array('type' => 'segment', 'options' => array('route' => '/access[/:action][/:id][/]', 'constraints' => array('action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[a-zA-Z0-9_-]+'), 'defaults' => array('__NAMESPACE__' => 'Access\\Controller', 'controller' => 'Access', 'action' => 'login'))))), 'view_manager' => array('template_path_stack' => array('access' => $gsAccessViewPath)), 'doctrine' => array('driver' => array('access_entities' => array('class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/Access/Entity')), 'orm_default' => array('drivers' => array('Access\\Entity' => 'access_entities'))), 'authentication' => array('orm_default' => array('object_manager' => 'Doctrine\\ORM\\EntityManager', 'identity_class' => 'Access\\Entity\\AccessExtended', 'identity_property' => 'stUsername', 'credential_property' => 'stPassword', 'credential_callable' => function (Entity\Access $poUser, $psPasswordGiven) {
    $laOptions = Config::getAppOptions('settings');
    if ($laOptions['criptPassword']) {
        Debug::debug('Encriptar password true');
        $psPasswordGiven = md5($laOptions['staticSalt'] . $psPasswordGiven . $poUser->getPasswordSalt());
    }
    if ($poUser->getPassword() === $psPasswordGiven) {
        return true;
    } else {
        $lsStatus = "WRONG PASSWORD";
        Access::log($poUser, $lsStatus);
        return false;
    }
}))));
示例#3
0
 public function indexxAction()
 {
     $loEntityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $loUser = new Access();
     $loForm = new RegistrationForm();
     $loForm->get('submit')->setValue('Register');
     $loForm->setHydrator(new DoctrineHydrator($loEntityManager, 'Access\\Entity\\Access'));
     if ($this->requestIsPost()) {
         $loForm->setInputFilter(new RegistrationFilter($this->getServiceLocator()));
         $loForm->setData($this->requestPost());
         if ($loForm->isValid()) {
             $poUser->set('stPasswordSalt', String::generateDynamicSalt());
             $poUser->set('UserGroup_Id', null);
             $poUser->set('stRegistrationToken', md5(uniqid(mt_rand(), true)));
             $loUser->populate($loForm->getData());
             $this->sendConfirmationEmail($loUser);
             $this->flashMessenger()->addMessage(array('id' => $this->get('_sModule') . '-' . microtime(true), 'hidden' => $this->get('_bHiddenPushMessage'), 'push' => $this->get('_bPushMessage'), 'type' => 'success', $loUser->getEmail()));
             $loEntityManager->persist($loUser);
             $loEntityManager->flush();
         }
     }
     return new ViewModel(array('form' => $loForm));
 }