Files
DomFramework/auth.php

176 lines
7.3 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="", $alreadyAuth=false)
{
$res = "";
$res .= "<!DOCTYPE html>\n";
$res .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" ";
$res .= " lang=\"en\">\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 .= " <style type='text/css'>\n";
$res .= "body { padding-top: 40px; padding-bottom: 40px;
font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
background-attachment: fixed; background-position: top;
background-image: radial-gradient(ellipse at center -60px,
#9da1ac 0%,#1c202a 100%);
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 .= ".container { background: white; border-radius:10px;
border-top: none; width:300px;
margin-left: auto; margin-right: auto;
text-align:center;
padding: 20px;}\n";
$res .= "input[type='text'], input[type='password'] {
display:inline-block;
border-radius : 10px 10px 10px 10px;
border: 1px solid #cccccc;
margin: 0px;
height:10px;
padding-top: 10px;
margin-bottom: 20px;
background-color:white;}\n";
$res .= "input[type='submit'] {
vertical-align: middle;
border-radius : 10px 10px 10px 10px;
height: 40px;
margin-top : 10px;
padding-top : 10px;
padding-bottom : 10px;
padding-left : 30px;
padding-right : 30px;
display: inline-block;
text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.75);
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.2) inset,
0px 1px 2px rgba(0, 0, 0, 0.05);
background-color: #cccccc;}\n";
$res .= "h2 { padding-top: 0px; padding-bottom: 30px;}\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";
if ($alreadyAuth === false)
{
$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 .= " <input type='submit' value='".dgettext("domframework",
"Sign in")."'/>\n";
}
else
{
$res .= " <h2 class='form-signin-heading'>".dgettext("domframework",
"Already sign in");
$res .= "</h2>\n";
$res .= " <p><a href='". $baseURL."authentication/logout'>".dgettext ("domframework", "Click here to logout")."</a></p>\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);
}
/** 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);
}
public function logout ()
{
throw new exception (dgettext("domframework",
"No logout method available"), 405);
}
}