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()) . "'");
60 session_regenerate_id(true);
65 $_SESSION['Pman_I18N'] = array();
70 if (!empty($_REQUEST['getAuthUser'])) {
71 //DB_Dataobject::debugLevel(5);
72 $this->sendAuthUserDetails();
76 if (!empty($_REQUEST['username'])) {
79 $this->jerr("INVALID REQUEST");
83 function sendAuthUserDetails()
85 // DB_DataObject::debugLevel(1);
86 $ff = HTML_FlexyFramework::get();
87 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
89 $u = DB_DataObject::factory($tbl);
91 $this->jok(array('id' => 0)); // not logged in..
94 $au = $u->getAuthUser();
96 $aur = $au->authUserArray();
98 /** -- these need modulizing somehow! **/
100 if ($this->hasModule('Fax')) {
101 // should check fax module???
102 $f = DB_DataObject::factory('Fax_Queue');
103 $aur['faxMax'] = $f->getMaxId();
104 $aur['faxNumPending'] = $f->getNumPending();
107 if ($this->hasModule('Documents')) {
109 $d = DB_DataObject::factory('Documents_Tracking');
110 $d->person_id = $au->id;
111 //$d->status = 0; // unread
112 $d->whereAdd('date_read IS NULL');
113 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
114 $aur['inbox_unread'] = $d->count();
117 //echo '<PRE>';print_r($aur);
129 //DB_DataObject::debugLevel(1);
130 if (!empty($_REQUEST['getAuthUser'])) {
131 $this->sendAuthUserDetails();
136 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
138 return $this->passwordRequest($_REQUEST['passwordRequest']);
142 if (!empty($_REQUEST['changePassword'])) {
143 return $this->changePassword($_REQUEST);
148 $ff = HTML_FlexyFramework::get();
149 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
152 $u = DB_DataObject::factory($tbl);
156 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
157 $this->jerr('You typed the wrong Username or Password (0)');
161 $u->authUserName($_REQUEST['username']);
164 if ($u->count() > 1 || !$u->find(true)) {
165 $this->jerr('You typed the wrong Username or Password (1)');
170 $this->jerr('Account disabled');
173 if ($u->checkPassword($_REQUEST['password'])) {
175 $this->addEvent("LOGIN", false, session_id());
176 if (!empty($_REQUEST['lang'])) {
177 $u->lang($_REQUEST['lang']);
181 $this->sendAuthUserDetails();
188 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
192 function passwordRequest($n)
194 $u = DB_DataObject::factory('Person');
195 //$u->company_id = $this->company->id;
197 $u->whereAdd('LENGTH(passwd) > 1');
200 if ($u->count() > 1 || !$u->find(true)) {
201 $this->jerr('invalid User (1)');
203 // got a avlid user..
204 if (!strlen($u->passwd)) {
205 $this->jerr('invalid User (2)');
207 // check to see if we have sent a request before..
209 if ($u->no_reset_sent > 3) {
210 $this->jerr('We have issued to many resets - please contact the Administrator');
212 $this->authFrom = time();
213 $this->authKey = $u->genPassKey($this->authFrom);
214 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
216 $ret = $u->sendTemplate('password_reset', $this);
217 if (is_object($ret)) {
218 $this->addEvent('SYSERR',false, $ret->getMessage());
219 $this->jerr($ret->getMessage());
221 $this->addEvent('PASSREQ',$u, $u->email);
223 $uu->no_reset_sent++;
229 function changePassword($r)
231 $au = $this->getAuthUser();
234 $au->setPassword($r['passwd1']);
238 // not logged in -> need to validate
239 if (empty($r['passwordReset'])) {
240 $this->jerr("invalid request");
242 // same code as reset pasword
244 $bits = explode('/', $r['passwordReset']);
247 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
249 if ($res !== false) {
252 // key is correct.. let's change password...
254 $u = DB_DataObject::factory('Person');
256 //$u->company_id = $this->company->id;
257 $u->whereAdd('LENGTH(passwd) > 1');
259 if (!$u->get($bits[0])) {
260 $this->jerr("invalid id"); // should not happen!!!!
263 $u->setPassword($r['passwd1']);