Skip to content

Commit 0013307

Browse files
author
Eugene Lee
committed
Refactored skeleton to include some changes so that we don't have to pass user object around everywhere and also removed some unecessary controller and view.
1 parent edd4185 commit 0013307

File tree

10 files changed

+40
-113
lines changed

10 files changed

+40
-113
lines changed

app/controllers/AdminController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,21 @@
22

33
class AdminController extends BaseController {
44

5+
protected $logged_in_user;
6+
7+
public function __construct() {
8+
// Fetch the User object, or set it to false if not logged in
9+
if (Confide::User()) {
10+
$this->logged_in_user = Confide::User();
11+
}
12+
else {
13+
$this->logged_in_user = false;
14+
}
15+
16+
View::share('logged_in_user', $this->logged_in_user);
17+
}
518

619
public function index() {
7-
return View::make('admin.index')->with('user', Confide::user());
20+
return View::make('admin.index');
821
}
922
}

app/controllers/ApiController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ApiController extends Controller {
88
public function __construct()
99
{
1010
$this->token = Input::get('token');
11+
$this->user = User::getFromToken($this->token);
1112
}
1213

1314
}

app/controllers/HomeController.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/controllers/admin/UserController.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
class AdminUserController extends AdminController {
44

5-
/**
6-
* Setup the layout used by the controller.
7-
*
8-
* @return void
9-
*/
10-
protected function setupLayout()
11-
{
12-
if (!is_null($this->layout))
13-
{
14-
$this->layout = View::make($this->layout);
15-
}
16-
}
175

186
public function index()
197
{
@@ -30,7 +18,9 @@ public function store()
3018
// Get form data, create new user
3119
// Hacky, I know, but had to do this because of Sentry
3220
$user_data = Input::all();
33-
$user = new User($user_data);
21+
$user = new User();
22+
$user->fill($user_data);
23+
3424
// TODO: If we need to do confirmation, then stop doing this below
3525
$user->confirmed = 1;
3626

@@ -84,11 +74,11 @@ public function login()
8474
{
8575
// If user is logged, redirect to internal
8676
// page, change it to '/admin', '/dashboard' or something
87-
return Redirect::to('/')->with('user', Confide::user());
77+
return Redirect::to('/');
8878
}
8979
else
9080
{
91-
return View::make('/login')->with('user', new User());
81+
return View::make('/login');
9282
}
9383
}
9484

app/controllers/api/v1/UserController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ class ApiV1UserController extends ApiController {
55

66
public function index()
77
{
8-
// Get user from token
9-
$user = User::getFromToken($this->token);
108
// Find permissions and find users that this person has permissions to view
11-
if($user->can('manage_user')) {
9+
if($this->user->can('manage_user')) {
1210

1311
$users = User::all();
1412
return Api::response($users->toArray());

app/filters.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
// Invalid API key
5959
if ($validate !== true)
6060
{
61-
return Api::error($validate->errors()->getMessages());
61+
return Api::error($validate->errors()->getMessages(), 401);
6262
}
6363
});
6464

@@ -76,14 +76,14 @@
7676
// Invalid API key
7777
if ($validate !== true)
7878
{
79-
return Api::error($validate->errors()->getMessages());
79+
return Api::error($validate->errors()->getMessages(), 401);
8080
}
8181

8282
$validToken = User::isValidToken(Input::get('token'));
8383

8484
if($validToken !== true)
8585
{
86-
return Api::error(Lang::get('errors.invalid_token'));
86+
return Api::error(Lang::get('errors.invalid_token'), 401);
8787
}
8888
});
8989

app/views/admin/users/form.blade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<label for="username" class="col-md-4">Username</label>
66
<div class="col-md-8">
77
{{ Form::text('username', $user->username, array('class' => 'form-control', 'id' => 'username')) }}
8-
{{ $errors->first('username') }}
8+
<span class="text-danger">{{ $errors->first('username') }}</span>
99
</div> <!-- /controls -->
1010
</div> <!-- /control-group -->
1111

@@ -14,7 +14,7 @@
1414
<label for="first_name" class="col-md-4">First Name</label>
1515
<div class="col-md-8">
1616
{{ Form::text('first_name', $user->first_name, array('class' => 'form-control', 'id' => 'first_name')) }}
17-
{{ $errors->first('first_name') }}
17+
<span class="text-danger">{{ $errors->first('first_name') }}</span>
1818
</div> <!-- /controls -->
1919
</div> <!-- /control-group -->
2020

@@ -23,7 +23,7 @@
2323
<label class="col-md-4" for="last_name">Last Name</label>
2424
<div class="col-md-8">
2525
{{ Form::text('last_name', $user->last_name, array('class' => 'form-control', 'id' => 'last_name')) }}
26-
{{ $errors->first('last_name') }}
26+
<span class="text-danger">{{ $errors->first('last_name') }}</span>
2727
</div>
2828
</div> <!-- /control-group -->
2929

@@ -32,7 +32,7 @@
3232
<label class="col-md-4" for="email">Email Address</label>
3333
<div class="col-md-8">
3434
{{ Form::text('email', $user->email, array('class' => 'form-control', 'id' => 'email')) }}
35-
{{ $errors->first('email') }}
35+
<span class="text-danger">{{ $errors->first('email') }}</span>
3636
</div> <!-- /controls -->
3737
</div> <!-- /control-group -->
3838

@@ -43,7 +43,7 @@
4343
<label class="col-md-4" for="password">Password</label>
4444
<div class="col-md-8">
4545
{{ Form::password('password', array('class' => 'form-control', 'id' => 'password')) }}
46-
{{ $errors->first('password') }}
46+
<span class="text-danger">{{ $errors->first('password') }}</span>
4747
</div> <!-- /controls -->
4848
</div> <!-- /control-group -->
4949

@@ -52,7 +52,7 @@
5252
<label class="col-md-4" for="password_confirmation">Confirm</label>
5353
<div class="col-md-8">
5454
{{ Form::password('password_confirmation', array('class' => 'form-control', 'id' => 'password_confirmation')) }}
55-
{{ $errors->first('password_confirmation') }}
55+
<span class="text-danger">{{ $errors->first('password_confirmation') }}</span>
5656
</div> <!-- /controls -->
5757
</div> <!-- /control-group -->
5858

app/views/hello.php

Lines changed: 0 additions & 52 deletions
This file was deleted.

app/views/layouts/admin.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@
5151
<ul class="nav navbar-nav navbar-right">
5252
<li class="dropdown">
5353

54-
@if( !empty($user))
54+
@if( !empty($logged_in_user))
5555
<a href="javscript:;" class="dropdown-toggle" data-toggle="dropdown">
5656
<i class="icon-user"></i>
57-
{{$user->username}}
57+
{{$logged_in_user->username}}
5858
<b class="caret"></b>
5959
</a>
6060

6161

6262
<ul class="dropdown-menu">
63-
<li><a href="/admin/users/{{$user->id}}/edit">Account Settings</a></li>
63+
<li><a href="/admin/users/{{$logged_in_user->id}}/edit">Account Settings</a></li>
6464
<li class="divider"></li>
6565
<li><a href="/logout">Logout</a></li>
6666
</ul>
@@ -79,7 +79,7 @@
7979

8080

8181

82-
@if( !empty($user))
82+
@if( !empty($logged_in_user))
8383

8484
<div class="subnavbar">
8585

@@ -112,7 +112,7 @@
112112

113113
<ul class="dropdown-menu">
114114
<li><a href="/admin/users">All Users</a></li>
115-
<li><a href="/admin/users/{{$user->id}}/edit">My Account</a></li> <!-- TODO : Should this point to same as above link? -->
115+
<li><a href="/admin/users/{{$logged_in_user->id}}/edit">My Account</a></li> <!-- TODO : Should this point to same as above link? -->
116116
<li><a href="/admin/users/create">Create New Account</a></li>
117117
</ul>
118118
</li>

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"license": "MIT",
66
"require": {
77
"laravel/framework": "4.0.*",
8-
"zizaco/confide": "1.0.x",
9-
"zizaco/entrust": "dev-master",
10-
"way/generators": "dev-master",
8+
"zizaco/confide": "2.0.0b4",
9+
"zizaco/entrust": "0.4.0beta",
10+
"way/generators": "1.0"
1111
},
1212
"autoload": {
1313
"classmap": [
@@ -17,7 +17,7 @@
1717
"app/database/migrations",
1818
"app/database/seeds",
1919
"app/tests/TestCase.php",
20-
"app/libraries"
20+
"app/libraries"
2121
]
2222
},
2323
"scripts": {
@@ -36,5 +36,5 @@
3636
"preferred-install": "dist"
3737
},
3838
"minimum-stability": "dev",
39-
"prefer-stable": true
39+
"prefer-stable": true
4040
}

0 commit comments

Comments
 (0)