Skip to content

Commit

Permalink
Auth created
Browse files Browse the repository at this point in the history
  • Loading branch information
wingman007 committed Jul 16, 2013
1 parent 5fba1ad commit 07caf66
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 3 deletions.
8 changes: 8 additions & 0 deletions SabryBangirov.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World from Sabri Bangirov</p>'; ?>
</body>
</html>
8 changes: 8 additions & 0 deletions StanislavVelikoff.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World from Taffo</p>'; ?>
</body>
</html>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"doctrine/doctrine-orm-module": "0.*",
"doctrine/doctrine-mongo-odm-module": "dev-master"
}
}
}
Binary file modified composer.phar
Binary file not shown.
5 changes: 3 additions & 2 deletions config/application.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'Application',
'DoctrineModule',
'DoctrineORMModule',
'DoctrineMongoODMModule',
// 'DoctrineMongoODMModule',

'Album', //this line is added
'ZhelyanGuglev',
Expand Down Expand Up @@ -33,7 +33,8 @@
'MihailKopuscu',
'RallNic',
'KrasimirTsvetanov',
'Fmi',
'Fmi',
'Auth',
),
'module_listener_options' => array(
'config_glob_paths' => array(
Expand Down
22 changes: 22 additions & 0 deletions module/Auth/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Auth;

class Module
{

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
49 changes: 49 additions & 0 deletions module/Auth/config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
return array(
'static_salt' => 'aFGQ475SDsdfsaf2342',
'controllers' => array(
'invokables' => array(
'Auth\Controller\Index' => 'Auth\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'auth' => array(
'type' => 'Literal',
'options' => array(
'route' => '/auth',
'defaults' => array(
'__NAMESPACE__' => 'Auth\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
// 'template_map' => array(
// 'layout/Auth' => __DIR__ . '/../view/layout/Auth.phtml',
// ),
'template_path_stack' => array(
'auth' => __DIR__ . '/../view'
),

'display_exceptions' => true,
),
);
99 changes: 99 additions & 0 deletions module/Auth/src/Auth/Controller/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
namespace Auth\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

use Zend\Authentication\Result;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;

use Zend\Db\Adapter\Adapter as DbAdapter;

use Zend\Authentication\Adapter\DbTable as AuthAdapter;

use Auth\Model\Auth;
use Auth\Form\AuthForm;

class IndexController extends AbstractActionController
{
public function indexAction()
{
return new ViewModel();
}

public function loginAction()
{
$form = new AuthForm();
$form->get('submit')->setValue('Login');
$messages = null;

$request = $this->getRequest();
if ($request->isPost()) {
$authFormFilters = new Auth();
$form->setInputFilter($authFormFilters->getInputFilter());
$form->setData($request->getPost());
if ($form->isValid()) {
$data = $form->getData();
$sm = $this->getServiceLocator();
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');

$config = $this->getServiceLocator()->get('Config');
$staticSalt = $config['static_salt'];

$authAdapter = new AuthAdapter($dbAdapter,
'users',
'usr_name',
'usr_password',
"MD5(CONCAT('$staticSalt', ?, usr_password_salt)) AND usr_active = 1"
);
$authAdapter
->setIdentity($data['usr_name'])
->setCredential($data['usr_password'])
;

$auth = new AuthenticationService();

$result = $auth->authenticate($authAdapter);

switch ($result->getCode()) {
case Result::FAILURE_IDENTITY_NOT_FOUND:
// do stuff for nonexistent identity
break;

case Result::FAILURE_CREDENTIAL_INVALID:
// do stuff for invalid credential
break;

case Result::SUCCESS:
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(
null,
'usr_password'
));
break;

default:
// do stuff for other failure
break;
}
foreach ($result->getMessages() as $message) {
$messages .= "$message\n";
}
}
}
return new ViewModel(array('form' => $form, 'messages' => $messages));
}

public function logoutAction()
{
$auth = new AuthenticationService();

if ($auth->hasIdentity()) {
$identity = $auth->getIdentity();
}

$auth->clearIdentity();
return $this->redirect()->toRoute('auth/default', array('controller' => 'index', 'action' => 'login'));
}
}
41 changes: 41 additions & 0 deletions module/Auth/src/Auth/Form/AuthForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace Auth\Form;

use Zend\Form\Form;

class AuthForm extends Form
{
public function __construct($name = null)
{
parent::__construct('auth');
$this->setAttribute('method', 'post');

$this->add(array(
'name' => 'usr_name',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Username',
),
));
$this->add(array(
'name' => 'usr_password',
'attributes' => array(
'type' => 'password',
),
'options' => array(
'label' => 'Password',
),
));

$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
}
67 changes: 67 additions & 0 deletions module/Auth/src/Auth/Model/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
namespace Auth\Model;

use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class Auth implements InputFilterAwareInterface
{
protected $inputFilter;

public function setInputFilter(InputFilterInterface $inputFilter)
{
throw new \Exception("Not used");
}

public function getInputFilter()
{
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$factory = new InputFactory();

$inputFilter->add($factory->createInput(array(
'name' => 'usr_name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));

$inputFilter->add($factory->createInput(array(
'name' => 'usr_password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));

$this->inputFilter = $inputFilter;
}

return $this->inputFilter;
}
}
1 change: 1 addition & 0 deletions module/Auth/view/auth/index/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Auth Controller Index Action</h1>
13 changes: 13 additions & 0 deletions module/Auth/view/auth/index/login.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Login </h1>
<?php echo $this->escapeHtml($this->messages); ?>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url('auth/default', array('controller' => 'index', 'action' => 'login')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formRow($form->get('usr_name'));
echo $this->formRow($form->get('usr_password'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
1 change: 1 addition & 0 deletions module/Auth/view/auth/index/logout.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>I am logout.</h1>

0 comments on commit 07caf66

Please sign in to comment.