91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
/** DomFramework
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
//namespace Domframework;
|
|
|
|
require_once ("domframework/auth.php");
|
|
require_once ("domframework/imap.php");
|
|
|
|
/** User authentication against IMAP server */
|
|
class authimap extends auth
|
|
{
|
|
/** IMAP server */
|
|
public $imapServer = "localhost";
|
|
/** IMAP TCP port (143 by default) */
|
|
public $imapPort = 143;
|
|
/** IMAP SSL connection */
|
|
public $imapSSL = false;
|
|
/** IMAP SSL CheckCertificate */
|
|
public $imapSSLCheckCertificates = true;
|
|
|
|
/** The details available after authentication */
|
|
private $details = null;
|
|
|
|
/** Check the availablity of the IMAP support in PHP */
|
|
function __construct ()
|
|
{
|
|
if (!function_exists ("imap_open"))
|
|
throw new Exception ("IMAP support unavailable in PHP", 500);
|
|
}
|
|
|
|
/** Establish the connection to IMAP server. Don't do anything as the
|
|
needed parameters are username and password */
|
|
public function connect ()
|
|
{
|
|
// Nothing to do
|
|
}
|
|
|
|
/** Try to authenticate the email/password of the user
|
|
@param string $email Email to authenticate
|
|
@param string $password Password to authenticate */
|
|
public function authentication ($email, $password)
|
|
{
|
|
$imap = new imap ($this->imapServer, $this->imapPort,
|
|
$email, $password,
|
|
$this->imapSSL, $this->imapSSLCheckCertificates);
|
|
$this->details = array ("email" => $email);
|
|
// Let the throw Exception be catched by the parent
|
|
return true;
|
|
}
|
|
|
|
/** Return all the parameters recorded for the authenticate user */
|
|
public function getdetails ()
|
|
{
|
|
return $this->details;
|
|
}
|
|
|
|
/** Method to change the password
|
|
@param string $oldpassword The old password (to check if the user have the
|
|
rights to change the password)
|
|
@param string $newpassword The new password to be recorded */
|
|
public function changepassword ($oldpassword, $newpassword)
|
|
{
|
|
throw new Exception (dgettext ("domframework",
|
|
"The password can't be change for IMAP users"), 405);
|
|
}
|
|
|
|
/** Method to overwrite the password (without oldpassword check)
|
|
Must be reserved to the administrators. For the users, use changepassword
|
|
method
|
|
@param string $email the user identifier to select
|
|
@param string $newpassword The new password to be recorded */
|
|
public function overwritepassword ($email, $newpassword)
|
|
{
|
|
throw new exception (dgettext ("domframework",
|
|
"The password can't be overwrite for IMAP users"),
|
|
405);
|
|
}
|
|
|
|
/** List all the users available in the database
|
|
Return firstname, lastname, mail, with mail is an array */
|
|
public function listusers ()
|
|
{
|
|
throw new Exception (dgettext ("domframework",
|
|
"Can't get list of users for IMAP server"), 405);
|
|
}
|
|
}
|