* @license BSD */ namespace Domframework; /** User authentication (abstract class) */ class Auth { /** The application name */ public $appName = null; /** Display the authentication page * The message is displayed to the user in case of error * The url is the caller url to go back if authentication is correct * @param string $baseURL The URL base to use for the links * @param string|null $message Message to display to the user * @param string|null $url URL to go back after successful authentication * @param mixed $alreadyAuth If the user is already authenticated, the value * will be displayed if the user is coming on the page. */ public function pageHTML ($baseURL, $message="", $url="", $alreadyAuth=false) { $res = ""; $res .= "\n"; $res .= "\n"; $res .= "\n"; $res .= "".dgettext ("domframework", "Sign in")."\n"; $res .= "appName !== null) $res .= "

".$this->appName."

\n"; $res .= "
\n"; $res .= " \n"; $res .= " \n"; } else { $res .= "

".dgettext ("domframework", "Already sign in"); $res .= "

\n"; if (is_string ($alreadyAuth)) { $res .= "

".dgettext ("domframework", "With login:")."

\n"; $res .= "

$alreadyAuth

\n"; } $res .= "

". dgettext ("domframework", "Logout")."\n"; if ($url !== "") $res .= "". dgettext ("domframework", "Go back to the calling page"). "\n"; $res .="

\n"; } if ($message !== "" && $message !== null) $res .= "
$message
\n"; $res .= "
\n"; $res .= "\n"; $res .= "\n"; $res .= "\n"; return $res; } /** Establish the connection to authentication server */ public function connect () { throw new \Exception (dgettext ("domframework", "No connect to authentication available"), 405); } /** Check if the email and password are correct * Return TRUE if the authentication is correct * Return an exception if there is a problem * @param string $email Email to authenticate * @param string $password Password to authenticate */ public function authentication ($email, $password) { throw new \Exception (dgettext ("domframework", "No authentication available"), 405); } /** Return all the parameters recorded for the authenticate user */ public function getdetails () { throw new \Exception (dgettext ("domframework", "No getdetails available"), 405); } /** 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", "No password change available"), 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", "No password overwrite available"), 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", "No List User available"), 405); } /** Method to disconnect the authenticated user */ public function logout () { throw new \Exception (dgettext ("domframework", "No logout method available"), 405); } }