diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php new file mode 100644 index 0000000..e40500b --- /dev/null +++ b/app/controllers/AdminController.php @@ -0,0 +1,65 @@ +beforeFilter('auth'); + } + + public function home() + { + return View::make('login'); + } + + public function manageUsers() + { + + } + + public function viewUser($id) + { + + } + + public function destroyUser($id) + { + + } + + public function restoreUser($id) + { + + } + + public function viewStats() + { + + } + + public function showContact($id) + { + + } + + public function contactUser($id) + { + + } + + public function revokeAccess($id) + { + + } + + public function showMatches() + { + + } + + +} \ No newline at end of file diff --git a/app/controllers/HomeController.php b/app/controllers/HomeController.php index a04fb06..c851044 100755 --- a/app/controllers/HomeController.php +++ b/app/controllers/HomeController.php @@ -15,8 +15,13 @@ class HomeController extends BaseController { | */ - public function showWelcome() + public function index() { + if(Auth::check()) + { + return Redirect::route('user', Auth::id()); + } + return View::make('home'); } diff --git a/app/controllers/SessionController.php b/app/controllers/SessionController.php index d85b5d6..d17acb4 100644 --- a/app/controllers/SessionController.php +++ b/app/controllers/SessionController.php @@ -5,16 +5,14 @@ class SessionController extends \BaseController public function showLogin() { + if(Auth::check()) + { + return Redirect::route('user', Auth::id()); + } + return View::make('login'); } - public function doLogout() - { - Auth::logout(); - return Redirect::to('login'); - Session::forget('user'); - } - public function doLogin() { $rules = array( @@ -68,4 +66,11 @@ class SessionController extends \BaseController } + public function doLogout() + { + Auth::logout(); + return Redirect::to('login'); + Session::forget('user'); + } + } \ No newline at end of file diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php index a17a2d9..cc8477d 100644 --- a/app/controllers/UserController.php +++ b/app/controllers/UserController.php @@ -4,7 +4,6 @@ class UserController extends \BaseController { - public function index() { $users = User::all(); @@ -39,6 +38,7 @@ class UserController extends \BaseController array('first' => Input::get('first'), 'last' => Input::get('last'), 'email' => Input::get('email'), + 'level' => 'user', 'password' => Hash::make(\Input::get('password')))); if($user->save()) @@ -182,7 +182,7 @@ class UserController extends \BaseController if ($user->save()) { - return Redirect::route('users', array($user_id)); + return Redirect::route('user', array($user_id)); }else { \Redirect::back('complete', array($user_id, $group_id )); @@ -223,7 +223,7 @@ class UserController extends \BaseController $user = User::find($id); \Session::flash('message', 'You have successfully updated your profile.'); - return Redirect::to('users', array($id)); + return Redirect::to('user', array($id)); } } diff --git a/app/database/migrations/2014_06_29_233811_alter_user_table_add_admin_column.php b/app/database/migrations/2014_06_29_233811_alter_user_table_add_admin_column.php new file mode 100644 index 0000000..839edf1 --- /dev/null +++ b/app/database/migrations/2014_06_29_233811_alter_user_table_add_admin_column.php @@ -0,0 +1,34 @@ +string('level', 32)->after('remember_token'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function(Blueprint $table) + { + $table->dropColumn('level'); + }); + } + +} diff --git a/app/filters.php b/app/filters.php index 2a780f7..c6ffda4 100755 --- a/app/filters.php +++ b/app/filters.php @@ -78,3 +78,15 @@ Route::filter('csrf', function() throw new Illuminate\Session\TokenMismatchException; } }); + +Route::filter('admin', function() +{ + if(Auth::check() && Auth::user()->level != 'admin') + { + \Session::flash('message', 'You tried to access restricted area!'); + return Redirect::to('denied'); + } +}); + +Route::when('admin/*', 'admin'); + diff --git a/app/models/User.php b/app/models/User.php index 5b80b15..f5c99d3 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -14,7 +14,7 @@ class User extends Eloquent implements UserInterface, RemindableInterface { protected $table = 'users'; protected $fillable = array( - 'first', 'last', 'email', 'password', 'location', 'skills', 'photo', 'bio', 'remember_token'); + 'first', 'last', 'email', 'password', 'location', 'skills', 'photo', 'bio', 'remember_token', 'level'); /** * The attributes excluded from the model's JSON form. @@ -67,4 +67,9 @@ class User extends Eloquent implements UserInterface, RemindableInterface { { return 'remember_token'; } + + public function getFullName() + { + return $this->first. ' ' . $this->last; + } } diff --git a/app/routes.php b/app/routes.php index 361cfee..84c15ae 100755 --- a/app/routes.php +++ b/app/routes.php @@ -14,7 +14,7 @@ /** * User Session Controller routes */ -Route::get('/', function(){return View::make('home') ;}); +Route::get('/', array('as' => 'home', 'uses' => 'HomeController@index')); Route::get('login', array('as' => 'login', 'uses' => 'SessionController@showLogin')); Route::post('login', array('uses' => 'SessionController@doLogin')); @@ -30,7 +30,7 @@ Route::group(array('before' => 'auth'), function() Route::get('users/group/{user_id}', array('as' => 'group', 'uses' => 'UserController@chooseGroup')); Route::get('users/group/{user_id}/{group_id}', array('as' => 'complete', 'uses' => 'UserController@completeRegistration')); Route::post('users/group/complete', array('uses' => 'UserController@saveProfile')); - Route::get('users/{id}', array('as' => 'users', 'uses' => 'UserController@showProfile')); + Route::get('user/{id}', array('as' => 'user', 'uses' => 'UserController@showProfile')); Route::get('users/{id}/edit', array('as' => 'edit', 'uses' => 'UserController@edit')); Route::put('users/{id}/update', array('uses' => 'UserController@update')); Route::get('users', array('as' => 'users', 'uses' => 'UserController@index')); @@ -46,4 +46,26 @@ Route::post('password/remind', array('uses' => 'RemindersController@postRemind') Route::get('password/reset/{token}', array('uses' => 'RemindersController@getReset')); Route::post('password/reset', array('uses' => 'RemindersController@postReset')); +/** + * Admin Routes ++ Management Stuff out of reach for regular users + */ +Route::group(array('before' => 'auth|admin'), function() +{ + Route::get('admin', array('as' => 'admin', 'uses' => 'AdminController@home')); + Route::get('admin/users', array('as' => 'all', 'uses' => 'AdminController@manageUsers')); + Route::get('admin/user/{id}', array('as' => 'userx', 'uses' => 'AdminController@viewUser')); + Route::delete('admin/user/{id}', array('uses' => 'AdminController@destroyUser')); + Route::post('admin/user/restore/{id}', array('uses' => 'AdminController@restoreUser')); + Route::get('admin/user/stats', array('as' => 'stats', 'uses' => 'AdminController@viewStats')); + Route::get('admin/user/contact/{id}', array('as' => 'contact', 'uses' => 'AdminController@showContact')); + Route::post('admin/user/contact', array('uses' => 'AdminController@contactUser')); + Route::post('admin/user/revoke', array('uses' => 'AdminController@revokeAccess')); + Route::get('admin/users/matches', array('as' => 'matches', 'uses' => 'AdminController@showMatches')); + +}); + +Route::get('denied', function() +{ + return View::make('404'); +}); diff --git a/app/views/404.blade.php b/app/views/404.blade.php new file mode 100644 index 0000000..428ae6d --- /dev/null +++ b/app/views/404.blade.php @@ -0,0 +1,74 @@ + + +
+Apparently you tried accessing a restricted area and the gods were not very pleased. Please press the Back button to navigate back to where you were,
+Or you could just press this neat little button:
+ Take Me Home +