]> git.wh0rd.org Git - tt-rss.git/blob - plugins/auth_imap/auth_imap.php
move authentication modules to plugins/
[tt-rss.git] / plugins / auth_imap / auth_imap.php
1 <?php
2 /* Requires php-imap
3         Put the following options in config.php:
4
5         define('IMAP_AUTH_SERVER', 'your.imap.server:port');
6         define('IMAP_AUTH_OPTIONS', '/tls/novalidate-cert/norsh');
7         // More about options: http://php.net/manual/ru/function.imap-open.php
8
9 */
10 class Auth_Imap extends Plugin implements IAuthModule {
11
12         private $link;
13         private $host;
14         private $base;
15
16         function about() {
17                 return array(1.0,
18                         "Authenticates against an IMAP server (configured in config.php)",
19                         "fox",
20                         true);
21         }
22
23         function init($host) {
24                 $this->link = $host->get_link();
25                 $this->host = $host;
26                 $this->base = new Auth_Base($this->link);
27
28                 $host->add_hook($host::HOOK_AUTH_USER, $this);
29         }
30
31         function authenticate($login, $password) {
32
33                 if ($login && $password) {
34                         $imap = imap_open(
35                                 "{".IMAP_AUTH_SERVER.IMAP_AUTH_OPTIONS."}INBOX",
36                                 $login,
37                                 $password);
38
39                         if ($imap) {
40                                 imap_close($imap);
41
42                                 return $this->base->auto_create_user($login);
43                         }
44                 }
45
46                 return false;
47         }
48
49 }
50
51 ?>