| 1 | <?php defined('SYSPATH') or die('No direct script access.'); |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | class LDAP_Auth_Controller extends Auth_Controller { |
|---|
| 14 | |
|---|
| 15 | public function __construct() |
|---|
| 16 | { |
|---|
| 17 | parent::__construct(); |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | $this->auth = new LDAP_Auth(); |
|---|
| 21 | |
|---|
| 22 | $this->auth->host('openldap.localdomain'); |
|---|
| 23 | $this->auth->base('ou=users,dc=example,dc=com'); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | public function index() |
|---|
| 27 | { |
|---|
| 28 | echo '<h1>LDAP Auth Demo</h1>'; |
|---|
| 29 | echo '<p>Go to your login page!</p>'; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | public function login() |
|---|
| 33 | { |
|---|
| 34 | if (Session::instance()->get('user_id')) |
|---|
| 35 | { |
|---|
| 36 | $form = new Forge('auth/logout', 'Log Out'); |
|---|
| 37 | |
|---|
| 38 | $form->submit('Logout Now'); |
|---|
| 39 | } |
|---|
| 40 | else |
|---|
| 41 | { |
|---|
| 42 | $form = new Forge(NULL, 'LDAP User Login'); |
|---|
| 43 | |
|---|
| 44 | $form->input('username')->label(TRUE)->rules('required|length[4,32]'); |
|---|
| 45 | $form->password('password')->label(TRUE)->rules('required|length[4,16]'); |
|---|
| 46 | $form->submit('Attempt Login'); |
|---|
| 47 | |
|---|
| 48 | if ($form->validate()) |
|---|
| 49 | { |
|---|
| 50 | |
|---|
| 51 | if ($this->auth->login($form->username->value, $form->password->value)) |
|---|
| 52 | { |
|---|
| 53 | echo '<h4>Login Success!</h4>'; |
|---|
| 54 | return; |
|---|
| 55 | } |
|---|
| 56 | else |
|---|
| 57 | { |
|---|
| 58 | $form->password->add_error('login_failed', 'Invalid username or password.'); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | echo $form->html(); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | } |
|---|