Completed
Branch master (1459ee)
by David
15:32
created
app/Console/Commands/BaseCommand.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,6 @@
 block discarded – undo
1 1
 <?php namespace App\Console\Commands;
2 2
 
3 3
 use Illuminate\Console\Command;
4
-use Symfony\Component\Console\Input\InputOption;
5
-use Symfony\Component\Console\Input\InputArgument;
6 4
 
7 5
 class BaseCommand extends Command {
8 6
 
Please login to merge, or discard this patch.
app/Console/Commands/Generic.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php namespace App\Console\Commands;
2 2
 
3 3
 use App\Console\Commands\BaseCommand;
4
-use Symfony\Component\Console\Input\InputOption;
5 4
 use Symfony\Component\Console\Input\InputArgument;
6 5
 
7 6
 class Generic extends BaseCommand {
Please login to merge, or discard this patch.
app/Http/Controllers/API/V1/ApiController.php 3 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -4,10 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use Illuminate\Database\Eloquent\ModelNotFoundException;
6 6
 use Illuminate\Contracts\Validation\ValidationException;
7
-use Illuminate\Foundation\Bus\DispatchesCommands;
8
-use Illuminate\Foundation\Validation\ValidatesRequests;
9
-use Illuminate\Routing\Controller as BaseController;
10
-
11 7
 use Chrisbjr\ApiGuard\Http\Controllers\ApiGuardController;
12 8
 
13 9
 abstract class ApiController extends ApiGuardController
Please login to merge, or discard this patch.
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -12,162 +12,162 @@
 block discarded – undo
12 12
 
13 13
 abstract class ApiController extends ApiGuardController
14 14
 {
15
-    /**
16
-     * Laraponse object, which abstracts Fractal
17
-     * 
18
-     * @var EllipseSynergie\ApiResponse\Laravel\Response
19
-     */
20
-    public $response;
15
+	/**
16
+	 * Laraponse object, which abstracts Fractal
17
+	 * 
18
+	 * @var EllipseSynergie\ApiResponse\Laravel\Response
19
+	 */
20
+	public $response;
21 21
     
22
-    /**
23
-     * The string name of the Eloquen Model
24
-     * 
25
-     * @var string
26
-     */
27
-    protected $modelName;
22
+	/**
23
+	 * The string name of the Eloquen Model
24
+	 * 
25
+	 * @var string
26
+	 */
27
+	protected $modelName;
28 28
     
29
-    /**
30
-     * The Eloquent Model
31
-     * 
32
-     * @var Illuminate\Database\Eloquent\Model
33
-     */
34
-    protected $model;
29
+	/**
30
+	 * The Eloquent Model
31
+	 * 
32
+	 * @var Illuminate\Database\Eloquent\Model
33
+	 */
34
+	protected $model;
35 35
     
36
-    /**
37
-     * The string name of the Transformer class
38
-     * 
39
-     * @var string
40
-     */
41
-    protected $transformerName;
36
+	/**
37
+	 * The string name of the Transformer class
38
+	 * 
39
+	 * @var string
40
+	 */
41
+	protected $transformerName;
42 42
     
43
-    /**
44
-     * The name of the collection that is returned in the JSON response
45
-     * 
46
-     * @var string
47
-     */
48
-    protected $collectionName;
43
+	/**
44
+	 * The name of the collection that is returned in the JSON response
45
+	 * 
46
+	 * @var string
47
+	 */
48
+	protected $collectionName;
49 49
     
50
-    /**
51
-     * The Fractal Manager
52
-     * 
53
-     * @var \League\Fractal\Manager
54
-     */
55
-    public $manager;
56
-
57
-
58
-    /**
59
-     * Constructor
60
-     */
61
-    public function __construct()
62
-    {
63
-        $this->response =  \Response::api();
50
+	/**
51
+	 * The Fractal Manager
52
+	 * 
53
+	 * @var \League\Fractal\Manager
54
+	 */
55
+	public $manager;
56
+
57
+
58
+	/**
59
+	 * Constructor
60
+	 */
61
+	public function __construct()
62
+	{
63
+		$this->response =  \Response::api();
64 64
         
65
-        if (!empty($this->modelName)) {
66
-            $this->model = new $this->modelName;
67
-        }
68
-
69
-        // if no collection name provided, use the model's table name
70
-        if (empty($this->collectionName)) {
71
-            $this->collectionName = $this->model->getTable();
72
-        }
65
+		if (!empty($this->modelName)) {
66
+			$this->model = new $this->modelName;
67
+		}
68
+
69
+		// if no collection name provided, use the model's table name
70
+		if (empty($this->collectionName)) {
71
+			$this->collectionName = $this->model->getTable();
72
+		}
73 73
         
74
-        // parse includes
75
-        if (\Input::get('include') != '') {
76
-            $this->manager = new \League\Fractal\Manager;
77
-            $this->manager->parseIncludes(explode(',', \Input::get('include')));
78
-
79
-            //print_r($this->manager);exit;
80
-        }
81
-
82
-        parent::__construct();
83
-    }
84
-
85
-    /**
86
-     * Create an item
87
-     * 
88
-     * @return array
89
-     */
90
-    public function create($data = null)
91
-    {   
92
-        $data = $data ?: \Input::json()->all();
93
-
94
-        try {
95
-            $this->model->validate($data);
96
-            $item = $this->model->create($data);
74
+		// parse includes
75
+		if (\Input::get('include') != '') {
76
+			$this->manager = new \League\Fractal\Manager;
77
+			$this->manager->parseIncludes(explode(',', \Input::get('include')));
78
+
79
+			//print_r($this->manager);exit;
80
+		}
81
+
82
+		parent::__construct();
83
+	}
84
+
85
+	/**
86
+	 * Create an item
87
+	 * 
88
+	 * @return array
89
+	 */
90
+	public function create($data = null)
91
+	{   
92
+		$data = $data ?: \Input::json()->all();
93
+
94
+		try {
95
+			$this->model->validate($data);
96
+			$item = $this->model->create($data);
97 97
             
98
-            return $this->showByObject($item);
98
+			return $this->showByObject($item);
99 99
         
100
-        } catch (ValidationException $e) {
101
-            return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY');
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Returns a single item
107
-     * 
108
-     * @param  int $id
109
-     * @return \Illuminate\Http\JsonResponse
110
-     */
111
-    public function show($id)
112
-    {        
113
-        try {
100
+		} catch (ValidationException $e) {
101
+			return $this->response->setStatusCode(422)->withError($e->errors()->toArray(), 'GEN-UNPROCESSABLE-ENTITY');
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Returns a single item
107
+	 * 
108
+	 * @param  int $id
109
+	 * @return \Illuminate\Http\JsonResponse
110
+	 */
111
+	public function show($id)
112
+	{        
113
+		try {
114 114
             
115
-            return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName);
115
+			return $this->response->withItem($this->model->findOrFail($id), new $this->transformerName);
116 116
         
117
-        } catch (ModelNotFoundException $e) {
118
-
119
-            return $this->respondNotFound();
120
-        }
121
-    }
122
-
123
-    /**
124
-     * Returns a single item
125
-     * 
126
-     * @param  object $object
127
-     * @return \Illuminate\Http\JsonResponse
128
-     */
129
-    public function showByObject($object)
130
-    {        
131
-        try {
132
-            return $this->response->withItem($object, new $this->transformerName);
117
+		} catch (ModelNotFoundException $e) {
118
+
119
+			return $this->respondNotFound();
120
+		}
121
+	}
122
+
123
+	/**
124
+	 * Returns a single item
125
+	 * 
126
+	 * @param  object $object
127
+	 * @return \Illuminate\Http\JsonResponse
128
+	 */
129
+	public function showByObject($object)
130
+	{        
131
+		try {
132
+			return $this->response->withItem($object, new $this->transformerName);
133 133
         
134
-        } catch (ModelNotFoundException $e) {
135
-
136
-            return $this->respondNotFound();
137
-        }
138
-    }
139
-
140
-    /**
141
-     * Returns a paginated collection
142
-     * 
143
-     * @return \Illuminate\Http\JsonResponse
144
-     */
145
-    public function collection()
146
-    {
147
-        $limit = \Input::get('limit') ?: 10;
148
-        $model = $this->model;
134
+		} catch (ModelNotFoundException $e) {
135
+
136
+			return $this->respondNotFound();
137
+		}
138
+	}
139
+
140
+	/**
141
+	 * Returns a paginated collection
142
+	 * 
143
+	 * @return \Illuminate\Http\JsonResponse
144
+	 */
145
+	public function collection()
146
+	{
147
+		$limit = \Input::get('limit') ?: 10;
148
+		$model = $this->model;
149 149
         
150
-        if (\Request::has('order')) {
151
-            list($orderCol, $orderBy) = explode('|', \Input::get('order'));
152
-            $model = $model->orderBy($orderCol, $orderBy);
153
-        }
154
-
155
-        return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName);
156
-    }
157
-
158
-    /**
159
-     * Handles 404 errors
160
-     * 
161
-     * @param  string $msg
162
-     * @return \Illuminate\Http\JsonResponse
163
-     */
164
-    public function respondNotFound($msg = 'Not found!')
165
-    {
166
-        return \Response::json([
167
-            'error' => [
168
-                'message' => $msg,
169
-                'status_code' => 404
170
-            ]
171
-        ], 404);
172
-    }
150
+		if (\Request::has('order')) {
151
+			list($orderCol, $orderBy) = explode('|', \Input::get('order'));
152
+			$model = $model->orderBy($orderCol, $orderBy);
153
+		}
154
+
155
+		return $this->response->withPaginator($model->paginate($limit), new $this->transformerName, $this->collectionName);
156
+	}
157
+
158
+	/**
159
+	 * Handles 404 errors
160
+	 * 
161
+	 * @param  string $msg
162
+	 * @return \Illuminate\Http\JsonResponse
163
+	 */
164
+	public function respondNotFound($msg = 'Not found!')
165
+	{
166
+		return \Response::json([
167
+			'error' => [
168
+				'message' => $msg,
169
+				'status_code' => 404
170
+			]
171
+		], 404);
172
+	}
173 173
 }
174 174
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
      */
61 61
     public function __construct()
62 62
     {
63
-        $this->response =  \Response::api();
63
+        $this->response = \Response::api();
64 64
         
65 65
         if (!empty($this->modelName)) {
66 66
             $this->model = new $this->modelName;
Please login to merge, or discard this patch.
app/Http/Middleware/Cors.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,7 @@
 block discarded – undo
1 1
 <?php namespace App\Http\Middleware;
2 2
 
3 3
 use Closure;
4
-
5 4
 use Illuminate\Contracts\Routing\Middleware;
6
-use Illuminate\Http\Response;
7 5
 
8 6
 class Cors implements Middleware {
9 7
 
Please login to merge, or discard this patch.
app/LaravelRestCms/User/User.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@
 block discarded – undo
43 43
 	 * Relationship to the api_key table
44 44
 	 * 
45 45
 	 * @codeCoverageIgnore
46
-	 * @return Illuminate\Database\Eloquent\Relations\HasOne
46
+	 * @return \Illuminate\Database\Eloquent\Relations\HasOne
47 47
 	 */
48 48
 	public function apiKey()
49 49
 	{
Please login to merge, or discard this patch.
app/Library/Sftp.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -126,7 +126,6 @@
 block discarded – undo
126 126
     /**
127 127
      * Retrieves a listing from directory
128 128
      * 
129
-     * @param  string   $dir 
130 129
      * @return boolean  success
131 130
      */
132 131
     public function rename($remoteFileFrom, $remoteFileTo)
Please login to merge, or discard this patch.
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -7,153 +7,153 @@
 block discarded – undo
7 7
 class Sftp
8 8
 {
9 9
     
10
-    protected $connectionName;
11
-
12
-    /**
13
-     * Constructor
14
-     *
15
-     * @param string $connectionName
16
-     */
17
-    public function __construct($connectionName)
18
-    {
19
-        $this->connectionName = $connectionName;
20
-    }
21
-
22
-    /**
23
-     * Gets all XML files from a remote folder
24
-     * 
25
-     * @param  string $remoteDir 
26
-     * @param  string $localDir 
27
-     * @return array
28
-     */
10
+	protected $connectionName;
11
+
12
+	/**
13
+	 * Constructor
14
+	 *
15
+	 * @param string $connectionName
16
+	 */
17
+	public function __construct($connectionName)
18
+	{
19
+		$this->connectionName = $connectionName;
20
+	}
21
+
22
+	/**
23
+	 * Gets all XML files from a remote folder
24
+	 * 
25
+	 * @param  string $remoteDir 
26
+	 * @param  string $localDir 
27
+	 * @return array
28
+	 */
29 29
    	public function getFiles($remoteDir, $localDir)
30 30
    	{    	
31
-    	$files = $this->remoteListPackaged($remoteDir);
31
+		$files = $this->remoteListPackaged($remoteDir);
32 32
 
33
-    	foreach ($files as $file) {			
33
+		foreach ($files as $file) {			
34 34
 			$this->getFile($file['fullFileName'], $localDir . '/' . $file['fileName']);
35 35
 		}
36 36
 
37
-    	return $files;
37
+		return $files;
38 38
   	}
39 39
 
40
-    /**
41
-     * Gets all XML files from a remote folder
42
-     * 
43
-     * @param  string 	$dir 
44
-     * @param  bool     $sorted 
45
-     * @param  string   $sortOrder 
46
-     * @return array
47
-     */
40
+	/**
41
+	 * Gets all XML files from a remote folder
42
+	 * 
43
+	 * @param  string 	$dir 
44
+	 * @param  bool     $sorted 
45
+	 * @param  string   $sortOrder 
46
+	 * @return array
47
+	 */
48 48
    	public function remoteListPackaged($dir, $sorted = true, $sortOrder = 'desc')
49 49
    	{    	
50
-    	$files = [];
50
+		$files = [];
51 51
 		$all = $this->remoteList($dir, $sorted, $sortOrder);
52 52
 		
53
-        foreach ($all as $file=>$val) {
53
+		foreach ($all as $file=>$val) {
54 54
 			if ($this->isValidExtension($val['filename'])) {
55 55
 				$files[] = [
56
-                    'fileName' => $val['filename'], 
57
-                    'fullFileName' => $dir . '/' .$val['filename'],
58
-                    'size' => $val['size'],
59
-                    'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60
-                ];
56
+					'fileName' => $val['filename'], 
57
+					'fullFileName' => $dir . '/' .$val['filename'],
58
+					'size' => $val['size'],
59
+					'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60
+				];
61 61
 			}
62 62
 		}
63 63
 
64 64
 		return $files;
65
-    }
65
+	}
66 66
 
67
-    /**
68
-     * Retrieves a file from a SSH/SFTP server
69
-     * 
70
-     * @param  string $remoteFile 
71
-     * @param  string $localFile 
67
+	/**
68
+	 * Retrieves a file from a SSH/SFTP server
69
+	 * 
70
+	 * @param  string $remoteFile 
71
+	 * @param  string $localFile 
72 72
 	 * @return \Symfony\Component\Console\Output\OutputInterface
73
-     */
74
-    public function getFile($remoteFile, $localFile)
75
-    {	
76
-    	return \SSH::into($this->connectionName)->get($remoteFile, $localFile);    
77
-    }
78
-
79
-    /**
80
-     * Places a file on a remote SSH/SFTP server
81
-     * 
82
-     * @param  string $remoteFile 
83
-     * @param  string $localFile 
73
+	 */
74
+	public function getFile($remoteFile, $localFile)
75
+	{	
76
+		return \SSH::into($this->connectionName)->get($remoteFile, $localFile);    
77
+	}
78
+
79
+	/**
80
+	 * Places a file on a remote SSH/SFTP server
81
+	 * 
82
+	 * @param  string $remoteFile 
83
+	 * @param  string $localFile 
84 84
 	 * @return \Symfony\Component\Console\Output\OutputInterface
85
-     */
86
-    public function putFile($remoteFile, $localFile)
87
-    {
88
-    	return \SSH::into($this->connectionName)->put($localFile, $remoteFile);
89
-    }
90
-
91
-    /**
92
-     * Retrieves a listing from directory
93
-     * 
94
-     * @param  string 	$dir 
95
-     * @param  bool     $sorted 
96
-     * @param  string   $sortOrder 
85
+	 */
86
+	public function putFile($remoteFile, $localFile)
87
+	{
88
+		return \SSH::into($this->connectionName)->put($localFile, $remoteFile);
89
+	}
90
+
91
+	/**
92
+	 * Retrieves a listing from directory
93
+	 * 
94
+	 * @param  string 	$dir 
95
+	 * @param  bool     $sorted 
96
+	 * @param  string   $sortOrder 
97 97
 	 * @return array 	array of files and folders	
98
-     */
99
-    public function remoteList($dir, $sorted = true, $sortOrder = 'desc')
100
-    {
101
-    	$conn = $this->getConnection();
102
-    	$conn->chdir($dir);
103
-        $list = $conn->rawlist();
104
-
105
-        if ($sorted) {
106
-            $list = $this->sortList($list, $sortOrder);
107
-        }
98
+	 */
99
+	public function remoteList($dir, $sorted = true, $sortOrder = 'desc')
100
+	{
101
+		$conn = $this->getConnection();
102
+		$conn->chdir($dir);
103
+		$list = $conn->rawlist();
104
+
105
+		if ($sorted) {
106
+			$list = $this->sortList($list, $sortOrder);
107
+		}
108 108
     	
109
-    	return $list;    
110
-    }
111
-
112
-    /**
113
-     * Retrieves a listing from directory
114
-     * 
115
-     * @param  array    $list 
116
-     * @param  string   $sortOrder 
117
-     * @return array    sorted array of a folder
118
-     */
119
-    public function sortList($list, $sortOrder = 'desc')
120
-    {
121
-        usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); 
122
-
123
-        return $sortOrder == 'asc' ? $list : array_reverse($list);
124
-    }
125
-
126
-    /**
127
-     * Retrieves a listing from directory
128
-     * 
129
-     * @param  string   $dir 
130
-     * @return boolean  success
131
-     */
132
-    public function rename($remoteFileFrom, $remoteFileTo)
133
-    {
134
-        $conn = $this->getConnection();
135
-        //print $conn->getSFTPLog();;
136
-        return $conn->rename($remoteFileFrom, $remoteFileTo);
137
-    }
138
-
139
-    /**
140
-     * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
141
-     * 
142
-     * @return Net_SFTP connection
143
-     */
144
-    protected function getConnection()
145
-    {
146
-    	return \SSH::into($this->connectionName)->getGateway()->getConnection();
147
-    }
148
-
149
-    /**
150
-     * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
151
-     * 
152
-     * @param  string $fileName 
153
-     * @return bool 	
154
-     */
155
-    protected function isValidExtension($fileName)
156
-    {
157
-    	return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err';
158
-    }
109
+		return $list;    
110
+	}
111
+
112
+	/**
113
+	 * Retrieves a listing from directory
114
+	 * 
115
+	 * @param  array    $list 
116
+	 * @param  string   $sortOrder 
117
+	 * @return array    sorted array of a folder
118
+	 */
119
+	public function sortList($list, $sortOrder = 'desc')
120
+	{
121
+		usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); 
122
+
123
+		return $sortOrder == 'asc' ? $list : array_reverse($list);
124
+	}
125
+
126
+	/**
127
+	 * Retrieves a listing from directory
128
+	 * 
129
+	 * @param  string   $dir 
130
+	 * @return boolean  success
131
+	 */
132
+	public function rename($remoteFileFrom, $remoteFileTo)
133
+	{
134
+		$conn = $this->getConnection();
135
+		//print $conn->getSFTPLog();;
136
+		return $conn->rename($remoteFileFrom, $remoteFileTo);
137
+	}
138
+
139
+	/**
140
+	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
141
+	 * 
142
+	 * @return Net_SFTP connection
143
+	 */
144
+	protected function getConnection()
145
+	{
146
+		return \SSH::into($this->connectionName)->getGateway()->getConnection();
147
+	}
148
+
149
+	/**
150
+	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
151
+	 * 
152
+	 * @param  string $fileName 
153
+	 * @return bool 	
154
+	 */
155
+	protected function isValidExtension($fileName)
156
+	{
157
+		return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err';
158
+	}
159 159
 }
160 160
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			if ($this->isValidExtension($val['filename'])) {
55 55
 				$files[] = [
56 56
                     'fileName' => $val['filename'], 
57
-                    'fullFileName' => $dir . '/' .$val['filename'],
57
+                    'fullFileName' => $dir . '/' . $val['filename'],
58 58
                     'size' => $val['size'],
59 59
                     'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60 60
                 ];
@@ -154,6 +154,6 @@  discard block
 block discarded – undo
154 154
      */
155 155
     protected function isValidExtension($fileName)
156 156
     {
157
-    	return substr(strrchr($fileName,'.'),1) === 'xml' || substr(strrchr($fileName,'.'),1) === 'err';
157
+    	return substr(strrchr($fileName, '.'), 1) === 'xml' || substr(strrchr($fileName, '.'), 1) === 'err';
158 158
     }
159 159
 }
160 160
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/API/V1/UserController.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -10,129 +10,129 @@
 block discarded – undo
10 10
 
11 11
 class UserController extends ApiGuardController
12 12
 {
13
-    /**
14
-     * The name of the model to use for this package
15
-     * 
16
-     * @var string
17
-     */
18
-    protected $modelName = 'App\LaravelRestCms\User\User';
13
+	/**
14
+	 * The name of the model to use for this package
15
+	 * 
16
+	 * @var string
17
+	 */
18
+	protected $modelName = 'App\LaravelRestCms\User\User';
19 19
     
20
-    /**
21
-     * The name of the transformer to use for this package
22
-     * 
23
-     * @var string
24
-     */
25
-    protected $transformerName = 'App\LaravelRestCms\User\UserTransformer';
20
+	/**
21
+	 * The name of the transformer to use for this package
22
+	 * 
23
+	 * @var string
24
+	 */
25
+	protected $transformerName = 'App\LaravelRestCms\User\UserTransformer';
26 26
     
27
-    /**
28
-     * The key to use as a key for this collection in the output
29
-     * 
30
-     * @var string
31
-     */
32
-    protected $collectionName = 'users';
33
-
34
-    /**
35
-     * The methods that don't require api authentication
36
-     * 
37
-     * @var array
38
-     */
39
-    protected $apiMethods = [
40
-        'authenticate' => [
41
-            'keyAuthentication' => false
42
-        ],
43
-        'deauthenticate' => [
44
-            'keyAuthentication' => false
45
-        ]
46
-    ];
47
-
48
-    /**
49
-     * Authenticate the login
50
-     * 
51
-     * @return \Illuminate\Http\JsonResponse
52
-     */
53
-    public function authenticate() 
54
-    {
55
-        $credentials['username'] = Input::get('username');
56
-        $credentials['password'] = Input::get('password');
27
+	/**
28
+	 * The key to use as a key for this collection in the output
29
+	 * 
30
+	 * @var string
31
+	 */
32
+	protected $collectionName = 'users';
33
+
34
+	/**
35
+	 * The methods that don't require api authentication
36
+	 * 
37
+	 * @var array
38
+	 */
39
+	protected $apiMethods = [
40
+		'authenticate' => [
41
+			'keyAuthentication' => false
42
+		],
43
+		'deauthenticate' => [
44
+			'keyAuthentication' => false
45
+		]
46
+	];
47
+
48
+	/**
49
+	 * Authenticate the login
50
+	 * 
51
+	 * @return \Illuminate\Http\JsonResponse
52
+	 */
53
+	public function authenticate() 
54
+	{
55
+		$credentials['username'] = Input::get('username');
56
+		$credentials['password'] = Input::get('password');
57 57
         
58
-        $validator = Validator::make([
59
-                'username' => $credentials['username'],
60
-                'password' => $credentials['password']
61
-            ],
62
-            [
63
-                'username' => 'required|max:255',
64
-                'password' => 'required|max:255'
65
-            ]
66
-        );
58
+		$validator = Validator::make([
59
+				'username' => $credentials['username'],
60
+				'password' => $credentials['password']
61
+			],
62
+			[
63
+				'username' => 'required|max:255',
64
+				'password' => 'required|max:255'
65
+			]
66
+		);
67 67
         
68
-        if ($validator->fails()) {
69
-            return $this->response->errorWrongArgsValidator($validator);
70
-        }
71
-
72
-        try {
73
-            $user                 = with(new User)->authenticate($credentials['username'], $credentials['password'])->first();
74
-            $credentials['email'] = $user->email;
75
-        } catch (\ErrorException $e) {
76
-            return $this->response->errorUnauthorized("Your username or password is incorrect");
77
-        }
78
-
79
-        // We have validated this user
80
-        // Assign an API key for this session
81
-        $apiKey = ApiKey::where('user_id', '=', $user->id)->first();
68
+		if ($validator->fails()) {
69
+			return $this->response->errorWrongArgsValidator($validator);
70
+		}
71
+
72
+		try {
73
+			$user                 = with(new User)->authenticate($credentials['username'], $credentials['password'])->first();
74
+			$credentials['email'] = $user->email;
75
+		} catch (\ErrorException $e) {
76
+			return $this->response->errorUnauthorized("Your username or password is incorrect");
77
+		}
78
+
79
+		// We have validated this user
80
+		// Assign an API key for this session
81
+		$apiKey = ApiKey::where('user_id', '=', $user->id)->first();
82 82
         
83
-        if (!isset($apiKey)) {
84
-            $apiKey                = new ApiKey;
85
-            $apiKey->user_id       = $user->id;
86
-            $apiKey->key           = $apiKey->generateKey();
87
-            $apiKey->level         = 5;
88
-            $apiKey->ignore_limits = 0;
89
-        } else {
90
-            $apiKey->generateKey();
91
-        }
92
-
93
-        if (!$apiKey->save()) {
94
-            return $this->response->errorInternalError("Failed to create an API key. Please try again.");
95
-        }
96
-
97
-
98
-        // We have an API key.. i guess we only need to return that.
99
-        return $this->response->withItem($user, new \App\LaravelRestCms\User\UserTransformer);
100
-    }
101
-
102
-    /**
103
-     * Retrieve the user model
104
-     * 
105
-     * @return Model
106
-     */
107
-    public function getUserDetails() 
108
-    {
109
-        $user = $this->apiKey->user;
110
-
111
-        return isset($user) ? $user : $this->response->errorNotFound();
112
-    }
113
-
114
-    /**
115
-     * Log the user out
116
-     * 
117
-     * @param  string $apiKey
118
-     * @return \Illuminate\Http\JsonResponse
119
-     */
120
-    public function deauthenticate($apiKey) 
121
-    {
122
-        $this->apiKey = ApiKey::where('key', $apiKey)->first();
123
-
124
-        if (empty($this->apiKey)) {
125
-            return $this->response->errorUnauthorized("There is no such user to deauthenticate.");
126
-        }
127
-
128
-        $this->apiKey->delete();
129
-
130
-        return $this->response->withArray([
131
-            'ok' => [
132
-                'code'      => 'SUCCESSFUL',
133
-                'http_code' => 200,
134
-                'message'   => 'User was successfuly deauthenticated'
135
-            ]
136
-        ]);
137
-    }
83
+		if (!isset($apiKey)) {
84
+			$apiKey                = new ApiKey;
85
+			$apiKey->user_id       = $user->id;
86
+			$apiKey->key           = $apiKey->generateKey();
87
+			$apiKey->level         = 5;
88
+			$apiKey->ignore_limits = 0;
89
+		} else {
90
+			$apiKey->generateKey();
91
+		}
92
+
93
+		if (!$apiKey->save()) {
94
+			return $this->response->errorInternalError("Failed to create an API key. Please try again.");
95
+		}
96
+
97
+
98
+		// We have an API key.. i guess we only need to return that.
99
+		return $this->response->withItem($user, new \App\LaravelRestCms\User\UserTransformer);
100
+	}
101
+
102
+	/**
103
+	 * Retrieve the user model
104
+	 * 
105
+	 * @return Model
106
+	 */
107
+	public function getUserDetails() 
108
+	{
109
+		$user = $this->apiKey->user;
110
+
111
+		return isset($user) ? $user : $this->response->errorNotFound();
112
+	}
113
+
114
+	/**
115
+	 * Log the user out
116
+	 * 
117
+	 * @param  string $apiKey
118
+	 * @return \Illuminate\Http\JsonResponse
119
+	 */
120
+	public function deauthenticate($apiKey) 
121
+	{
122
+		$this->apiKey = ApiKey::where('key', $apiKey)->first();
123
+
124
+		if (empty($this->apiKey)) {
125
+			return $this->response->errorUnauthorized("There is no such user to deauthenticate.");
126
+		}
127
+
128
+		$this->apiKey->delete();
129
+
130
+		return $this->response->withArray([
131
+			'ok' => [
132
+				'code'      => 'SUCCESSFUL',
133
+				'http_code' => 200,
134
+				'message'   => 'User was successfuly deauthenticated'
135
+			]
136
+		]);
137
+	}
138 138
 }
139 139
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/routes.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,6 +15,6 @@
 block discarded – undo
15 15
 Route::group(['prefix' => 'api/v1', 'namespace' => 'Api\V1'], function()
16 16
 {
17 17
 	// users/auth
18
-    Route::post('user/login', 'UserController@authenticate');
19
-    Route::get('user/logout/{api_key}', 'UserController@deauthenticate');
18
+	Route::post('user/login', 'UserController@authenticate');
19
+	Route::get('user/logout/{api_key}', 'UserController@deauthenticate');
20 20
 });
21 21
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Middleware/Authenticate.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,7 @@
 block discarded – undo
37 37
 			if ($request->ajax())
38 38
 			{
39 39
 				return response('Unauthorized.', 401);
40
-			}
41
-			else
40
+			} else
42 41
 			{
43 42
 				return redirect()->guest('auth/login');
44 43
 			}
Please login to merge, or discard this patch.