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()
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);
136 $ff = HTML_FlexyFramework::get();
137 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
140 $u = DB_DataObject::factory($tbl);
144 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
145 $this->jerr('You typed the wrong Username or Password (0)');
149 $u->authUserName($_REQUEST['username']);
152 if ($u->count() > 1 || !$u->find(true)) {
153 $this->jerr('You typed the wrong Username or Password (1)');
158 $this->jerr('Account disabled');
161 if ($u->checkPassword($_REQUEST['password'])) {
163 $this->addEvent("LOGIN");
164 if (!empty($_REQUEST['lang'])) {
165 $u->lang($_REQUEST['lang']);
169 $this->sendAuthUserDetails();
176 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
180 function passwordRequest($n)
182 $u = DB_DataObject::factory('Person');
183 //$u->company_id = $this->company->id;
185 $u->whereAdd('LENGTH(passwd) > 1');
188 if ($u->count() > 1 || !$u->find(true)) {
189 $this->jerr('invalid User (1)');
191 // got a avlid user..
192 if (!strlen($u->passwd)) {
193 $this->jerr('invalid User (2)');
195 // check to see if we have sent a request before..
197 if ($u->no_reset_sent > 3) {
198 $this->jerr('We have issued to many resets - please contact the Administrator');
200 $this->authFrom = time();
201 $this->authKey = $u->genPassKey($this->authFrom);
202 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
204 $ret = $u->sendTemplate('password_reset', $this);
205 if (is_object($ret)) {
206 $this->addEvent('SYSERR',false, $ret->getMessage());
207 $this->jerr($ret->getMessage());
209 $this->addEvent('PASSREQ',$u, $u->email);
211 $uu->no_reset_sent++;
217 function changePassword($r)
219 $au = $this->getAuthUser();
222 $au->setPassword($r['passwd1']);
226 // not logged in -> need to validate
227 if (empty($r['passwordReset'])) {
228 $this->jerr("invalid request");
230 // same code as reset pasword
232 $bits = explode('/', $r['passwordReset']);
235 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
237 if ($res !== false) {
240 // key is correct.. let's change password...
242 $u = DB_DataObject::factory('Person');
244 //$u->company_id = $this->company->id;
245 $u->whereAdd('LENGTH(passwd) > 1');
247 if (!$u->get($bits[0])) {
248 $this->jerr("invalid id"); // should not happen!!!!
251 $u->setPassword($r['passwd1']);