forked from LearningLocker/learninglocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserController.php
128 lines (99 loc) · 2.59 KB
/
UserController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
use Locker\Repository\User\UserRepository as User;
use Locker\Repository\Lrs\LrsRepository as Lrs;
class UserController extends BaseController {
/**
* User
*/
protected $user;
/**
* Lrs
**/
protected $lrs;
/**
* Construct
*
* @param User $user
*/
public function __construct(User $user, Lrs $lrs){
$this->user = $user;
$this->lrs = $lrs;
$this->logged_in_user = Auth::user();
$this->beforeFilter('auth', array('except' => array('verifyEmail')));
$this->beforeFilter('csrf', array('only' => array('update','updateRole', 'destroy')));
$this->beforeFilter('user.delete', array('only' => 'destroy'));
$this->beforeFilter('auth.super', array('only' => array('updateRole','index')));
}
/**
* Display a listing of users.
*
* @return View
*/
public function index(){
return View::make('index', array( 'users' => $this->user->all() ));
}
/**
* Show the form for creating a new resource.
*
* @return View
*/
public function create(){
return View::make('register.index');
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return View
*/
public function edit( $id ){
return View::make('partials.users.edit')
->with( 'user', $this->user->find( $id ) )
->with( 'list', $this->lrs->all() );
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return View
*/
public function update( $id ){
$data = Input::all();
//if email being changed, verify new one, otherwise ignore
if( $data['email'] != Auth::user()->email ){
$rules['email'] = 'required|email|unique:users';
}
$rules['name'] = 'required';
$validator = Validator::make($data, $rules);
if ($validator->fails()) return Redirect::back()->withErrors($validator);
// Update the user
$s = $this->user->update($id, $data);
if($s){
return Redirect::back()->with('success', Lang::get('users.updated'));
}
return Redirect::back()
->withInput()
->with('error', Lang::get('users.updated_error'));
}
/**
* Update the user's role.
*
* @param int $id
* @return View
*/
public function updateRole( $id, $role ){
$s = $this->user->updateRole($id, $role);
return Response::json($s);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return View
*/
public function destroy( $id ){
//delete
$this->user->delete( $id );
return Redirect::back()->with('success', Lang::get('users.deleted'));
}
}