Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 972b1c8

Browse files
author
Khary Sharpe
committed
Initial code
1 parent d3d9b16 commit 972b1c8

File tree

120 files changed

+14188
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+14188
-1
lines changed

.env.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
APP_KEY=SomeRandomString
4+
APP_URL=http://localhost
5+
6+
DB_CONNECTION=mysql
7+
DB_HOST=127.0.0.1
8+
DB_PORT=3306
9+
DB_DATABASE=homestead
10+
DB_USERNAME=homestead
11+
DB_PASSWORD=secret
12+
13+
CACHE_DRIVER=file
14+
SESSION_DRIVER=file
15+
QUEUE_DRIVER=sync
16+
17+
REDIS_HOST=127.0.0.1
18+
REDIS_PASSWORD=null
19+
REDIS_PORT=6379
20+
21+
MAIL_DRIVER=smtp
22+
MAIL_HOST=mailtrap.io
23+
MAIL_PORT=2525
24+
MAIL_USERNAME=null
25+
MAIL_PASSWORD=null
26+
MAIL_ENCRYPTION=null
27+
28+
API_PREFIX=api
29+
API_DEBUG=true
30+
31+
JWT_SECRET=

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.idea
2+
.DS_Store
3+
.env
4+
/vendor
5+
/node_modules
6+
/public/storage
7+
Homestead.yaml
8+
Homestead.json

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 kharysharpe
3+
Copyright (c) 2016 Khary Sharpe
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

app/Console/Commands/Inspire.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Foundation\Inspiring;
7+
8+
class Inspire extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'inspire';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Display an inspiring quote';
23+
24+
/**
25+
* Execute the console command.
26+
*
27+
* @return mixed
28+
*/
29+
public function handle()
30+
{
31+
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
32+
}
33+
}

app/Console/Kernel.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
// Commands\Inspire::class,
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
}

app/Events/Event.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
abstract class Event
6+
{
7+
//
8+
}

app/Exceptions/Handler.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Validation\ValidationException;
7+
use Illuminate\Auth\Access\AuthorizationException;
8+
use Illuminate\Database\Eloquent\ModelNotFoundException;
9+
use Symfony\Component\HttpKernel\Exception\HttpException;
10+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11+
12+
class Handler extends ExceptionHandler
13+
{
14+
/**
15+
* A list of the exception types that should not be reported.
16+
*
17+
* @var array
18+
*/
19+
protected $dontReport = [
20+
AuthorizationException::class,
21+
HttpException::class,
22+
ModelNotFoundException::class,
23+
ValidationException::class,
24+
];
25+
26+
/**
27+
* Report or log an exception.
28+
*
29+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30+
*
31+
* @param \Exception $e
32+
* @return void
33+
*/
34+
public function report(Exception $e)
35+
{
36+
parent::report($e);
37+
}
38+
39+
/**
40+
* Render an exception into an HTTP response.
41+
*
42+
* @param \Illuminate\Http\Request $request
43+
* @param \Exception $e
44+
* @return \Illuminate\Http\Response
45+
*/
46+
public function render($request, Exception $e)
47+
{
48+
return parent::render($request, $e);
49+
}
50+
}

app/Http/Controllers/Controller.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Foundation\Bus\DispatchesJobs;
6+
use Illuminate\Routing\Controller as BaseController;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
9+
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
10+
11+
class Controller extends BaseController
12+
{
13+
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
14+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php namespace App\Http\Controllers;
2+
3+
use App\Transformers\UsersTransformer;
4+
use JWTAuth;
5+
use Exception;
6+
use Tymon\JWTAuth\Exceptions\JWTException;
7+
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
8+
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
9+
use Dingo\Api\Http\Request;
10+
use Dingo\Api\Routing\Helpers;
11+
use Illuminate\Support\Facades\Log;
12+
13+
14+
class SessionsController extends Controller
15+
{
16+
use Helpers;
17+
18+
/**
19+
* Returns the authenticated user
20+
*
21+
* @return \Illuminate\Http\JsonResponse
22+
*/
23+
function index()
24+
{
25+
26+
if (!$user = $this->auth->getUser()) {
27+
$this->response->errorNotFound();
28+
}
29+
30+
return $this->response->item($user, new UsersTransformer());
31+
32+
}
33+
34+
/**
35+
* API Login, on success return JWT Auth token
36+
*
37+
* @param \Illuminate\Http\Request $request
38+
*
39+
* @return \Illuminate\Http\JsonResponse
40+
*/
41+
function store(Request $request)
42+
{
43+
44+
// grab credentials from the request
45+
$credentials = $request->only('email', 'password');
46+
47+
try {
48+
// attempt to verify the credentials and create a token for the user
49+
if (!$token = JWTAuth::attempt($credentials)) {
50+
return $this->response->array(['error' => 'invalid_credentials'], 401);
51+
}
52+
} catch (JWTException $e) {
53+
// something went wrong whilst attempting to encode the token
54+
return $this->response->array(['error' => 'could_not_create_token'], 500);
55+
}
56+
// all good so return the token
57+
return $this->response->array(['token' => $token]);
58+
}
59+
60+
/**
61+
* Refresh the token
62+
*
63+
* @return mixed
64+
*/
65+
function update()
66+
{
67+
68+
$token = JWTAuth::getToken();
69+
70+
if (!$token) {
71+
$this->response->errorMethodNotAllowed('Token not provided');
72+
}
73+
74+
try {
75+
$refreshedToken = JWTAuth::refresh($token);
76+
}
77+
catch (JWTException $e)
78+
{
79+
$this->response->errorInternal('Not able to refresh Token');
80+
}
81+
82+
return $this->response->array(['token' => $refreshedToken]);
83+
84+
}
85+
86+
/**
87+
* Log out
88+
* Invalidate the token, so user cannot use it anymore
89+
* They have to relogin to get a new token
90+
*
91+
* @param Request $request
92+
*/
93+
public function delete(Request $request)
94+
{
95+
$token = JWTAuth::getToken();
96+
97+
if (!$token) {
98+
$this->response->errorMethodNotAllowed('Token not provided');
99+
}
100+
101+
JWTAuth::invalidate($token);
102+
103+
return $this->response->array(['token' => 'Token destroyed']);
104+
105+
}
106+
107+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php namespace App\Http\Controllers;
2+
3+
use App\Transformers\UsersTransformer;
4+
use App\User;
5+
use Dingo\Api\Http\Request;
6+
use Dingo\Api\Routing\Helpers;
7+
8+
9+
class UsersController extends Controller
10+
{
11+
use Helpers;
12+
13+
function index ()
14+
{
15+
$users = User::all();
16+
17+
return $this->response->collection($users, new UsersTransformer());
18+
}
19+
20+
function store(Request $request)
21+
{
22+
$input = $request->all();
23+
24+
$user = User::Create($input);
25+
26+
if ($user) {
27+
28+
$response = $this->response->array($user);
29+
30+
return $response->setStatusCode(201);
31+
32+
}
33+
34+
return $this->response->errorBadRequest();
35+
}
36+
37+
}

app/Http/Kernel.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace App\Http;
4+
5+
use Illuminate\Foundation\Http\Kernel as HttpKernel;
6+
7+
class Kernel extends HttpKernel
8+
{
9+
/**
10+
* The application's global HTTP middleware stack.
11+
*
12+
* These middleware are run during every request to your application.
13+
*
14+
* @var array
15+
*/
16+
protected $middleware = [
17+
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
18+
];
19+
20+
/**
21+
* The application's route middleware groups.
22+
*
23+
* @var array
24+
*/
25+
protected $middlewareGroups = [
26+
'web' => [
27+
\App\Http\Middleware\EncryptCookies::class,
28+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
29+
\Illuminate\Session\Middleware\StartSession::class,
30+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
31+
\App\Http\Middleware\VerifyCsrfToken::class,
32+
],
33+
34+
'api' => [
35+
'throttle:60,1',
36+
],
37+
];
38+
39+
/**
40+
* The application's route middleware.
41+
*
42+
* These middleware may be assigned to groups or used individually.
43+
*
44+
* @var array
45+
*/
46+
protected $routeMiddleware = [
47+
'auth' => \App\Http\Middleware\Authenticate::class,
48+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
49+
'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
50+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
51+
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
52+
];
53+
54+
protected function schedule(Schedule $schedule)
55+
{
56+
$schedule->command('quicksand:run')
57+
->daily();
58+
}
59+
}

0 commit comments

Comments
 (0)