Automatic Login
so this works...
The variables $MAIL; and $ANYID; are customly reffered in secure.inc.php for example. $ANYID;grabs the first ID associated with $MAIL. Works for my purpose, but its a bit slow...
login.php
<?php
require_once('main.inc.php');
if(!defined('INCLUDE_DIR')) die('Fatal Error');
define('CLIENTINC_DIR',INCLUDE_DIR.'client/');
define('OSTCLIENTINC',TRUE); //make includes happy
require_once(INCLUDE_DIR.'class.client.php');
require_once(INCLUDE_DIR.'class.ticket.php');
//We are ready baby
$email=$MAIL;
$ticketID=$ANYID;
//$_SESSION=array(); #Uncomment to disable login strikes.
//Check time for last max failed login attempt strike.
if($_SESSION) {
if((time()-$_SESSION)<$cfg->getClientLoginTimeout()) {
$errors='You\'ve reached maximum failed login attempts allowed. Try again later or <a href="open.php">open a new ticket</a>';
}else{ //Timeout is over.
//Reset the counter for next round of attempts after the timeout.
$_SESSION=null;
$_SESSION=0;
}
}
//See if we can fetch local ticket id associated with the ID given
if(!$errors && is_numeric($ticketID) && Validator:($email) && ($tid=Ticket:($ticketID))) {
//At this point we know the ticket is valid.
$ticket= new Ticket($tid);
//TODO: 1) Check how old the ticket is...3 months max?? 2) Must be the latest 5 tickets??
//Check the email given.
if($ticket->getId() && strcasecmp($ticket->getEMail(),$email)==0){
//valid match...create session goodies for the client.
$user = new ClientSession($email,$ticket->getId());
$_SESSION=array(); //clear.
$_SESSION =$ticket->getEmail(); //Email
$_SESSION =$ticket->getExtId(); //Ticket ID --acts as password when used with email. See above.
$_SESSION =$user->getSessionToken();
$_SESSION=$cfg->getTZoffset();
$_SESSION=$cfg->observeDaylightSaving();
//Log login info...
$msg=sprintf("%s/%s logged in ",$ticket->getEmail(),$ticket->getExtId(),$_SERVER);
Sys:(LOG_DEBUG,'User login',$msg);
//Redirect tickets.php
session_write_close();
session_regenerate_id();
<USERMENTION username="header">@header</USERMENTION>("Location: tickets.php");
require('tickets.php'); //Just incase. of header already sent error.
exit;
}
}
//If we get to this point we know the login failed.
$_SESSION+=1;
if(!$errors && $_SESSION>$cfg->getClientMaxLogins()) {
// $loginmsg='Access Denied';
$errors='Forgot your login info? Please <a href="open.php">open a new ticket</a>.';
$_SESSION=time();
$alert='Excessive login attempts by a client?'."\n".
'Email: '.$_POST."\n".'Ticket#: '.$_POST."\n".
'IP: '.$_SERVER."\n".'Time:'.date('M j, Y, g a T')."\n\n".
'Attempts #'.$_SESSION;
Sys:(LOG_ALERT,'Excessive login attempts (client)',$alert,($cfg->alertONLoginError()));
}elseif($_SESSION%2==0){ //Log every other failed login attempt as a warning.
$alert='Email: '.$_POST."\n".'Ticket #: '.$_POST."\n".'IP: '.$_SERVER.
"\n".'TIME: '.date('M j, Y, g a T')."\n\n".'Attempts #'.$_SESSION;
Sys:(LOG_WARNING,'Failed login attempt (client)',$alert);
}
//require(CLIENTINC_DIR.'header.inc.php');
//require(CLIENTINC_DIR.'footer.inc.php');
?>