1
0
Fork 0

First, minimalistic version

This commit is contained in:
Gergely Polonkai (W00d5t0ck) 2011-09-29 18:50:21 +02:00
parent 244aaa00fe
commit cc5aa56d38
3 changed files with 153 additions and 66 deletions

View File

@ -9,11 +9,52 @@ interface gatewayBackend
* @param String $sessionId
* @return String $token
*/
public function get_token($username, $password, $ip, $sessionId);
public function getToken($username, $password, $ip, $sessionId);
/**
* @param
*
* @param String $token
* @param String $sessionId
* @param String $ip
* @return Boolean
*/
public function
public function checkToken($token, $sessionId, $ip);
/**
* removeToken() Remove a logged out user's token
*
* @param String $token
*/
public function removeToken($token);
/**
* sendSMS()
*
* Send SMS message to recipient's phone number
* @param String $token
* @param String $recipient
* @param String $message
* @param Array $passwordLocations
* @return Boolean
*/
public function sendSMS($token, $recipient, $message, $passwordLocations);
/**
* auditLog() Log audit messages
*
* @param String $ip
* @param String $event
* @param String $message
*/
public function auditLog($ip, $event, $message);
/**
* messageLog() Log sent messages
*
* @param String $recipient
* @param String $message
* @param String $ip
*/
public function messageLog($recipient, $message, $ip);
}

View File

@ -1,7 +1,61 @@
<?php
require_once 'gatewayBackend.php';
class postgresGatewayBackend implements gatewayBackend
final class postgresGatewayBackend implements gatewayBackend
{
const GWBE_SUCCESS = 0;
const GWBE_DBERROR = 1;
const GWBE_AUTHFAIL = 2;
private $dbh = null;
public function __construct($dbHost, $dbUser, $dbPassword, $dbName)
{
$dsn = 'pgsql:host=' . $dbHost . ';dbname=' . $dbName;
$this->dbh = new PDO($dsn, $dbUser, $dbPassword);
}
public function getToken($username, $password, $ip, $sessionId)
{
$query = 'SELECT id, password FROM users WHERE username = :username:';
$sth = $this->dbh->prepare($query);
if ($sth->execute(array(':username:' => $username)))
{
/*
audit_log('Unsuccessful login by $username from $ip');
audit_log('Could not create token for $username at $ip');
return 'Authentication failed. Reason: Internal Server Error';
*/
}
else
{
throw new Exception('AuthFail', self::GWBE_DBERROR);
}
}
public function checkToken($token, $sessionId, $ip)
{
return null;
}
public function removeToken($token)
{
return null;
}
public function sendSMS($token, $recipient, $message, $passwordLocations)
{
return null;
}
public function auditLog($ip, $event, $message)
{
return null;
}
public function messageLog($recipient, $message, $ip)
{
return null;
}
}

View File

@ -2,37 +2,27 @@
class smsSender
{
protected $sessionId = null;
protected $backend;
public function __construct($backend, $sessionId)
{
$this->sessionId = $sessionId;
$this->backend = $backend;
}
public function login($username, $password)
{
/*
if (valid_user($username, $password))
try
{
$token = generate_token($ip, $session_id, $token, $start_time);
if ($token)
$token = $this->backend->getToken($username, $password, $_SERVER['REMOTE_ADDR'], $this->sessionId);
}
catch (Exception $e)
{
audit_log('Successful login by $username from $ip');
throw new Exception('Authentication failed. Reason: ' . $e->getMessage());
}
$this->backend->auditLog($_SERVER['REMOTE_ADDR'], 'login', 'Successful login by ' . $username);
return $token;
}
else
{
audit_log('Could not create token for $username at $ip');
return 'Authentication failed. Reason: Internal Server Error';
}
}
else
{
audit_log('Unsuccessful login by $username from $ip');
return 'Authentication failed. Reason: Bad username or password';
}
*/
return array('username' => $username, 'password' => $password, 'session-id' => $this->sessionId);
}
public function send($token, $recipient, $message, $passwordLocations)
{
@ -55,7 +45,8 @@ class smsSender
throw new Exception('Authentication failed. Reason: Invalid Token');
}
*/
return array('token' => $token, 'recipient' => $recipient, 'message' => $message, 'password-locations' => $passwordLocations, 'session-id' => $this->sessionId);
/* TODO: implement */
throw new Exception('This feature is not yet implemented');
}
public function logout($token)
@ -63,8 +54,9 @@ class smsSender
/*
delete_token($token);
audit_log('$token->username logged out at $ip');
*/
return 'success';
*/
/* TODO: implement */
throw new Exception('This feature is not yet implemented');
}
}