Location: PHPKode > projects > Itshomi PHP Framework > itshomi/components/imiuser/DoLogin.php
<?
/*************************************************************
*                   Login verification service               *
*                 Copyright ALM Software Technologies        *
*                  Created by: Fernando Martinez             *
*                        10/12/05                            *
**************************************************************/


/** perform user login */
class DoLogin extends ImiComponent
{
    private $db;
    
    function doTask()
    {	
        $this->db = $this->navigator->getInstance('dbtable');
        $this->db->useTable('user');
        if(!get_magic_quotes_gpc()){
            $username = $this->db->escapeString($_REQUEST["username"]);
        }else{
            $username = $_REQUEST["username"];
        }
        $pwd	  = $_REQUEST["password"];
        $sql = "select * from user inner join role on user.roleid=role.id where username=".$this->db->pS($this->db->escapeString($username));
        $user = $this->db->execQuery($sql);
        if($user!==null && count($user)>0)
        {
                $pwd = md5($pwd);  
                if(strpos($user[0]["password"],$pwd)!==false)
                {
                        if($user[0]["active"]==0 && $user[0]["deleted"]!=1)
                        {
                                $_REQUEST['feedback'] = "Your account has been temporarily blocked. If you believe this is a mistake, please <a href='index.php?q=contact'>contact us</a>.";
                                return;
                        }
                        $lastlogin = $user[0]['lastlogin'];
                        if(isset($lastlogin))
                        {
                                $lastloginMsg = "You last logged in ".$lastlogin;
                        }else
                        {
                                $lastloginMsg = "This is your first time here as a member!!";
                        }
                        session_regenerate_id();
                        $_SESSION['LoggedIn']=true;
                        $_REQUEST['feedback']="Welcome, ".$username."<br>".$lastloginMsg."<br>";
                        $_SESSION['uname']=$username;
                        $_SESSION['uid']=$user[0][0];
                        $_SESSION['email']=$user[0]['email'];
                        $_SESSION['roleid']=$user[0]['roleid'];
				$_SESSION['mtype']=$user[0]['mtype'];
        $_SESSION['rolename']=$user[0]['rolename'];
                        $_SESSION['country']=$user[0]['country'];
                        $_SESSION['landingpage']=$user[0]['landingpage'];
                        $names[0] = "lastlogin";
                        $values[0]=$this->db->pS(date("Y/m/d H:i:s"));
        $names[1] = "loggedin";
        $values[1] = "1";
                        $this->db->updateRows($names,$values,"username=".$this->db->pS($username));
                        if(!isset($_REQUEST['mbq'])){
                $this->addView($this->navigator->getPath()."/".$user[0]['landingpage']);
            $this->addViewData('CONTENT_HEAD','Your Portfolio');
        }else
                                addView($this->compPath()."mbhome.php");
                }else
                {
                        $_SESSION['LoggedIn']=false;
                        $_REQUEST['feedback']="Incorrect password";
                }
        }else
        {
                $_REQUEST['feedback']="Your username doesn't exist";
        }
    }
}
Return current item: Itshomi PHP Framework