<?php

/**
 *  Project Name: VzAuth
 *  Version: 0.1
 * 
 *  URL: http://www.vizyonyazilim.com/arge/vzauth
 *
 *  @author Kamil ORS
 *
 */

class Auth {

    var 
$CI;
    var 
$auth = array(
        
'userName' => '',       # Kullanici Adi
        
'userId' => 0,          # Id
        
'eMail' => '',          # E-Mail
        
'ipAddress' => '',      # IP Adresi
        
'roles' => array(),     # Kullanici Yetkileri
        
'loggedIn' => false     # Giris Yapip Yapmadigi
    
);
#-------------------------------------------------------------------------------


    
function Auth() {
         
$this->CI = & get_instance();
         
$this->CI->load->library('session');

         
    }
#-------------------------------------------------------------------------------


    /**
     * Kullanici Girisi
     * @return boolean
     */
     
function login($userName$pass null) {

     
#Test Veriler Gir

         
$this->auth['userName'] = $userName;
         
$this->auth['userId'] = 1;
         
$this->auth['eMail'] = 'kamilors@gmail.com';
         
$this->auth['ipAddress'] = '';
         
$this->auth['loggedIn'] = true;
         
         
$this->auth['roles'] = array('admin''demo''golden''normal');

         
$this->CI->session->set_userdata('auth',$this->auth);

         return 
true;
     }
#-------------------------------------------------------------------------------

    /**
     * Oturumu Kapat
     */
     
function logout() {
         
$this->CI->session->unset_userdata('auth');
     }
#-------------------------------------------------------------------------------

     /**
      * Kullanici Giris Yapmismi
      * @return boolean
      */
      
function isLoggedIn() {
          
$vz $this->CI->session->userdata('auth');
          if(isset (
$vz) && $vz['loggedIn'] == true) {
              return 
true;
          }

          return 
false;
      }
#-------------------------------------------------------------------------------

    /**
     * Yetki Kontrolu Yap
     * @return boolean
     */
     
function hasRole($role) {
         
$vz $this->CI->session->userdata('auth');
         return 
in_array($role$vz['roles']);
     }
#-------------------------------------------------------------------------------

    /**
     * Kullanici Adi
     * @return string
     */
    
function getUserName() {
        
$vz $this->CI->session->userdata('auth');
        return 
$vz['userName'];
    }
#-------------------------------------------------------------------------------

    /**
     * Kullanici ID
     * @return int
     */
    
function getUserId() {
        
$vz $this->CI->session->userdata('auth');
        return 
$vz['userId'];
    }
#-------------------------------------------------------------------------------

    /**
     * E-Mail Adresi
     * @return string
     */
    
function getEMail() {
        
$vz $this->CI->session->userdata('auth');
        return 
$vz['eMail'];
    }
#-------------------------------------------------------------------------------

    /**
     * IP Adresi
     * @return string
     */
    
function getIpAddress() {
        
$vz $this->CI->session->userdata('auth');
        return 
$vz['ipAddress'];
    }
#-------------------------------------------------------------------------------

    /**
     * Kullanici Yetkileri
     * @return array
     */
    
function getRoles() {
        
$vz $this->CI->session->userdata('auth');
        return 
$vz['roles'];
    }
#-------------------------------------------------------------------------------

}

?>