Skip to content

Commit

Permalink
creating api with routing and nice urls, creating open playsheet page
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanFriday committed Aug 13, 2015
1 parent b3b331c commit f278374
Show file tree
Hide file tree
Showing 89 changed files with 5,964 additions and 136 deletions.
2 changes: 1 addition & 1 deletion api/api_common_private.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

include_once("../headers/session_header.php");
session_start();
require_once('api_common.php');
require_once('../headers/security_header.php');

Expand Down
16 changes: 8 additions & 8 deletions api/playlist/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
$rawdata = array();


$query_for_playsheet = 'SELECT playlists.*,
$query_for_playsheet = 'SELECT playsheets.*,
hosts.name as host_name
FROM playlists
LEFT JOIN hosts on hosts.id = playlists.host_id
WHERE playlists.id = '.$id;
FROM playsheets
LEFT JOIN hosts on hosts.id = playsheets.host_id
WHERE playsheets.id = '.$id;

if ( $result = mysqli_query($db,$query_for_playsheet)){
$rawdata['playlist'] = mysqli_fetch_assoc($result);
Expand Down Expand Up @@ -122,8 +122,8 @@
$rawdata['plays'][$i]['insert_song_length_second'] = str_pad(strval($play['insert_song_length_second']), 2, "0", STR_PAD_LEFT);

}

foreach($rawdata['ads'] as $i => $ad){
if($using_sam){
foreach($rawdata['ads'] as $i => $ad){

$rawdata['ads'][$i]['played'] = ($ad['played'] == 1) ? true : false;

Expand All @@ -140,9 +140,9 @@
}
}
}


}
}


$start_unix = strtotime($rawdata['playlist']['start_time']);
$start = getdate($start_unix);
Expand Down
10 changes: 5 additions & 5 deletions api/playlists/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@


$query = '
SELECT playlists.start_time, playlists.edit_date, playlists.id as playlist_id,
SELECT playsheets.start_time, playsheets.edit_date, playsheets.id as playsheet_id,
show_id as sh_id,
shows.name as show_name
FROM playlists
LEFT JOIN podcast_episodes on playlists.podcast_episode = podcast_episodes.id
LEFT JOIN shows on shows.id = playlists.show_id
FROM playsheets
LEFT JOIN podcast_episodes on playsheets.podcast_episode = podcast_episodes.id
LEFT JOIN shows on shows.id = playsheets.show_id
ORDER BY
playlists.edit_date
playsheets.edit_date
DESC limit ' . $limit . ' OFFSET ' . $offset;


Expand Down
3 changes: 3 additions & 0 deletions api2/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.css linguist-vendored
*.less linguist-vendored
33 changes: 33 additions & 0 deletions api2/app/Console/Commands/Inspire.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;

class Inspire extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'inspire';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Display an inspiring quote';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
}
}
30 changes: 30 additions & 0 deletions api2/app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\Inspire::class,
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
}
}
8 changes: 8 additions & 0 deletions api2/app/Events/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace App\Events;

abstract class Event
{
//
}
51 changes: 51 additions & 0 deletions api2/app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
HttpException::class,
ModelNotFoundException::class,
];

/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
return parent::report($e);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
$e = new NotFoundHttpException($e->getMessage(), $e);
}

return parent::render($request, $e);
}
}
65 changes: 65 additions & 0 deletions api2/app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

/**
* Create a new authentication controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}

/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}

/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
32 changes: 32 additions & 0 deletions api2/app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/

use ResetsPasswords;

/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
12 changes: 12 additions & 0 deletions api2/app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController
{
use DispatchesJobs, ValidatesRequests;
}
33 changes: 33 additions & 0 deletions api2/app/Http/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
];

/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
];
}
47 changes: 47 additions & 0 deletions api2/app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Guard;

class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;

/**
* Create a new filter instance.
*
* @param Guard $auth
* @return void
*/
public function __construct(Guard $auth)
{
$this->auth = $auth;
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('auth/login');
}
}

return $next($request);
}
}
Loading

0 comments on commit f278374

Please sign in to comment.