Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* IndexController
*
* @author
* @version
*/
require_once 'Zend/Controller/Action.php';
class Auth_IndexController extends Unl_Controller_Action {
public function indexAction()
{
$this->_redirect('/auth/index/login');
}
public function loginAction()
{
$session = new Zend_Session_Namespace(__CLASS__);
$this->view->errorMessage = $session->errorMessage;
unset($session->errorMessage);
}
public function logoutAction()
{
Zend_Auth::getInstance()->clearIdentity();
$this->_redirect('');
}
public function validateAction()
{
$username = $this->getRequest()->getParam('username');
$password = $this->getRequest()->getParam('password');
$auth = Unl_Auth::getInstance();
$ldap = new Unl_Ldap('ldap://localhost:10389');
$ldapAdapter = new Unl_Auth_Adapter_Ldap($ldap, $username, $password);
$auth->pushAdapter($ldapAdapter);
try {
$result = $auth->authenticate($ldapAdapter);
} catch (Exception $e) {
//
}
if (!$result || !$result->isValid()) {
$session = new Zend_Session_Namespace(__CLASS__);
$session->errorMessage = 'Login Failed';
$this->_redirect('/auth/index');
return;
}
$this->_redirect('');
}
}