MTrackWeb/Login.php
[web.mtrack] / MTrackWeb / Login.php
1 <?php
2
3 require_once 'MTrackWeb.php';
4
5
6 class MTrackWeb_Login extends MTrackWeb
7 {
8      
9     function getAuth()
10     {
11         return true;
12     }
13     
14     function get($u='', $ar=array())
15     {
16         
17         if (!empty($_REQUEST['logout'])) {
18             if ($this->getAuthUser()) {
19                 $this->getAuthUser()->logout();
20             }
21             header('location: ' . $this->baseURL);
22             exit;
23             
24             
25         }
26          
27         $this->jerr("invalid url");
28         return;
29     }
30     function errmsg($str) {
31         
32         return $this->jerr($str);
33         
34     }
35     /**
36      * AJAX ONLY?
37      */
38     function post()
39     {
40         
41         if (!empty($_POST['refresh'])) {
42             @session_start();
43             $this->jok("refreshed");
44         }
45         
46         $u = DB_DataObject::factory('Person');
47         //$u->active = 1;
48         $u->whereAdd('LENGTH(passwd) > 1');
49         //$u->company_id = $this->company->id;
50         
51         if (empty($_REQUEST['username'])) { //|| (strpos($_REQUEST['username'], '@') < 1)) {
52              $this->jerr('Missing username');
53             
54         }
55          
56         $u->email = $_REQUEST['username'];
57         if ($u->count() > 1 || !$u->find(true)) {
58            $this->jerr('Bad Username / Password combination');
59             
60         }
61         
62         //if (!$u->active) {
63         //    return $this->errmsg('disabled');
64         //}
65         
66         if ($u->checkPassword($_REQUEST['password'])) {
67             $u->login();
68             $this->addEvent("LOGIN");
69             //if (!empty($_REQUEST['lang']) && $_REQUEST['lang'] != $u->lang) {
70             //    $uu = clone($u);
71             ////    $uu->lang = $_REQUEST['lang'];
72             //    $uu->update();
73             //}
74              // log it..
75              $this->jok($u->toArray());
76              
77             HTML_FlexyFramework::run(''); // 
78             
79             //$this->sendAuthUserDetails();
80             exit;
81
82             //exit;
83         }
84         
85          
86         $this->jerr('Bad Username / Password combination'); // - " . htmlspecialchars(print_r($_POST,true))."'");
87         
88     }
89     
90     
91     
92     
93 }