Alternc  latest
Alternc logiel libre pour l'h├ębergement
 All Classes Namespaces Files Functions Variables Pages
Alternc_Api_Auth_Login Class Reference

Authentication API used by server to authenticate a user using his alternc login and password. More...

+ Inheritance diagram for Alternc_Api_Auth_Login:

Public Member Functions

 __construct ($service)
 Constructor of the Login Api Auth. More...
 
 auth ($options)
 Authenticate a user. More...
 
 instructions ()
 instructions on how to use this Auth class More...
 

Public Attributes

const ERR_INVALID_ARGUMENT = 1111201
 

Private Attributes

 $db
 

Detailed Description

Authentication API used by server to authenticate a user using his alternc login and password.

Definition at line 7 of file Login.php.

Constructor & Destructor Documentation

Alternc_Api_Auth_Login::__construct (   $service)

Constructor of the Login Api Auth.

Parameters
$servicean Alternc_Api_Service object
Returns
create the object

Implements Alternc_Api_Auth_Interface.

Definition at line 19 of file Login.php.

References ERR_INVALID_ARGUMENT.

19  {
20 
21  if (!($service instanceof Alternc_Api_Service))
22  throw new \Exception("Invalid argument (service)", ERR_INVALID_ARGUMENT);
23 
24  $this->db = $service->getDb();
25  }
const ERR_INVALID_ARGUMENT
Definition: Login.php:11
Service API used by server to export API methods this class can be used to implement an API service /...
Definition: Service.php:11

Member Function Documentation

Alternc_Api_Auth_Login::auth (   $options)

Authenticate a user.

Parameters
$optionsoptions, depending on the auth scheme, including uid for setuid users here, login is the AlternC username, and password is the password for this username.
Returns
an Alternc_Api_Token

Implements Alternc_Api_Auth_Interface.

Definition at line 34 of file Login.php.

References $db, and Alternc_Api_Token\tokenGenerate().

34  {
35 
36  if (!isset($options["login"]) || !is_string($options["login"])) {
37  throw new \Exception("Missing required parameter login", self::ERR_INVALID_ARGUMENT);
38  }
39  if (!isset($options["password"]) || !is_string($options["password"])) {
40  throw new \Exception("Missing required parameter password", self::ERR_INVALID_ARGUMENT);
41  }
42 
43  if (!preg_match("#^[0-9a-zA-Z-]{1,32}$#", $options["login"])) { // FIXME : normalize this on AlternC !!!
44  throw new \Exception("Invalid login", self::ERR_INVALID_LOGIN);
45  }
46 
47  $stmt = $db->query("SELECT m.enabled,m.uid,m.login,m.su FROM membres m WHERE m.login=? AND m.password=?;", array($options["login"], $options["password"]), PDO::FETCH_CLASS);
48  $me = $stmt->fetch();
49  if (!$me)
50  return new Alternc_Api_Response(array("code" => ERR_INVALID_AUTH, "message" => "Invalid login or password"));
51  if (!$me->enabled)
52  return new Alternc_Api_Response(array("code" => ERR_DISABLED_ACCOUNT, "message" => "Account is disabled"));
53 
55  array("uid" => $me->uid, "isAdmin" => ($me->su != 0)), $this->db
56  );
57  }
static tokenGenerate($options, $db)
Create a new token in the DB for the associated user/admin.
Definition: Token.php:75
Standard Response object for the AlternC API.
Definition: Response.php:7
Alternc_Api_Auth_Login::instructions ( )

instructions on how to use this Auth class

Returns
array("fields" => array("fields to send, required or not"), "description" => "description of this auth")

Implements Alternc_Api_Auth_Interface.

Definition at line 63 of file Login.php.

63  {
64  return array("fields" => array("login" => "AlternC user account", "password" => "AlternC's user password stored in membres table."),
65  "description" => "Authenticate against an AlternC user and password, the same as for the control panel"
66  );
67  }

Member Data Documentation

Alternc_Api_Auth_Login::$db
private

Definition at line 9 of file Login.php.

Referenced by auth().

const Alternc_Api_Auth_Login::ERR_INVALID_ARGUMENT = 1111201

Definition at line 11 of file Login.php.

Referenced by __construct().


The documentation for this class was generated from the following file: