Files
DomFramework/auth.php

134 lines
5.4 KiB
PHP

<?php
/** DomFramework
@package domframework
@author Dominique Fournier <dominique@fournier38.fr> */
/** User authentication (abstract class) */
class auth
{
/** 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|null $message Message to display to the user
@param string|null $url URL to go back after successful authentication */
public function pageHTML ($baseURL, $message="", $url="")
{
$res = "";
$res .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"";
$res .= " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$res .= "<html>\n";
$res .= "<head>\n";
$res .= "<title>".dgettext("domframework", "Sign in")."</title>\n";
$res .= "<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'";
$res .= " />\n";
$res .= "<script type='text/javascript' src='$baseURL".
"/public/js/jquery.min.js'>";
$res .= "</script>\n";
$res .= "<script type='text/javascript' src='$baseURL".
"/public/js/bootstrap.js'>";
$res .= "</script>\n";
$res .= "<link type='text/css' rel='stylesheet' href='";
$res .= "$baseURL/public/css/bootstrap.css'/>\n";
$res .= " <style type='text/css'>\n";
$res .= "body { padding-top: 40px; padding-bottom: 40px;";
$res .= " background-color: #eee; }\n";
$res .= ".form-signin { max-width: 330px;padding:15px;margin:0 auto;}\n";
$res .= ".form-signin .form-signin-heading, .form-signin .checkbox {";
$res .= " margin-bottom: 10px; }\n";
$res .= ".form-signin .checkbox { font-weight: normal; }\n";
$res .= ".form-signin .form-control {";
$res .= "position: relative; font-size: 16px; height: auto;";
$res .= "padding: 10px; -webkit-box-sizing: border-box;";
$res .= "-moz-box-sizing: border-box; box-sizing: border-box; }\n";
$res .= ".form-signin .form-control:focus { z-index: 2; }\n";
$res .= ".form-signin input[type='text'] { margin-bottom: -1px;";
$res .= "border-bottom-left-radius: 0; border-bottom-right-radius: 0; }\n";
$res .= ".form-signin input[type='password'] {";
$res .= "margin-bottom: 10px; border-top-left-radius: 0;";
$res .= "border-top-right-radius: 0; }\n";
$res .= " </style>\n";
$res .= " </head>\n";
$res .= " <body>\n";
$res .= "<div class='container'>\n";
$res .= " <form class='form-signin' role='form' method='post' ";
$res .= "action='";
if ($url === "")
$res .= "#";
else
$res .= $baseURL."authentication/$url";
$res .= "'>\n";
$res .= " <h2 class='form-signin-heading'>".dgettext("domframework",
"Please sign in");
$res .= "</h2>\n";
$res .= " <input type='text' class='form-control' name='email' ";
$res .= "placeholder='".dgettext("domframework",
"Email address")."' required autofocus/>\n";
$res .= " <input type='password' class='form-control' name='password' ";
$res .= "placeholder='".dgettext("domframework",
"Password")."' required/>\n";
$res .= " <label class='checkbox'>";
$res .= "<input type='checkbox' name='remember-me'/>".dgettext("domframework",
"Remember me");
$res .= "</label>\n";
$res .= " <button class='btn btn-lg btn-primary btn-block' ";
$res .= "type='submit'>".dgettext("domframework",
"Sign in")."</button>\n";
if ($message !== "")
$res .= "<div class='alert alert-danger'>$message</div>";
$res .= " </form>\n";
$res .= "</div>\n";
$res .= "</body>\n";
$res .= "</html>\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);
}
/** 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);
}
public function logout ()
{
throw new exception (dgettext("domframework",
"No logout method available"), 405);
}
}