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();
51 $this->addEvent('LOGOUT', false, session_id());
52 session_regenerate_id(true);
57 $_SESSION['Pman_I18N'] = array();
62 if (!empty($_REQUEST['getAuthUser'])) {
63 //DB_Dataobject::debugLevel(5);
64 $this->sendAuthUserDetails();
68 if (!empty($_REQUEST['username'])) {
71 $this->jerr("INVALID REQUEST");
75 function sendAuthUserDetails()
77 // DB_DataObject::debugLevel(1);
78 $ff = HTML_FlexyFramework::get();
79 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
81 $u = DB_DataObject::factory($tbl);
83 $this->jok(array('id' => 0)); // not logged in..
86 $au = $u->getAuthUser();
88 $aur = $au->authUserArray();
90 /** -- these need modulizing somehow! **/
92 if ($this->hasModule('Fax')) {
93 // should check fax module???
94 $f = DB_DataObject::factory('Fax_Queue');
95 $aur['faxMax'] = $f->getMaxId();
96 $aur['faxNumPending'] = $f->getNumPending();
99 if ($this->hasModule('Documents')) {
101 $d = DB_DataObject::factory('Documents_Tracking');
102 $d->person_id = $au->id;
103 //$d->status = 0; // unread
104 $d->whereAdd('date_read IS NULL');
105 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
106 $aur['inbox_unread'] = $d->count();
109 //echo '<PRE>';print_r($aur);
121 //DB_DataObject::debugLevel(1);
122 if (!empty($_REQUEST['getAuthUser'])) {
123 $this->sendAuthUserDetails();
128 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
130 return $this->passwordRequest($_REQUEST['passwordRequest']);
134 if (!empty($_REQUEST['changePassword'])) {
135 return $this->changePassword($_REQUEST);
140 $ff = HTML_FlexyFramework::get();
141 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
144 $u = DB_DataObject::factory($tbl);
148 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
149 $this->jerr('You typed the wrong Username or Password (0)');
153 $u->authUserName($_REQUEST['username']);
156 if ($u->count() > 1 || !$u->find(true)) {
157 $this->jerr('You typed the wrong Username or Password (1)');
162 $this->jerr('Account disabled');
165 if ($u->checkPassword($_REQUEST['password'])) {
167 $this->addEvent("LOGIN", false, session_id());
168 if (!empty($_REQUEST['lang'])) {
169 $u->lang($_REQUEST['lang']);
173 $this->sendAuthUserDetails();
180 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
184 function passwordRequest($n)
186 $u = DB_DataObject::factory('Person');
187 //$u->company_id = $this->company->id;
189 $u->whereAdd('LENGTH(passwd) > 1');
192 if ($u->count() > 1 || !$u->find(true)) {
193 $this->jerr('invalid User (1)');
195 // got a avlid user..
196 if (!strlen($u->passwd)) {
197 $this->jerr('invalid User (2)');
199 // check to see if we have sent a request before..
201 if ($u->no_reset_sent > 3) {
202 $this->jerr('We have issued to many resets - please contact the Administrator');
204 $this->authFrom = time();
205 $this->authKey = $u->genPassKey($this->authFrom);
206 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
208 $ret = $u->sendTemplate('password_reset', $this);
209 if (is_object($ret)) {
210 $this->addEvent('SYSERR',false, $ret->getMessage());
211 $this->jerr($ret->getMessage());
213 $this->addEvent('PASSREQ',$u, $u->email);
215 $uu->no_reset_sent++;
221 function changePassword($r)
223 $au = $this->getAuthUser();
226 $au->setPassword($r['passwd1']);
230 // not logged in -> need to validate
231 if (empty($r['passwordReset'])) {
232 $this->jerr("invalid request");
234 // same code as reset pasword
236 $bits = explode('/', $r['passwordReset']);
239 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
241 if ($res !== false) {
244 // key is correct.. let's change password...
246 $u = DB_DataObject::factory('Person');
248 //$u->company_id = $this->company->id;
249 $u->whereAdd('LENGTH(passwd) > 1');
251 if (!$u->get($bits[0])) {
252 $this->jerr("invalid id"); // should not happen!!!!
255 $u->setPassword($r['passwd1']);