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);
123 $u->whereAdd('LENGTH(passwd) > 1');
124 //$u->company_id = $this->company->id;
126 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
127 $this->jerr('You typed the wrong Username or Password (0)');
131 $u->email = $_REQUEST['username'];
132 if ($u->count() > 1 || !$u->find(true)) {
133 $this->jerr('You typed the wrong Username or Password (1)');
138 $this->jerr('Account disabled');
141 if ($u->checkPassword($_REQUEST['password'])) {
143 $this->AddEvent("LOGIN");
144 if (!empty($_REQUEST['lang']) && $_REQUEST['lang'] != $u->lang) {
146 $uu->lang = $_REQUEST['lang'];
151 $this->sendAuthUserDetails();
158 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
162 function passwordRequest($n)
164 $u = DB_DataObject::factory('Person');
165 //$u->company_id = $this->company->id;
167 $u->whereAdd('LENGTH(passwd) > 1');
170 if ($u->count() > 1 || !$u->find(true)) {
171 $this->jerr('invalid User (1)');
173 // got a avlid user..
174 if (!strlen($u->passwd)) {
175 $this->jerr('invalid User (2)');
177 // check to see if we have sent a request before..
179 if ($u->no_reset_sent > 3) {
180 $this->jerr('We have issued to many resets - please contact the Administrator');
182 $this->authFrom = time();
183 $this->authKey = $u->genPassKey($this->authFrom);
184 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
186 $ret = $u->sendTemplate('password_reset', $this);
187 if (is_object($ret)) {
188 $this->addEvent('SYSERR',false, $ret->getMessage());
189 $this->jerr($ret->getMessage());
191 $this->addEvent('PASSREQ',$u, $u->email);
193 $uu->no_reset_sent++;
199 function changePassword($r)
201 $au = $this->getAuthUser();
204 $au->setPassword($r['passwd1']);
208 // not logged in -> need to validate
209 if (empty($r['passwordReset'])) {
210 $this->jerr("invalid request");
212 // same code as reset pasword
214 $bits = explode('/', $r['passwordReset']);
217 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
219 if ($res !== false) {
222 // key is correct.. let's change password...
224 $u = DB_DataObject::factory('Person');
226 //$u->company_id = $this->company->id;
227 $u->whereAdd('LENGTH(passwd) > 1');
229 if (!$u->get($bits[0])) {
230 $this->jerr("invalid id"); // should not happen!!!!
233 $u->setPassword($r['passwd1']);