OpenSencillo  2015.002
logMan Class Reference
+ Inheritance diagram for logMan:
+ Collaboration diagram for logMan:

Public Member Functions

 __construct ($DBHost, $DBName, $DBUser, $DBPass)
 install ()
 editPerm ($login=null, $perm=null)
 getPerm ()
 ereg ()
 login ($ajax)
 checkSession ($signal=false)
 basicLogin ($translate, $seo)
 addToMainArray ($name, $data)
 ajaxSendJson ()
 addNewUser ($pass, $perm)
 createSession ()
 destroySession ()
 addSessionData ($name, $data=null)
 getSessionData ($name)
 signIn ($pass)
 getSignedUser ()
 signOut ()
 clean ($string)

Protected Attributes

 $log = array()
 $status = array()

Detailed Description

Definition at line 2 of file login.management.logman.php.


Constructor & Destructor Documentation

__construct ( DBHost,
DBName,
DBUser,
DBPass 
)

Create connection

Parameters:
string$DBHost
string$DBName
string$DBUser
string$DBPass

Reimplemented from mysql.

Definition at line 7 of file login.management.logman.php.

        {
                parent::__construct($DBHost,$DBName,$DBUser,$DBPass);
                $this->log['server']=$_SERVER['SERVER_NAME'];
                $this->log['request']=$_SERVER['REQUEST_URI'];
                $this->log['port']=$_SERVER['REMOTE_PORT'];
                $this->log['agent']=$_SERVER['HTTP_USER_AGENT'];
                $this->log['referer']=$_SERVER['HTTP_REFERER'];
                $this->log['external_ip']=$_SERVER['REMOTE_ADDR'];
                $this->status=array(
                        'called'=>$_POST['atype'],
                        'date'=>date('Y-m-d'),
                        'time'=>date('H:i:s')
                );
                if($this->test())
                {
                        $this->log['database']=array('host'=>$this->DBHost,
                                                                                 'name'=>$this->DBName,
                                                                                 'user'=>$this->DBUser,
                                                                                 'pass'=>$this->DBPass);
                        $this->install();
                }
                else
                {
                        die("<b>login.management.logman: MySQL connection failed!</b>".mysql_error());
                }
        }

Member Function Documentation

addNewUser ( pass,
perm 
) [final]

Definition at line 300 of file login.management.logman.php.

        {
                
        }
addSessionData ( name,
data = null 
) [final]

Store data in new session

Parameters:
string$name
string$data
Returns:
string

Definition at line 334 of file login.management.logman.php.

        {
                $_SESSION[$name]=$data;
                return $data;
        }
addToMainArray ( name,
data 
) [final]

Add data to main login array

Parameters:
string$name
multitype$data

Definition at line 287 of file login.management.logman.php.

        {
                $this->status[$name]=$data;
        }
ajaxSendJson ( ) [final]

Convert main array to JSON export and print as AJAX response

Definition at line 295 of file login.management.logman.php.

        {
                print json_encode($this->status);
        }
basicLogin ( translate,
seo 
)

Create default login system

Parameters:
object$translate
object$seo
Returns:
number

Definition at line 227 of file login.management.logman.php.

        {
                $this->createSession();
                if((is_object($translate))&&(is_object($seo)))
                {
                        switch($_GET['p'])
                        {
                                case 'logout':
                                        $this->destroySession();
                                case '':
                                        define('LOGIN_ERRMSG',"000:".$_SESSION['sessionid']);
                                        define('LOGIN_ACTION','/login');
                                        echo $seo->save();
                                        require_once 'fw_templates/login.default.screen.php';
                                        break;
                                case 'login':
                                        $status = $this->checkSession(true);
                                        $seo->custom('<script type="text/javascript">console.log("Login status:'.$status["code"].'");</script>');
                                        switch($status['code'])
                                        {
                                                case 200:
                                                case 202:
                                                        //login success
                                                        define('LOGIN_ERRMSG',$status['code'].":".$_SESSION['sessionid'].":ok:user:".$this->getSessionData('userid'));
                                                        echo $seo->save();
                                                        require_once 'fw_templates/account.dafault.screen.php';
                                                        break;
                                                default:
                                                        //login failed
                                                        $this->destroySession();
                                                        define('LOGIN_ERRMSG',$status['code'].":".$_SESSION['sessionid'].":failed");
                                                        define('LOGIN_ACTION','/login');
                                                        echo $seo->save();
                                                        require_once 'fw_templates/login.default.screen.php';
                                        }
                                        break;
                                case 'ereg':
                                case 'registration':
                                        //ereg
                                        $this->destroySession();
                                        define('LOGIN_ACTION','/registration');
                                        $status = $this->ereg();
                                        define('LOGIN_ERRMSG',$status['code'].":ereg");
                                        echo $seo->save();
                                        require_once 'fw_templates/ereg.default.screen.php';
                                        break;
                        }
                        return $status['code'];
                }
                else 
                {
                        return 500;
                }
        }
checkSession ( signal = false) [final]

Check whether session

Parameters:
bool$signal
Returns:
boolean|Ambigous <multitype:number , multitype:>

Definition at line 205 of file login.management.logman.php.

        {
                $this->openTable('users');
                $browser = ($this->getSessionData('sessionid') ? array("code"=>200) : $this->login($_POST));
                $server  = $this->output("`id`=".$this->getSessionData('userid'));
                
                if(!$signal)
                {
                        return (($server['line'][1][1]===$this->getSessionData('sessionid'))&&($browser["code"]<300)&&($server['line'][1][8]===$this->getSessionData('perm')) ? true : false);
                }
                else 
                {
                        return (($server['line'][1][1]===$this->getSessionData('sessionid'))&&($browser["code"]<300)&&($server['line'][1][8]===$this->getSessionData('perm')) ? $browser : array("code"=>404));
                }
        }
clean ( string) [final]

Remove all special characters

Parameters:
string$string
Returns:
string

Definition at line 375 of file login.management.logman.php.

        {
            return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
        }
createSession ( ) [final]

Create session data

Returns:
multitype array

Definition at line 309 of file login.management.logman.php.

        {
                $this->log['session']=array('exist'=>session_start(),
                                                                        'id'=>hash("sha512",session_id().date("YmdHis")),
                                                                        'date'=>date('Y-m-d'),
                                                                        'time'=>date('H:i:s'));
                return $this->log['session'];
        }
destroySession ( ) [final]

Destroy exist session

Definition at line 321 of file login.management.logman.php.

        {
                $this->update('`id`='.$this->getSessionData('userid'),"`sign`=NULL");
                unset($this->log['session']);
                session_destroy();
        }
editPerm ( login = null,
perm = null 
) [final]

Update perm in logMan

Parameters:
string
int(1000~1111)
Returns:
int OR false

Definition at line 74 of file login.management.logman.php.

        {
                if(isset($login))
                {
                        if((is_numeric($perm))&&($perm<=1111))
                        {
                                $this->set("perm",$perm);
                                $this->update("`login`=".$this->log['user']);
                                unset($this->log['perm']);
                                $this->log['perm']=$perm;
                                return $this->log['perm'];
                        }
                        else
                        {
                                return false;
                        }
                }
                else
                {
                        $this->set("perm",$perm);
                        $this->update("`login`=".$login);
                }
        }
ereg ( ) [final]

Create new user in database

Parameters:
array$_POST
Returns:
array $this->status

Definition at line 115 of file login.management.logman.php.

        {
                $this->openTable('users');
            if(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
            {
                $user=$this->output("`login`='".$_POST['email']."'","`id` ASC",1);
                if($user['line'][1][0]==null)
            {
                try 
                {
                    $this->insert("'first_use',0,'".strtolower($_POST['email'])."',MD5('".$_POST['pass']."'),'".strtolower($_POST['email'])."','".$this->clean(ucwords(strtolower($_POST['fname'])))."','".$this->clean(ucwords(strtolower($_POST['lname'])))."',1000,'".$this->log['external_ip'].":".$this->log['port']."','".$this->log['agent']."',DATE(NOW()),TIME(NOW())");
                    $this->status['status']='ok';
                    $this->status['code']=200;
                }
                catch(Exception $e)
                {
                        $this->status['status']='failed';
                        $this->status['code']=417;
                }
            }
            else 
            {
                $this->status['status']='exist';
                $this->status['code']=409;
            }
            }
            else 
            {
                $this->status['status']='invalid';
                $this->status['code']=403;
            }
            return $this->status;
        }
getPerm ( ) [final]

Returned actual user permission

Returns:
int(4)

Definition at line 103 of file login.management.logman.php.

        {
                return $this->log['perm'];
        }
getSessionData ( name) [final]

Get data from session storage

Parameters:
string$name
Returns:
multitype

Definition at line 345 of file login.management.logman.php.

        {
                return $_SESSION[$name];
        }
getSignedUser ( ) [final]

Get all information about signed user

Returns:
array

Definition at line 360 of file login.management.logman.php.

        {
                return $this->log;
        }
install ( ) [final]

Install logMan if table not exist

Returns:
bool

Definition at line 41 of file login.management.logman.php.

        {
                try
                {
                        $this->newColumn("sign","TEXT");
                        $this->newColumn("active","INT(1)");
                        $this->newColumn("login","VARCHAR(255)");
                        $this->newColumn("pass","VARCHAR(255)");
                        $this->newColumn("email","VARCHAR(255)");
                        $this->newColumn("fname","VARCHAR(255)");
                        $this->newColumn("lname","VARCHAR(255)");
                        $this->newColumn("perm","INT(4)");
                        $this->newColumn("ip","VARCHAR(20)");
                        $this->newColumn("agent","TEXT");
                        $this->newColumn("date","VARCHAR(20)");
                        $this->newColumn("time","VARCHAR(20)");
                        $this->createTable("users");
                        return true;
                }
                catch(Exception $e)
                {
                        return false;
                }
        }
login ( ajax) [final]

Login with ajax

Parameters:
array$ajax
Returns:
array $this->status

Definition at line 156 of file login.management.logman.php.

        {
                $this->openTable('users');
            if(filter_var($ajax['email'],FILTER_VALIDATE_EMAIL))
            {
                if($this->output("`login`='".strtolower($ajax['email'])."' AND `pass`=MD5('".$ajax['pass']."')","`id` ASC",1)!=false)
            {
                $this->status['status']='authorized';
                $this->status['code']=202;
                $this->status['user']=$this->output("`login`='".strtolower($ajax['email'])."' AND `pass`=MD5('".$ajax['pass']."')","`id` ASC",1);
                
                $this->addSessionData('userid',$this->status['user']['line'][1][0]);
                $this->addSessionData('login',$this->status['user']['line'][1][3]);
                $this->addSessionData('email',$this->status['user']['line'][1][5]);
                $this->addSessionData('perm',$this->status['user']['line'][1][8]);
                $this->addSessionData('sessionid',$this->log['session']['id']);
                $this->addSessionData('start',date('Y-m-d H:i:s'));
                if($this->status['user']['line'][1][1]=='first_use')
                {
                    $this->addSessionData('tutorial',true);
                }
                else
                {
                    $this->addSessionData('tutorial',false);
                }
                $this->update('`id`='.$this->status['user']['line'][1][0],"`sign`='".$this->getSessionData('sessionid')."',`ip`='".$this->log['external_ip'].":".$this->log['port']."',`agent`='".$this->log['agent']."',`date`='".$this->status['date']."',`time`='".$this->status['time']."'");
                
                unset($this->status['user']['line']);
            }
            else 
            {
                $this->status['status']='unauthorized';
                $this->status['code']=404;
            }
            }
            else 
            {
                $this->status['status']='invalid';
                $this->status['code']=403;
            }
            return $this->status;
        }
signIn ( pass) [final]

Definition at line 350 of file login.management.logman.php.

        {
                
        }
signOut ( ) [final]

Definition at line 365 of file login.management.logman.php.

        {
                //TODO
        }

Field Documentation

$log = array() [protected]

Definition at line 4 of file login.management.logman.php.

$status = array() [protected]

Definition at line 5 of file login.management.logman.php.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables