Overview

Namespaces

  • Core
    • BaseClasses
    • Cookie
    • Crontab
    • DB
    • Input
    • Mailer
    • Middleware
      • Auth
      • CSRF
    • Route
    • Session
    • System
  • None

Classes

  • Bridge
  • Core\BaseClasses\BaseAuth
  • Core\BaseClasses\BaseController
  • Core\BaseClasses\BaseCSRF
  • Core\Cookie\Cookie
  • Core\Crontab\Crontab
  • Core\DB\DB
  • Core\Input\Input
  • Core\Mailer\Mailer
  • Core\Middleware\Auth\Auth
  • Core\Middleware\CSRF\CSRF
  • Core\Route\Route
  • Core\Session\Session
  • Core\System\System

Functions

  • back
  • ControllerAutoload
  • dbd
  • ErrorHandler
  • ExceptionHandler
  • json
  • loadConfig
  • MiddlewareAutoload
  • redirect
  • SPAutoload
  • view
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * @Author: Shakti Phartiyal
  5:  * Date: 12/1/16
  6:  * Time: 12:29 PM
  7:  */
  8: namespace Core\BaseClasses;
  9: 
 10: use Core\DB\DB;
 11: use Core\System\System;
 12: 
 13: class BaseAuth
 14: {
 15:     private $headers;
 16: 
 17:     /**
 18:      * Sets headers in Base Auth object
 19:      * @return BaseAuth Object
 20:      *
 21:      */
 22:     protected function headers()
 23:     {
 24:         $this->headers = System::FilterInput(getallheaders());
 25:         return $this;
 26:     }
 27: 
 28:     /**
 29:      * Checks if Auth key exists in the request headers
 30:      * @return bool
 31:      */
 32:     protected function hasAuthKey()
 33:     {
 34:         return (array_key_exists("Auth-Key",$this->headers) && $this->headers['Auth-Key'] != "");
 35:     }
 36: 
 37:     /**
 38:      * Returns the auth key
 39:      * @return mixed
 40:      */
 41:     protected function getAuthKey()
 42:     {
 43:         return $this->headers['Auth-Key'];
 44:     }
 45: 
 46:     /**
 47:      * Checks if the API Keys in the request has any associated users with it in DB
 48:      * @param $key
 49:      * @return bool
 50:      */
 51:     protected function keyHasAssociatedID($key)
 52:     {
 53:         $db = DB::ADO();
 54:         $rs = $db->Execute('select user_id from api_keys WHERE api_key = ? AND status = ? ',[$key, 1]);
 55:         $associatedID = $rs->fetchRow();
 56:         if($associatedID == "")
 57:         {
 58:             return false;
 59:         }
 60:         else
 61:         {
 62:             return true;
 63:         }
 64:     }
 65: 
 66:     /**
 67:      * Checks whether the request has a checksum in headers
 68:      * @return bool
 69:      */
 70:     protected function hasChecksum()
 71:     {
 72:         return (array_key_exists("Auth-Ch", $this->headers) && $this->headers['Auth-Ch'] != "");
 73:     }
 74: 
 75:     /**
 76:      * Returns checksum
 77:      * @return mixed
 78:      */
 79:     protected function getChecksum()
 80:     {
 81:         return $this->headers['Auth-Ch'];
 82:     }
 83: 
 84:     /**
 85:      * Matches the supplied user name and password with the DB Credentials
 86:      * @param $userName
 87:      * @param $password
 88:      * @return bool | mixed user Data
 89:      */
 90:     protected function matchCredentials($userName, $password)
 91:     {
 92:         $db = DB::ADO();
 93:         $rs = $db->Execute('SELECT * from users WHERE user_name = ? AND password = ? AND status = 1',[$userName, System::GenerateHash($password)]);
 94:         $associateduser = $rs->getAssoc();
 95:         if(count($associateduser) < 1)
 96:         {
 97:             return false;
 98:         }
 99:         else
100:         {
101:             foreach ($associateduser as $assocUser)
102:             {
103:                 return $assocUser;
104:             }
105:         }
106:     }
107: 
108:     /**
109:      * Checks if the data in session matches the user data
110:      * @param $uid
111:      * @param $uname
112:      * @return bool | mixed
113:      */
114:     protected function matchSessionData($uid, $uname)
115:     {
116:         $db = DB::ADO();
117:         $rs = $db->Execute('SELECT * from users WHERE id = ? AND user_name = ? AND status = 1',[$uid, $uname]);
118:         $associateduser = $rs->getAssoc();
119:         if(count($associateduser) < 1)
120:         {
121:             return false;
122:         }
123:         else
124:         {
125:             foreach ($associateduser as $assocUser)
126:             {
127:                 return $assocUser;
128:             }
129:         }
130:     }
131: 
132: }
API documentation generated by ApiGen