3 require_once 'Pman.php';
5 class Pman_Login extends Pman
8 var $masterTemplate = 'login.html';
10 function getAuth() // everyone allowed in here..
12 parent::getAuth(); // load company..
28 if (!empty($_REQUEST['logout'])) {
29 $u = $this->getAuthUser();
32 $this->addEvent('LOGOUT');
37 $_SESSION['Pman_I18N'] = array();
42 if (!empty($_REQUEST['getAuthUser'])) {
43 $this->sendAuthUserDetails();
47 if (!empty($_REQUEST['username'])) {
50 $this->jerr("INVALID REQUEST");
54 function sendAuthUserDetails()
57 $ff = HTML_FlexyFramework::get();
58 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
60 $u = DB_DataObject::factory($tbl);
62 $this->jok(array('id' => 0)); // not logged in..
65 $au = $u->getAuthUser();
67 $aur = $au->authUserArray();
69 /** -- these need modulizing somehow! **/
71 if ($this->hasModule('Fax')) {
72 // should check fax module???
73 $f = DB_DataObject::factory('Fax_Queue');
74 $aur['faxMax'] = $f->getMaxId();
75 $aur['faxNumPending'] = $f->getNumPending();
78 if ($this->hasModule('Documents')) {
80 $d = DB_DataObject::factory('Documents_Tracking');
81 $d->person_id = $au->id;
82 //$d->status = 0; // unread
83 $d->whereAdd('date_read IS NULL');
84 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
85 $aur['inbox_unread'] = $d->count();
88 //echo '<PRE>';print_r($aur);
101 if (!empty($_REQUEST['getAuthUser'])) {
102 $this->sendAuthUserDetails();
107 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
109 return $this->passwordRequest($_REQUEST['passwordRequest']);
113 if (!empty($_REQUEST['changePassword'])) {
114 return $this->changePassword($_REQUEST);
117 $ff = HTML_FlexyFramework::get();
118 $tbl = empty($ff->Pman['authTable']) ? 'Person' : $ff->Pman['authTable'];
121 $u = DB_DataObject::factory($tbl);
125 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
126 $this->jerr('You typed the wrong Username or Password (0)');
130 $u->whereAdd('LENGTH(passwd) > 1');
131 $u->email = $_REQUEST['username'];
133 if ($u->count() > 1 || !$u->find(true)) {
134 $this->jerr('You typed the wrong Username or Password (1)');
139 $this->jerr('Account disabled');
142 if ($u->checkPassword($_REQUEST['password'])) {
144 $this->AddEvent("LOGIN");
145 if (!empty($_REQUEST['lang']) && $_REQUEST['lang'] != $u->lang) {
147 $uu->lang = $_REQUEST['lang'];
152 $this->sendAuthUserDetails();
159 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
163 function passwordRequest($n)
165 $u = DB_DataObject::factory('Person');
166 //$u->company_id = $this->company->id;
168 $u->whereAdd('LENGTH(passwd) > 1');
171 if ($u->count() > 1 || !$u->find(true)) {
172 $this->jerr('invalid User (1)');
174 // got a avlid user..
175 if (!strlen($u->passwd)) {
176 $this->jerr('invalid User (2)');
178 // check to see if we have sent a request before..
180 if ($u->no_reset_sent > 3) {
181 $this->jerr('We have issued to many resets - please contact the Administrator');
183 $this->authFrom = time();
184 $this->authKey = $u->genPassKey($this->authFrom);
185 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
187 $ret = $u->sendTemplate('password_reset', $this);
188 if (is_object($ret)) {
189 $this->addEvent('SYSERR',false, $ret->getMessage());
190 $this->jerr($ret->getMessage());
192 $this->addEvent('PASSREQ',$u, $u->email);
194 $uu->no_reset_sent++;
200 function changePassword($r)
202 $au = $this->getAuthUser();
205 $au->setPassword($r['passwd1']);
209 // not logged in -> need to validate
210 if (empty($r['passwordReset'])) {
211 $this->jerr("invalid request");
213 // same code as reset pasword
215 $bits = explode('/', $r['passwordReset']);
218 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
220 if ($res !== false) {
223 // key is correct.. let's change password...
225 $u = DB_DataObject::factory('Person');
227 //$u->company_id = $this->company->id;
228 $u->whereAdd('LENGTH(passwd) > 1');
230 if (!$u->get($bits[0])) {
231 $this->jerr("invalid id"); // should not happen!!!!
234 $u->setPassword($r['passwd1']);