MTrackWeb/Gitlive.php
[web.mtrack] / MTrackWeb / Gitlive.php
1 <?php
2
3 /**
4  * JSON api for gitlive desktop application
5  */
6 require_once 'MTrackWeb.php';
7 class MTrackWeb_Gitlive extends MTrackWeb
8 {
9     function h401()
10     {
11         header('WWW-Authenticate: Basic realm="Gitlive"');
12         header('HTTP/1.0 401 Unauthorized');
13         echo 'Needs data!';
14         exit;
15     }
16     function getAuth()
17     {
18         if (!isset($_SERVER['PHP_AUTH_USER'])) {
19             $this->h401();
20         } 
21         $u = DB_DataObject::factory('Person');
22         //$u->active = 1;
23         $u->whereAdd('LENGTH(passwd) > 1');
24         //$u->company_id = $this->company->id;
25          
26         $u->email = $_SERVER['PHP_AUTH_USER'];
27         if ($u->count() > 1 || !$u->find(true)) {
28             $this->h401();
29             
30         }
31         
32         //if (!$u->active) {
33         //    return $this->errmsg('disabled');
34         //}
35         
36         if ($u->checkPassword($_SERVER['PHP_AUTH_PW'])) {
37             $u->login();
38             $this->authUser = $u;
39             // we do not log automated???
40             return true;
41
42             //exit;
43         }    
44             
45             
46     }
47     
48     function get($repo) {
49         
50         $r = DB_DataObject::factory('mtrack_repos');
51         if (!$r->get('shortname', $repo)) {
52             $this->jerr("invalid repo");
53         }
54         // make sure it's a valid project..
55         if (!$this->projectPerm($r->project_id, 'MTrack.Issue', 'S')) {
56             $this->jerr("no perms");
57         }
58         
59         
60         
61         $this->jok("WORKED!");
62         
63     }
64     
65 }