3 require_once 'Pman.php';
9 * User class must provide the following features.
15 * active() -- is user active. // or set prior to checking..
16 * authUserName(n) - sets the value prior to a find(true)
17 * checkPassword($_REQUEST['password'])) {
19 * lang(val) - to set the language..
24 class Pman_Login extends Pman
27 var $masterTemplate = 'login.html';
29 function getAuth() // everyone allowed in here..
31 parent::getAuth(); // load company..
47 if (!empty($_REQUEST['logout'])) {
48 $u = $this->getAuthUser();
52 $this->addEvent('LOGOUT');
53 $e = DB_DataObject::factory('Events');
54 $e->query("UPDATE Events SET remarks = '' WHERE
55 person_id = {$u->id} AND
57 remarks = '". $e->escape(session_id()) . "'");
59 session_regenerate_id(true);
64 $_SESSION['Pman_I18N'] = array();
69 if (!empty($_REQUEST['getAuthUser'])) {
70 //DB_Dataobject::debugLevel(5);
71 $this->sendAuthUserDetails();
75 if (!empty($_REQUEST['username'])) {
78 $this->jerr("INVALID REQUEST");
82 function sendAuthUserDetails()
84 // DB_DataObject::debugLevel(1);
85 $ff = HTML_FlexyFramework::get();
86 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
88 $u = DB_DataObject::factory($tbl);
90 $this->jok(array('id' => 0)); // not logged in..
93 $au = $u->getAuthUser();
95 $aur = $au->authUserArray();
97 /** -- these need modulizing somehow! **/
99 if ($this->hasModule('Fax')) {
100 // should check fax module???
101 $f = DB_DataObject::factory('Fax_Queue');
102 $aur['faxMax'] = $f->getMaxId();
103 $aur['faxNumPending'] = $f->getNumPending();
106 if ($this->hasModule('Documents')) {
108 $d = DB_DataObject::factory('Documents_Tracking');
109 $d->person_id = $au->id;
110 //$d->status = 0; // unread
111 $d->whereAdd('date_read IS NULL');
112 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
113 $aur['inbox_unread'] = $d->count();
116 //echo '<PRE>';print_r($aur);
128 //DB_DataObject::debugLevel(1);
129 if (!empty($_REQUEST['getAuthUser'])) {
130 $this->sendAuthUserDetails();
135 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
137 return $this->passwordRequest($_REQUEST['passwordRequest']);
141 if (!empty($_REQUEST['changePassword'])) {
142 return $this->changePassword($_REQUEST);
147 $ff = HTML_FlexyFramework::get();
148 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
151 $u = DB_DataObject::factory($tbl);
155 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
156 $this->jerr('You typed the wrong Username or Password (0)');
160 $u->authUserName($_REQUEST['username']);
163 if ($u->count() > 1 || !$u->find(true)) {
164 $this->jerr('You typed the wrong Username or Password (1)');
169 $this->jerr('Account disabled');
172 if ($u->checkPassword($_REQUEST['password'])) {
174 $this->addEvent("LOGIN", false, session_id());
175 if (!empty($_REQUEST['lang'])) {
176 $u->lang($_REQUEST['lang']);
180 $this->sendAuthUserDetails();
187 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
191 function passwordRequest($n)
193 $u = DB_DataObject::factory('Person');
194 //$u->company_id = $this->company->id;
196 $u->whereAdd('LENGTH(passwd) > 1');
199 if ($u->count() > 1 || !$u->find(true)) {
200 $this->jerr('invalid User (1)');
202 // got a avlid user..
203 if (!strlen($u->passwd)) {
204 $this->jerr('invalid User (2)');
206 // check to see if we have sent a request before..
208 if ($u->no_reset_sent > 3) {
209 $this->jerr('We have issued to many resets - please contact the Administrator');
211 $this->authFrom = time();
212 $this->authKey = $u->genPassKey($this->authFrom);
213 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
215 $ret = $u->sendTemplate('password_reset', $this);
216 if (is_object($ret)) {
217 $this->addEvent('SYSERR',false, $ret->getMessage());
218 $this->jerr($ret->getMessage());
220 $this->addEvent('PASSREQ',$u, $u->email);
222 $uu->no_reset_sent++;
228 function changePassword($r)
230 $au = $this->getAuthUser();
233 $au->setPassword($r['passwd1']);
237 // not logged in -> need to validate
238 if (empty($r['passwordReset'])) {
239 $this->jerr("invalid request");
241 // same code as reset pasword
243 $bits = explode('/', $r['passwordReset']);
246 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
248 if ($res !== false) {
251 // key is correct.. let's change password...
253 $u = DB_DataObject::factory('Person');
255 //$u->company_id = $this->company->id;
256 $u->whereAdd('LENGTH(passwd) > 1');
258 if (!$u->get($bits[0])) {
259 $this->jerr("invalid id"); // should not happen!!!!
262 $u->setPassword($r['passwd1']);