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 // i18n language and coutry lists.
72 $lang = empty($au->lang) ? 'en' : $au->lang;
73 if (empty($_SESSION['Pman_I18N'][$lang])) {
74 require_once 'Pman/I18N.php';
80 $aur['i18n'] =$_SESSION['Pman_I18N'][$lang];
83 $aur['perms'] = $au->getPerms();
84 $g = DB_DataObject::Factory('Group_Members');
85 $aur['groups'] = $g->listGroupMembership($au, 'name');
88 $aur['dailykey'] = '';
90 /** -- these need modulizing somehow! **/
92 if ($this->hasModule('Fax')) {
93 // should check fax module???
94 $f = DB_DataObject::factory('Fax_Queue');
95 $aur['faxMax'] = $f->getMaxId();
96 $aur['faxNumPending'] = $f->getNumPending();
99 if ($this->hasModule('Documents')) {
101 $d = DB_DataObject::factory('Documents_Tracking');
102 $d->person_id = $au->id;
103 //$d->status = 0; // unread
104 $d->whereAdd('date_read IS NULL');
105 $d->applyFilters(array('query'=> array('unread' => 1)), $au);
106 $aur['inbox_unread'] = $d->count();
109 //echo '<PRE>';print_r($aur);
122 if (!empty($_REQUEST['passwordRequest'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
124 return $this->passwordRequest($_REQUEST['passwordRequest']);
128 if (!empty($_REQUEST['changePassword'])) {
129 return $this->changePassword($_REQUEST);
133 $u = DB_DataObject::factory('Person');
135 $u->whereAdd('LENGTH(passwd) > 1');
136 //$u->company_id = $this->company->id;
138 if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
139 $this->jerr('You typed the wrong Username or Password (0)');
143 $u->email = $_REQUEST['username'];
144 if ($u->count() > 1 || !$u->find(true)) {
145 $this->jerr('You typed the wrong Username or Password (1)');
150 $this->jerr('Account disabled');
153 if ($u->checkPassword($_REQUEST['password'])) {
155 $this->AddEvent("LOGIN");
156 if (!empty($_REQUEST['lang']) && $_REQUEST['lang'] != $u->lang) {
158 $uu->lang = $_REQUEST['lang'];
163 $this->sendAuthUserDetails();
170 $this->jerr('You typed the wrong Username or Password (2)'); // - " . htmlspecialchars(print_r($_POST,true))."'");
174 function passwordRequest($n)
176 $u = DB_DataObject::factory('Person');
177 //$u->company_id = $this->company->id;
179 $u->whereAdd('LENGTH(passwd) > 1');
182 if ($u->count() > 1 || !$u->find(true)) {
183 $this->jerr('invalid User (1)');
185 // got a avlid user..
186 if (!strlen($u->passwd)) {
187 $this->jerr('invalid User (2)');
189 // check to see if we have sent a request before..
191 if ($u->no_reset_sent > 3) {
192 $this->jerr('We have issued to many resets - please contact the Administrator');
194 $this->authFrom = time();
195 $this->authKey = $u->genPassKey($this->authFrom);
196 $this->authKey = md5($u->email . $this->authFrom . $u->passwd);
198 $ret = $u->sendTemplate('password_reset', $this);
199 if (is_object($ret)) {
200 $this->addEvent('SYSERR',false, $ret->getMessage());
201 $this->jerr($ret->getMessage());
203 $this->addEvent('PASSREQ',$u, $u->email);
205 $uu->no_reset_sent++;
211 function changePassword($r)
213 $au = $this->getAuthUser();
216 $au->setPassword($r['passwd1']);
220 // not logged in -> need to validate
221 if (empty($r['passwordReset'])) {
222 $this->jerr("invalid request");
224 // same code as reset pasword
226 $bits = explode('/', $r['passwordReset']);
229 $res= $this->resetPassword(@$bits[0],@$bits[1],@$bits[2]);
231 if ($res !== false) {
234 // key is correct.. let's change password...
236 $u = DB_DataObject::factory('Person');
238 //$u->company_id = $this->company->id;
239 $u->whereAdd('LENGTH(passwd) > 1');
241 if (!$u->get($bits[0])) {
242 $this->jerr("invalid id"); // should not happen!!!!
245 $u->setPassword($r['passwd1']);