Skip to content
This repository has been archived by the owner on Apr 12, 2020. It is now read-only.

Entrega Proyecto 1 #27

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/
28 changes: 28 additions & 0 deletions app/Album.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App;

use App\Song;
use App\User;
use Illuminate\Database\Eloquent\Model;

class Album extends Model{

protected $fillable = [
'list_name', 'public', 'owner'
];

protected $primaryKey = 'list_id';

public function songs () {
return $this->hasMany(Song::class,'list_id','list_id');
}

public function users () {
return $this->belongsTo(User::class,'owner');
}

public function addSong (Song $song) {
$this->songs()->create($song);
}
}
141 changes: 141 additions & 0 deletions app/Http/Controllers/AlbumsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

namespace App\Http\Controllers;

use App\Album;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Auth;
use Redirect;

class AlbumsController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index () {
$album = Album::select('*')->where('owner', Auth::user()->name)->get();

return view('albums.indexAlbum', compact('album'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create () {
$this->middleware('auth');

if (Auth::user()) {
return view('albums.createAlbum');
}

else {
return Redirect::to('/login');
}
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store () {
$this->middleware('auth');

$attributes = array(
'list_name' => 'required',
'public' => 'required'
);
$validator = Validator::make(Input::all(), $attributes);

if ($validator->fails()) {
return Redirect::to('albums.createAlbum')->withErrors($validator)->withInput(Input::except('password'));
}
else {
$album = new Album;
$album->list_name = Input::get('list_name');
$album->public = Input::get('public');
$album->owner = Auth::user()->name;
$album->save();

return Redirect::to('albums');
}
}

/**
* Display the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function show (Album $album) {
if ($album->public == 0) {

if (!Auth::user()) {
return Redirect::to('/login');
}

else {
if (Auth::user()->name != $album->owner) {
abort(403, 'Unauthorized Action');
}
}

}
return view('albums.showAlbum', compact('album'));
}

/**
* Show the form for editing the specified resource.
*
* @return \Illuminate\Http\Response
*/
public function edit (Album $album) {
$this->middleware('auth');

if (Auth::user()) {
if ((Auth::user()->name) == ($album->owner)) {
return view('albums.editAlbum', compact('album'));
}

else {
abort(403, 'Unauthorized Action');
}
}

else {
return Redirect::to('/login');
}
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function update (Request $request, Album $album) {
$this->middleware('auth');

$album->update(request(['list_name', 'public']));

return redirect('/albums');
}

/**
* Remove the specified resource from storage.
*
* @return \Illuminate\Http\Response
*/
public function destroy (Album $album) {
$this->middleware('auth');

$album->delete();

return redirect('/albums');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = 'home';

/**
* Create a new controller instance.
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = 'home';

/**
* Create a new controller instance.
Expand All @@ -49,7 +49,7 @@ public function __construct()
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255', 'unique:users'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
Expand All @@ -67,6 +67,11 @@ protected function create(array $data)
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'email_public' => 1,
'first_name' => "",
'first_name_public' => 1,
'last_name' => "",
'last_name_public' => 1
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = 'home';

/**
* Create a new controller instance.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = 'home';

/**
* Create a new controller instance.
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('home');
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/PagesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers;

use App\Album;
use Illuminate\Http\Request;

class PagesController extends Controller {
public function home() {
return view('welcome');
}

public function profile() {
return view('profile');
}

public function about() {
return view('about');
}

public function browse() {
$album = Album::select('*')->where('public',1)->get();
return view('browse',compact('album'));
}
}
Loading