Repository navigation
Expand file tree
/
Copy pathclient.php
More file actions
245 lines (197 loc) · 7.36 KB
/
Copy pathclient.php
File metadata and controls
245 lines (197 loc) · 7.36 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
class Controller_Client extends Template {
public function action_list()
{
if ( Request::is_datatables() )
{
if ( ! ACL::check('access oaclient2'))
{
throw new HTTP_Exception_404('You have no permission to access oauth2 clients.');
}
$posts = ORM::factory('oaclient');
if ( ! User::is_admin())
{
$user = Auth::instance()->get_user();
$posts->where('user_id', '=', $user->id);
}
$this->_datatables = $posts->dataTables( array('title', 'client_id', 'user_id', 'created') );
foreach ($this->_datatables->result() as $oaclient)
{
$this->_datatables->add_row(array
(
HTML::anchor($oaclient->url ,Text::plain($oaclient->title)),
$oaclient->client_id,
$oaclient->user->nick,
System::date('M d, Y',$oaclient->created),
HTML::icon($oaclient->edit_url, 'fa-edit', array('class'=>'action-edit', 'data-toggle' => 'popup1', 'title'=> __('Edit'))) . ' ' .
HTML::icon($oaclient->delete_url, 'fa-trash-o', array('class'=>'action-delete', 'data-toggle' => 'popup', 'title'=> __('Delete')))
));
}
}
$this->title = __('Oauth Clients');
$view = View::factory('client/list')
->bind('datatables', $this->_datatables)
->set('url', Route::url('oauth2/client', array('action' => 'list'), TRUE))
->set('show', TRUE);
$this->response->body($view);
}
public function action_Register()
{
if ( ! ACL::check('administer oauth2'))
{
throw new HTTP_Exception_404('You have no permission to add oauth2 clients.');
}
$this->title = __('Oaclient Registration');
$grant_types = Config::get('oauth2.grant_types');
$view = View::factory('client/form')->set('grant_types', $grant_types)->bind('oaclient', $oaclient)->bind('errors', $this->_errors);
$oaclient = ORM::factory('oaclient');
if ( isset($_POST['cancel']) AND $this->valid_post() )
{
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
if ($this->valid_post('save'))
{
$oaclient->values($this->request->post());
try
{
if (isset($_POST['grant_types']) && ! empty($_POST['grant_types']))
{
$grant_types_selected = implode(" ", $_POST['grant_types']);
$oaclient->grant_types = $grant_types_selected;
}
if (isset($_FILES) AND isset($_FILES['logo']))
{
$filename = uniqid().preg_replace('/\s+/u', '_', $_FILES['logo']['name']);
if( $file = Upload::save($_FILES['logo'], $filename, APPPATH.'/media/logos') )
{
$oaclient->logo = $filename;
}
}
$oaclient->save();
Message::success( __('Client registered :title ', array(':title' => $oaclient->title)) );
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
catch(ORM_Validation_Exception $e)
{
$this->_errors = $e->errors('models');
}
}
$this->response->body($view);
}
public function action_edit()
{
if ( ! ACL::check('edit oaclient2'))
{
throw new HTTP_Exception_404('You have no permission to edit oauth2 clients.');
}
$id = (int) $this->request->param('id');
$oaclient = ORM::factory('oaclient', $id);
if( ! $oaclient->loaded() )
{
Message::error( __('Client: doesn\'t exists!') );
Kohana::$log->add(Log::ERROR, 'Attempt to edit non-existent client');
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
if ( isset($_POST['cancel']) AND $this->valid_post() )
{
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
if ($this->valid_post('save'))
{
$oaclient->values($this->request->post());
try
{
//$grant_types_selected = 'authorization_code';
if (isset($_POST['grant_types']) && ! empty($_POST['grant_types']))
{
$grant_types_selected = implode(" ", $_POST['grant_types']);
$oaclient->grant_types = $grant_types_selected;
}
if (isset($_FILES) AND isset($_FILES['logo']))
{
$filename = uniqid().preg_replace('/\s+/u', '_', $_FILES['logo']['name']);
if( $file = Upload::save($_FILES['logo'], $filename, APPPATH.'/media/logos') )
{
$oaclient->logo = $filename;
}
}
$oaclient->save();
Message::success( __('Client :title updated successfully', array(':title' => $oaclient->title)) );
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
catch(ORM_Validation_Exception $e)
{
$this->_errors = $e->errors('models');
}
}
$grant_types = Config::get('oauth2.grant_types');
$this->title = __('Edit oaclient');
$this->subtitle = Text::plain($oaclient->title);
$view = View::factory('client/form')
->set('grant_types', $grant_types)
->bind('oaclient', $oaclient)
->bind('errors', $this->_errors);
$this->response->body($view);
}
public function action_view()
{
if ( ! ACL::check('access oaclient2'))
{
throw new HTTP_Exception_404('You have no permission to access oauth2 clients.');
}
$id = (int) $this->request->param('id');
$oaclient = ORM::factory('oaclient', $id);
if( ! $oaclient->loaded() )
{
Message::error( __('Client: doesn\'t exists!') );
Kohana::$log->add(Log::ERROR, 'Attempt to edit non-existent client');
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
$this->title = __('Client info');
$this->response->body(View::factory('client/view')->set('oaclient', $oaclient));
}
public function action_delete()
{
if ( ! ACL::check('delete oaclient2'))
{
throw new HTTP_Exception_404('You have no permission to delete oauth2 clients.');
}
$id = (int) $this->request->param('id');
$redirect = empty($this->redirect) ? Route::get('oauth2/client')->uri(array('action' => 'list')) : $this->redirect;
$oaclient = ORM::factory('oaclient', $id);
if ( ! $oaclient->loaded() )
{
Message::error( __('oaclient: doesn\'t exists!') );
Kohana::$log->add(Log::ERROR, 'Attempt to delete non-existent oaclient');
$this->request->redirect(Route::get('oauth2/client')->uri(array('action' => 'list')));
}
$clone_oaclient = clone $oaclient;
if ( ! Access::oaclient('delete', $oaclient) )
{
// If the lead was not loaded, we return access denied.
throw new HTTP_Exception_404('Attempt to non-existent oaclient.');
}
$this->title = __('Delete oaclient');
$this->subtitle = Text::plain($oaclient->client_id);
$form = View::factory('form/confirm')->set('action', $oaclient->delete_url)->set('title', $oaclient->client_id);
// If deletion is not desired, redirect to post
if ( isset($_POST['no']) AND $this->valid_post() )
$this->request->redirect( 'oauth2/client' );
// If deletion is confirmed
if ( isset($_POST['yes']) AND $this->valid_post() )
{
try
{
$oaclient->delete();
Message::success( __('oaclient: :title deleted successfully', array(':title' => $clone_oaclient->client_id)) );
$this->request->redirect($redirect);
}
catch(Exception $e)
{
Message::error( __('oaclient: :title unable to delete the record', array(':title' => $clone_oaclient->client_id)) );
$this->request->redirect($redirect);
}
}
$this->response->body($form);
}
}