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();
52 $this->addEvent('LOGOUT');
53 $e = DB_DataObject::factory('Events');
55 session_regenerate_id(true);
60 $_SESSION['Pman_I18N'] = array();
65 if (!empty($_REQUEST['getAuthUser'])) {
66 //DB_Dataobject::debugLevel(5);
67 $this->sendAuthUserDetails();
71 if (!empty($_REQUEST['username'])) {
74 $this->jerr("INVALID REQUEST");
78 function sendAuthUserDetails()
80 // DB_DataObject::debugLevel(1);
81 $ff = HTML_FlexyFramework::get();
82 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
84 $u = DB_DataObject::factory($tbl);
86 $this->jok(array('id' => 0)); // not logged in..
89 $au = $u->getAuthUser();
91 $aur = $au->authUserArray();
93 /** -- these need modulizing somehow! **/
95 if ($this->hasModule('Fax')) {
96 // should check fax module???
97 $f = DB_DataObject::factory('Fax_Queue');
98 $aur['faxMax'] = $f->getMaxId();
99 $aur['faxNumPending'] = $f->getNumPending();
102 if ($this->hasModule('Documents')) {
104 $d = DB_DataObject::factory('Documents_Tracking');
105 $d->person_id = $au->id;
106 //$d->status = 0; // unread
107 $d->whereAdd('date_read IS NULL');
108 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
109 $aur['inbox_unread'] = $d->count();
112 //echo '<PRE>';print_r($aur);
124 //DB_DataObject::debugLevel(1);
125 if (!empty($_REQUEST['getAuthUser'])) {
126 $this->sendAuthUserDetails();
131 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
133 return $this->passwordRequest($_REQUEST['passwordRequest']);
137 if (!empty($_REQUEST['changePassword'])) {
138 return $this->changePassword($_REQUEST);
143 $ff = HTML_FlexyFramework::get();
144 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
147 $u = DB_DataObject::factory($tbl);
151 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
152 $this->jerr('You typed the wrong Username or Password (0)');
156 $u->authUserName($_REQUEST['username']);
159 if ($u->count() > 1 || !$u->find(true)) {
160 $this->jerr('You typed the wrong Username or Password (1)');
165 $this->jerr('Account disabled');
168 if ($u->checkPassword($_REQUEST['password'])) {
170 // we might need this later..
171 $this->addEvent("LOGIN", false, session_id());
172 if (!empty($_REQUEST['lang'])) {
173 $u->lang($_REQUEST['lang']);
177 $this->sendAuthUserDetails();
184 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
188 function passwordRequest($n)
190 $u = DB_DataObject::factory('Person');
191 //$u->company_id = $this->company->id;
193 $u->whereAdd('LENGTH(passwd) > 1');
196 if ($u->count() > 1 || !$u->find(true)) {
197 $this->jerr('invalid User (1)');
199 // got a avlid user..
200 if (!strlen($u->passwd)) {
201 $this->jerr('invalid User (2)');
203 // check to see if we have sent a request before..
205 if ($u->no_reset_sent > 3) {
206 $this->jerr('We have issued to many resets - please contact the Administrator');
208 $this->authFrom = time();
209 $this->authKey = $u->genPassKey($this->authFrom);
210 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
212 $ret = $u->sendTemplate('password_reset', $this);
213 if (is_object($ret)) {
214 $this->addEvent('SYSERR',false, $ret->getMessage());
215 $this->jerr($ret->getMessage());
217 $this->addEvent('PASSREQ',$u, $u->email);
219 $uu->no_reset_sent++;
225 function changePassword($r)
227 $au = $this->getAuthUser();
230 $au->setPassword($r['passwd1']);
234 // not logged in -> need to validate
235 if (empty($r['passwordReset'])) {
236 $this->jerr("invalid request");
238 // same code as reset pasword
240 $bits = explode('/', $r['passwordReset']);
243 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
245 if ($res !== false) {
248 // key is correct.. let's change password...
250 $u = DB_DataObject::factory('Person');
252 //$u->company_id = $this->company->id;
253 $u->whereAdd('LENGTH(passwd) > 1');
255 if (!$u->get($bits[0])) {
256 $this->jerr("invalid id"); // should not happen!!!!
259 $u->setPassword($r['passwd1']);