php8
[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('core_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              
76             $this->authUser= $u;
77             $p = DB_DataObject::factory('core_project');
78             $p->get($this->currentProject());
79             $ret = $u->toArray();
80             $ret['project'] = $p->toArray();
81             $this->jok($ret);
82              
83             
84             //$this->sendAuthUserDetails();
85             exit;
86
87             //exit;
88         }
89         
90          
91         $this->jerr('Bad Username / Password combination'); // - " . htmlspecialchars(print_r($_POST,true))."'");
92         
93     }
94     
95     
96     
97     
98 }