class MTrackWeb_Login extends MTrackWeb
{
- var $template = 'login.html';
-
+
function getAuth()
{
return true;
function get($u='', $ar=array())
{
- if (!isset($_REQUEST['ajax_body'])) {
- $this->title = "Login";
- return;
- }
- $this->masterTemplate = 'login.html';
-
- if (!empty($u)) {
- /** ---------- reset passwords ----- */
- $uu = explode('/', $u);
- if ($uu[0] != 'Reset') {
- $this->err('404', 'Invalid URL');
- }
- $u = DB_DataObject::factory('Person');
- if (!$u->get($uu[1])) {
- $this->err('404', 'Invalid URL');
- }
- $uu[2] = (int) $uu[2];
-
- if ($uu[2] < (time() - (60 * 60 * 24 * 2))) { // older than 2 days.
- HTML_FlexyFramework::run('ForgotPassword', array('errors' => array('reset_expired' => 1)));
- exit;
- }
- // print_R($u->genPassKey($uu[2]));
- if ($uu[3] != $u->genPassKey($uu[2])) {
- HTML_FlexyFramework::run('ForgotPassword', array('errors' => array('reset_invalid' => 1)));
- exit;
- }
- // do reset!!!.
-
- $pp = clone($u);
- $u->generatePassword();
- $u->update($pp);
- $u->sendTemplate('reset_password', $this);
-
- $this->warnings = array('password_sent' => true);
-
- }
-
- if (!empty($ar)) {
- foreach($ar as $k=>$v) {
- $this->$k = $v;
- }
- }
-
-
if (!empty($_REQUEST['logout'])) {
if ($this->getAuthUser()) {
$this->getAuthUser()->logout();
}
- HTML_FlexyFramework::run(''); //
-
+ header('location: ' . $this->baseURL);
+ exit;
- }
-
- if (!empty($_POST)) {
- require_once 'HTML/Template/Flexy/Factory.php';
- $this->elements = HTML_Template_Flexy_Factory::fromArray ( $_POST ,$this->elements);
}
-
+
+ $this->jerr("invalid url");
return;
}
function errmsg($str) {
- $this->errors[$str] = 1;
- return true;
+
+ return $this->jerr($str);
}
-
- function post()
+ /**
+ * AJAX ONLY?
+ */
+ function post($request)
{
- $u = DB_DataObject::factory('Person');
+ if (!empty($_POST['refresh'])) {
+ @session_start();
+ $this->jok("refreshed");
+ }
+
+ $u = DB_DataObject::factory('core_person');
//$u->active = 1;
$u->whereAdd('LENGTH(passwd) > 1');
//$u->company_id = $this->company->id;
if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
- return $this->errmsg('bad_1');
+ $this->jerr('Missing username');
}
$u->email = $_REQUEST['username'];
if ($u->count() > 1 || !$u->find(true)) {
- return $this->errmsg('bad_2');
+ $this->jerr('Bad Username / Password combination');
}
// $uu->update();
//}
// log it..
- HTML_FlexyFramework::run(''); //
+
+ $this->authUser= $u;
+ $p = DB_DataObject::factory('core_project');
+ $p->get($this->currentProject());
+ $ret = $u->toArray();
+ $ret['project'] = $p->toArray();
+ $this->jok($ret);
+
//$this->sendAuthUserDetails();
exit;
}
- return $this->errmsg('bad_3'); // - " . htmlspecialchars(print_r($_POST,true))."'");
+ $this->jerr('Bad Username / Password combination'); // - " . htmlspecialchars(print_r($_POST,true))."'");
}