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());
56 $_SESSION['Pman_I18N'] = array();
61 if (!empty($_REQUEST['getAuthUser'])) {
62 //DB_Dataobject::debugLevel(5);
63 $this->sendAuthUserDetails();
67 if (!empty($_REQUEST['username'])) {
70 $this->jerr("INVALID REQUEST");
74 function sendAuthUserDetails()
76 // DB_DataObject::debugLevel(1);
77 $ff = HTML_FlexyFramework::get();
78 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
80 $u = DB_DataObject::factory($tbl);
82 $this->jok(array('id' => 0)); // not logged in..
85 $au = $u->getAuthUser();
87 $aur = $au->authUserArray();
89 /** -- these need modulizing somehow! **/
91 if ($this->hasModule('Fax')) {
92 // should check fax module???
93 $f = DB_DataObject::factory('Fax_Queue');
94 $aur['faxMax'] = $f->getMaxId();
95 $aur['faxNumPending'] = $f->getNumPending();
98 if ($this->hasModule('Documents')) {
100 $d = DB_DataObject::factory('Documents_Tracking');
101 $d->person_id = $au->id;
102 //$d->status = 0; // unread
103 $d->whereAdd('date_read IS NULL');
104 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
105 $aur['inbox_unread'] = $d->count();
108 //echo '<PRE>';print_r($aur);
120 //DB_DataObject::debugLevel(1);
121 if (!empty($_REQUEST['getAuthUser'])) {
122 $this->sendAuthUserDetails();
127 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
129 return $this->passwordRequest($_REQUEST['passwordRequest']);
133 if (!empty($_REQUEST['changePassword'])) {
134 return $this->changePassword($_REQUEST);
139 $ff = HTML_FlexyFramework::get();
140 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
143 $u = DB_DataObject::factory($tbl);
147 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
148 $this->jerr('You typed the wrong Username or Password (0)');
152 $u->authUserName($_REQUEST['username']);
155 if ($u->count() > 1 || !$u->find(true)) {
156 $this->jerr('You typed the wrong Username or Password (1)');
161 $this->jerr('Account disabled');
164 if ($u->checkPassword($_REQUEST['password'])) {
166 $this->addEvent("LOGIN", false, session_id());
167 if (!empty($_REQUEST['lang'])) {
168 $u->lang($_REQUEST['lang']);
172 $this->sendAuthUserDetails();
179 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
183 function passwordRequest($n)
185 $u = DB_DataObject::factory('Person');
186 //$u->company_id = $this->company->id;
188 $u->whereAdd('LENGTH(passwd) > 1');
191 if ($u->count() > 1 || !$u->find(true)) {
192 $this->jerr('invalid User (1)');
194 // got a avlid user..
195 if (!strlen($u->passwd)) {
196 $this->jerr('invalid User (2)');
198 // check to see if we have sent a request before..
200 if ($u->no_reset_sent > 3) {
201 $this->jerr('We have issued to many resets - please contact the Administrator');
203 $this->authFrom = time();
204 $this->authKey = $u->genPassKey($this->authFrom);
205 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
207 $ret = $u->sendTemplate('password_reset', $this);
208 if (is_object($ret)) {
209 $this->addEvent('SYSERR',false, $ret->getMessage());
210 $this->jerr($ret->getMessage());
212 $this->addEvent('PASSREQ',$u, $u->email);
214 $uu->no_reset_sent++;
220 function changePassword($r)
222 $au = $this->getAuthUser();
225 $au->setPassword($r['passwd1']);
229 // not logged in -> need to validate
230 if (empty($r['passwordReset'])) {
231 $this->jerr("invalid request");
233 // same code as reset pasword
235 $bits = explode('/', $r['passwordReset']);
238 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
240 if ($res !== false) {
243 // key is correct.. let's change password...
245 $u = DB_DataObject::factory('Person');
247 //$u->company_id = $this->company->id;
248 $u->whereAdd('LENGTH(passwd) > 1');
250 if (!$u->get($bits[0])) {
251 $this->jerr("invalid id"); // should not happen!!!!
254 $u->setPassword($r['passwd1']);