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');
56 $_SESSION['Pman_I18N'] = array();
61 if (!empty($_REQUEST['getAuthUser'])) {
62 $this->sendAuthUserDetails();
66 if (!empty($_REQUEST['username'])) {
69 $this->jerr("INVALID REQUEST");
73 function sendAuthUserDetails()
75 DB_DataObject::debugLevel(1);
76 $ff = HTML_FlexyFramework::get();
77 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
79 $u = DB_DataObject::factory($tbl);
81 $this->jok(array('id' => 0)); // not logged in..
84 $au = $u->getAuthUser();
86 $aur = $au->authUserArray();
88 /** -- these need modulizing somehow! **/
90 if ($this->hasModule('Fax')) {
91 // should check fax module???
92 $f = DB_DataObject::factory('Fax_Queue');
93 $aur['faxMax'] = $f->getMaxId();
94 $aur['faxNumPending'] = $f->getNumPending();
97 if ($this->hasModule('Documents')) {
99 $d = DB_DataObject::factory('Documents_Tracking');
100 $d->person_id = $au->id;
101 //$d->status = 0; // unread
102 $d->whereAdd('date_read IS NULL');
103 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
104 $aur['inbox_unread'] = $d->count();
107 //echo '<PRE>';print_r($aur);
120 if (!empty($_REQUEST['getAuthUser'])) {
121 $this->sendAuthUserDetails();
126 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
128 return $this->passwordRequest($_REQUEST['passwordRequest']);
132 if (!empty($_REQUEST['changePassword'])) {
133 return $this->changePassword($_REQUEST);
138 $ff = HTML_FlexyFramework::get();
139 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
142 $u = DB_DataObject::factory($tbl);
146 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
147 $this->jerr('You typed the wrong Username or Password (0)');
151 $u->authUserName($_REQUEST['username']);
154 if ($u->count() > 1 || !$u->find(true)) {
155 $this->jerr('You typed the wrong Username or Password (1)');
160 $this->jerr('Account disabled');
163 if ($u->checkPassword($_REQUEST['password'])) {
165 $this->addEvent("LOGIN");
166 if (!empty($_REQUEST['lang'])) {
167 $u->lang($_REQUEST['lang']);
171 $this->sendAuthUserDetails();
178 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
182 function passwordRequest($n)
184 $u = DB_DataObject::factory('Person');
185 //$u->company_id = $this->company->id;
187 $u->whereAdd('LENGTH(passwd) > 1');
190 if ($u->count() > 1 || !$u->find(true)) {
191 $this->jerr('invalid User (1)');
193 // got a avlid user..
194 if (!strlen($u->passwd)) {
195 $this->jerr('invalid User (2)');
197 // check to see if we have sent a request before..
199 if ($u->no_reset_sent > 3) {
200 $this->jerr('We have issued to many resets - please contact the Administrator');
202 $this->authFrom = time();
203 $this->authKey = $u->genPassKey($this->authFrom);
204 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
206 $ret = $u->sendTemplate('password_reset', $this);
207 if (is_object($ret)) {
208 $this->addEvent('SYSERR',false, $ret->getMessage());
209 $this->jerr($ret->getMessage());
211 $this->addEvent('PASSREQ',$u, $u->email);
213 $uu->no_reset_sent++;
219 function changePassword($r)
221 $au = $this->getAuthUser();
224 $au->setPassword($r['passwd1']);
228 // not logged in -> need to validate
229 if (empty($r['passwordReset'])) {
230 $this->jerr("invalid request");
232 // same code as reset pasword
234 $bits = explode('/', $r['passwordReset']);
237 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
239 if ($res !== false) {
242 // key is correct.. let's change password...
244 $u = DB_DataObject::factory('Person');
246 //$u->company_id = $this->company->id;
247 $u->whereAdd('LENGTH(passwd) > 1');
249 if (!$u->get($bits[0])) {
250 $this->jerr("invalid id"); // should not happen!!!!
253 $u->setPassword($r['passwd1']);