Skip to content

Commit

Permalink
Merge pull request #8 from andela-sachungo/develop
Browse files Browse the repository at this point in the history
testing
  • Loading branch information
sachungo committed Jan 12, 2016
2 parents cf95613 + 452de3d commit ff28949
Show file tree
Hide file tree
Showing 95 changed files with 6,006 additions and 232 deletions.
23 changes: 23 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=localhost
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.css linguist-vendored
*.less linguist-vendored
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/vendor
/node_modules
Homestead.yaml
Homestead.json
.env
*.log
.DS_Store
7 changes: 7 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
preset: laravel

linting: true

finder:
exclude:
- "tests"
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: vendor/bin/heroku-php-apache2 public
45 changes: 45 additions & 0 deletions app/Categories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Soma;

use Illuminate\Database\Eloquent\Model;

class Categories extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'categories';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'title',
];

/**
* A category belongs to a user.
*
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo('Soma\User');
}

/**
* A category has many videos.
*
* @return Illuminate\Database\Eloquent\Relations\HasMany
*/
public function videos()
{
return $this->hasMany('Soma\Videos', 'category_id');
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/Inspire.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Console\Commands;
namespace Soma\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Console;
namespace Soma\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
Expand Down
2 changes: 1 addition & 1 deletion app/Events/Event.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Events;
namespace Soma\Events;

abstract class Event
{
Expand Down
2 changes: 1 addition & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Exceptions;
namespace Soma\Exceptions;

use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace App\Http\Controllers\Auth;
namespace Soma\Http\Controllers\Auth;

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

Expand All @@ -23,6 +23,8 @@ class AuthController extends Controller

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

protected $redirectPath = '/dashboard';

/**
* Create a new authentication controller instance.
*
Expand All @@ -43,8 +45,9 @@ 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',
'email' => 'required|email|max:255|max:255',
'password' => 'required|min:6',
'confirm-password' => 'required|same:password',
]);
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace App\Http\Controllers\Auth;
namespace Soma\Http\Controllers\Auth;

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

class PasswordController extends Controller
Expand Down
63 changes: 63 additions & 0 deletions app/Http/Controllers/Auth/SocialAuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Soma\Http\Controllers\Auth;

use Auth;
use Socialite;
use Soma\User;
use Soma\Http\Controllers\Controller;

class SocialAuthController extends Controller
{
/**
* Redirect the user to the provider authentication page.
*
* @return Response
*/
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}

/**
* Obtain the user information from the provider.
*
* Specify true as the second parameter to "Auth::login()"
* " to set the "remember me" cookie.
*
* @return Response
*/
public function handleProviderCallback($provider)
{
try {
$user = Socialite::driver($provider)->user();
} catch (\Exception $e) {
return redirect()->route('register');
}

$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);

return redirect()->route('dashboard');
}

/**
* Return user if exists; create and return if doesn't.
*
* @param $socialUser
* @return User
*/
private function findOrCreateUser($socialUser)
{
if ($authUser = User::where('email', $socialUser->getEmail())->first()) {
return $authUser;
}

return User::create([
'name' => $socialUser->getName(),
'email' => $socialUser->getEmail(),
'provider_id' => $socialUser->getAvatar(),
'avatar' => $socialUser->getAvatar(),
]);
}
}
124 changes: 124 additions & 0 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace Soma\Http\Controllers;

use Soma\User;
use Soma\Categories;
use Soma\Http\Requests\CategoriesRequest;

class CategoryController extends Controller
{
/**
* A constructor.
*/
public function __construct()
{
$this->middleware('auth', [
'except' => [
'getVideosByCategory',
],
]);
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
/*public function index()
{
$categories = Categories::all();
return view('categories.index')->with('categories', $categories);
}*/

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('categories.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(CategoriesRequest $request)
{
$user = User::authorizedUser($request->email)->first();
$user->categories()->create([
'title' => $request->title,
]);

// FLASH MESSAGE

return redirect()->back();
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$category = Categories::find($id);

return view('categories.edit')->with('category', $category);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(CategoriesRequest $request, $id)
{
$category = Categories::find($id);
$category->update([
'title' => $request->title,
]);

// FLASH MESSAGE
return redirect()->route('own.categories');
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$category = Categories::find($id);
if ($category) {
Categories::destroy($id);

return redirect()->back();
}

// REDIRECT WITH MESSAGE CATEGORY NOT FOUND
return redirect()->route('dashboard');
}

/**
* Get the categories of a particular user.
*
* @return \Illuminate\Http\Response
*/
public function getCategories()
{
$categories = Categories::where('user_id', auth()->user()->id)->get();

return view('categories.own')->with('categories', $categories);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers;
namespace Soma\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
Expand Down
Loading

0 comments on commit ff28949

Please sign in to comment.