ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilPDOAuthentication.php
Go to the documentation of this file.
1<?php
2
3require_once 'Services/Authentication/classes/PDO/interface.ilAuthPDOInterface.php';
4
9
10 protected $_sessionName = '_authsession';
11 protected $allowLogin = true;
12 protected $_postUsername = 'username';
13 protected $_postPassword = 'password';
15 protected $enableLogging;
17 protected $status = '';
18 protected $username = null;
19 protected $password;
20 protected $session;
21 protected $server;
22 protected $post;
23 protected $cookie;
24
25
26 public function __construct() {
27 // $started = session_start();
28 // $sess = session_id();
29 // $db_session_handler = new ilSessionDBHandler();
30 // if (!$db_session_handler->setSaveHandler())
31 // {
32 // throw new Exception("Disable save mode or set session_hanlder to \"user\"");
33 // }
34 @session_start(); // Due to UnitTests we have to silence this...
35
36 $this->session = $_SESSION[$this->_sessionName];
37 $this->server = $_SERVER;
38 $this->post = $_POST;
39 $this->cookie = $_COOKIE;
40 }
41
42
43 public function setIdle($time, $add = false) {
44 // TODO: Implement setIdle() method.
45 }
46
47
54 public function setExpire($time, $add = false) {
55 // TODO: Implement setExpire() method.
56 }
57
58
63 public function start() {
64 // TODO SAME AS old AUTH
65 $this->assignData();
66 if (!$this->checkAuth() && $this->allowLogin) {
67 $this->login();
68 }
69 }
70
71
75 protected function checkAuth() {
76 return isset($_SESSION['_authsession']['username']);
77 }
78
79
80 protected function login() {
81 if (!empty($this->username) && $this->verifyPassword($this->username, $this->password)) {
82 $this->setAuth($this->username);
83 } else {
84 $this->status = AUTH_WRONG_LOGIN;
85 }
86 }
87
88
97 function getAuth() {
98 return $this->checkAuth();
99 }
100
101
105 function getStatus() {
106 return $this->status;
107 }
108
109
113 function getUsername() {
114 return $_SESSION['_authsession']['username'];
115 }
116
117
124 function sessionValidThru() {
125 return time() + 1000000;
126 }
127
128
129 public function logout() {
130 $_SESSION['_authsession'] = null;
131 }
132
133 protected function assignData() {
134 if (isset($this->post[$this->_postUsername])
135 && $this->post[$this->_postUsername] != ''
136 ) {
137 $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postUsername]) : $this->post[$this->_postUsername]);
138 }
139 if (isset($this->post[$this->_postPassword])
140 && $this->post[$this->_postPassword] != ''
141 ) {
142 $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postPassword]) : $this->post[$this->_postPassword]);
143 }
144 }
145
146
150 private function setAuth($username) {
151 // session_regenerate_id(true); doesn't seem to work on PHP7
152
153 if (!isset($_SESSION['_authsession'])) {
154 $_SESSION['_authsession'] = array();
155 }
156
157 $_SESSION['_authsession']['username'] = $username;
158 }
159
160
166 private function verifyPassword($username, $password) {
167 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
168
173 return ilUserPasswordManager::getInstance()->verifyPassword($user, $password);
174 }
175}
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
start()
Start new auth session.
setExpire($time, $add=false)
Set the maximum expire time.
sessionValidThru()
Returns the time up to the session is valid.
getAuth()
Has the user been authenticated?
setIdle($time, $add=false)
Set maximum idle time.
static getInstance()
Single method to reduce footprint (included files, created instances)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']