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'])) {
23 class Pman_Login extends Pman
26 var $masterTemplate = 'login.html';
28 function getAuth() // everyone allowed in here..
30 parent::getAuth(); // load company..
46 if (!empty($_REQUEST['logout'])) {
47 $u = $this->getAuthUser();
50 $this->addEvent('LOGOUT');
55 $_SESSION['Pman_I18N'] = array();
60 if (!empty($_REQUEST['getAuthUser'])) {
61 $this->sendAuthUserDetails();
65 if (!empty($_REQUEST['username'])) {
68 $this->jerr("INVALID REQUEST");
72 function sendAuthUserDetails()
75 $ff = HTML_FlexyFramework::get();
76 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
78 $u = DB_DataObject::factory($tbl);
80 $this->jok(array('id' => 0)); // not logged in..
83 $au = $u->getAuthUser();
85 $aur = $au->authUserArray();
87 /** -- these need modulizing somehow! **/
89 if ($this->hasModule('Fax')) {
90 // should check fax module???
91 $f = DB_DataObject::factory('Fax_Queue');
92 $aur['faxMax'] = $f->getMaxId();
93 $aur['faxNumPending'] = $f->getNumPending();
96 if ($this->hasModule('Documents')) {
98 $d = DB_DataObject::factory('Documents_Tracking');
99 $d->person_id = $au->id;
100 //$d->status = 0; // unread
101 $d->whereAdd('date_read IS NULL');
102 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
103 $aur['inbox_unread'] = $d->count();
106 //echo '<PRE>';print_r($aur);
119 if (!empty($_REQUEST['getAuthUser'])) {
120 $this->sendAuthUserDetails();
125 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
127 return $this->passwordRequest($_REQUEST['passwordRequest']);
131 if (!empty($_REQUEST['changePassword'])) {
132 return $this->changePassword($_REQUEST);
135 $ff = HTML_FlexyFramework::get();
136 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
139 $u = DB_DataObject::factory($tbl);
143 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
144 $this->jerr('You typed the wrong Username or Password (0)');
148 $u->authUserName($_REQUEST['username']);
151 if ($u->count() > 1 || !$u->find(true)) {
152 $this->jerr('You typed the wrong Username or Password (1)');
157 $this->jerr('Account disabled');
160 if ($u->checkPassword($_REQUEST['password'])) {
162 $this->AddEvent("LOGIN");
163 if (!empty($_REQUEST['lang']) && $_REQUEST['lang'] != $u->lang) {
165 $uu->lang = $_REQUEST['lang'];
170 $this->sendAuthUserDetails();
177 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
181 function passwordRequest($n)
183 $u = DB_DataObject::factory('Person');
184 //$u->company_id = $this->company->id;
186 $u->whereAdd('LENGTH(passwd) > 1');
189 if ($u->count() > 1 || !$u->find(true)) {
190 $this->jerr('invalid User (1)');
192 // got a avlid user..
193 if (!strlen($u->passwd)) {
194 $this->jerr('invalid User (2)');
196 // check to see if we have sent a request before..
198 if ($u->no_reset_sent > 3) {
199 $this->jerr('We have issued to many resets - please contact the Administrator');
201 $this->authFrom = time();
202 $this->authKey = $u->genPassKey($this->authFrom);
203 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
205 $ret = $u->sendTemplate('password_reset', $this);
206 if (is_object($ret)) {
207 $this->addEvent('SYSERR',false, $ret->getMessage());
208 $this->jerr($ret->getMessage());
210 $this->addEvent('PASSREQ',$u, $u->email);
212 $uu->no_reset_sent++;
218 function changePassword($r)
220 $au = $this->getAuthUser();
223 $au->setPassword($r['passwd1']);
227 // not logged in -> need to validate
228 if (empty($r['passwordReset'])) {
229 $this->jerr("invalid request");
231 // same code as reset pasword
233 $bits = explode('/', $r['passwordReset']);
236 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
238 if ($res !== false) {
241 // key is correct.. let's change password...
243 $u = DB_DataObject::factory('Person');
245 //$u->company_id = $this->company->id;
246 $u->whereAdd('LENGTH(passwd) > 1');
248 if (!$u->get($bits[0])) {
249 $this->jerr("invalid id"); // should not happen!!!!
252 $u->setPassword($r['passwd1']);