IMAP Authentication, where to put the code?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
zimmerlis
User
Posts: 9

IMAP Authentication, where to put the code?

Post by zimmerlis »

Hello

I use the security option "Use Existing Table", this works fine, so I can setup the securtity level for each user. All User are in the table available.
Now I whant to have a single sign on for the user, because they are already registered on my Synology NAS, where also the web application runs.
The User have alread a registration on the synology and can also change and set the password there.

On Wordpress I use a PlugIn IMAP Authentication, because the NAS does have a mail server and an mail account for each user.
So I used the example code from the code repository under "Code -> Server Events -> Other -> Login Page"

// User Logging In event
function User_LoggingIn($usr, &$pwd) {
if (!function_exists("imap_open")) die("PHP IMAP extension not installed.");
// IMAP authentication example for User_CustomValidate server event
$mailboxStream = imap_open("{127.0.0.1:993/imap/ssl/novalidate-cert}",$usr,$pwd,0,1);
if ($mailboxStream) {
imap_close($mailboxStream);
$this->setCurrentUserName($usr); // Set the current user name
return TRUE;
}
}

But this login does not work as an authentication replacement, it is additional to the PHP Maker Table Authentication.

If I use the password from the Table, I receive the message:
Login cancelled

If I use the password from the IMAP Server, I receive the message:
Fatal error: Call to undefined method clogin::setCurrentUserName() in /volume1/web/access/login.php on line 454

I have also tested to use this code to set the user:

// User Logging In event
function User_LoggingIn($usr, &$pwd) {
if (!function_exists("imap_open")) die("PHP IMAP extension not installed.");
// IMAP authentication example for User_CustomValidate server event
$mailboxStream = imap_open("{127.0.0.1:993/imap/ssl/novalidate-cert}",$usr,$pwd,0,1);
if ($mailboxStream) {
imap_close($mailboxStream);
//$this->setCurrentUserName($usr); // Set the current user name
$_SESSION[EW_SESSION_USER_NAME] = $usr;
return TRUE;
}
}

Then if I login with the password of the IMAP Server, I get:
Incorrect user ID or password


mobhar
User
Posts: 11731

Post by mobhar »

You should use "User_CustomValidate" instead of "User_LoggingIn" server event to validate your IMAP authentication.

In addition, you may simply use "setCurrentUserName" method that belongs to "Security" class in "User_CustomValidate" since it is a security class member.

Read "Server Events and Client Scripts" in PHPMaker help file for more information and example.


zimmerlis
User
Posts: 9

Post by zimmerlis »

This has worked now:

// User Custom Validate event
function User_CustomValidate(&$usr, &$pwd) {

if (!function_exists("imap_open")) die("PHP IMAP extension not installed.");
// IMAP authentication example for User_CustomValidate server event
$mailboxStream = imap_open("{127.0.0.1:993/imap/ssl/novalidate-cert}",$usr,$pwd,0,1);
if ($mailboxStream) {
	imap_close($mailboxStream);
	$this->setCurrentUserName($usr); // Set the current user name 
	return true;
} else {
	return false;
}

}

Thanks!


Post Reply