1: <?php
2: 3: 4: 5: 6: 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: 19: 20: 21:
22: protected function headers()
23: {
24: $this->headers = System::FilterInput(getallheaders());
25: return $this;
26: }
27:
28: 29: 30: 31:
32: protected function hasAuthKey()
33: {
34: return (array_key_exists("Auth-Key",$this->headers) && $this->headers['Auth-Key'] != "");
35: }
36:
37: 38: 39: 40:
41: protected function getAuthKey()
42: {
43: return $this->headers['Auth-Key'];
44: }
45:
46: 47: 48: 49: 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: 68: 69:
70: protected function hasChecksum()
71: {
72: return (array_key_exists("Auth-Ch", $this->headers) && $this->headers['Auth-Ch'] != "");
73: }
74:
75: 76: 77: 78:
79: protected function getChecksum()
80: {
81: return $this->headers['Auth-Ch'];
82: }
83:
84: 85: 86: 87: 88: 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: 110: 111: 112: 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: }