forked from wingman007/fmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fba1ad
commit 07caf66
Showing
13 changed files
with
313 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
"doctrine/doctrine-orm-module": "0.*", | ||
"doctrine/doctrine-mongo-odm-module": "dev-master" | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Auth Controller Index Action</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>I am logout.</h1> |