Skip to content

Commit cefaef9

Browse files
committed
Merge pull request #626 from LearningLocker/develop
v1.4.1
2 parents ec937fb + 8a36798 commit cefaef9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+470
-711
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0
1+
1.4.1

app/controllers/ClientController.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Locker\Repository\User\UserRepository as UserRepo;
44
use Locker\Repository\Lrs\Repository as LrsRepo;
5-
use Locker\Repository\Client\ClientRepository as ClientRepo;
5+
use Locker\Repository\Client\Repository as ClientRepo;
66

77
class ClientController extends BaseController {
88

@@ -47,7 +47,7 @@ public function edit($lrs_id, $id) {
4747
$opts = ['user' => \Auth::user()];
4848
$lrs = $this->lrs->show($lrs_id, $opts);
4949
$lrs_list = $this->lrs->index($opts);
50-
$client = $this->client->find($id);
50+
$client = $this->client->show($id, ['lrs_id' => $lrs_id]);
5151
return View::make('partials.client.edit', [
5252
'client' => $client,
5353
'lrs' => $lrs,
@@ -65,7 +65,7 @@ public function create($lrs_id) {
6565
$lrs = $this->lrs->show($lrs_id, $opts);
6666
$data = ['lrs_id' => $lrs->id];
6767

68-
if ($this->client->create($data)) {
68+
if ($this->client->store([], ['lrs_id' => $lrs_id])) {
6969
$message_type = 'success';
7070
$message = trans('lrs.client.created_sucecss');
7171
} else {
@@ -83,14 +83,31 @@ public function create($lrs_id) {
8383
* @return View
8484
*/
8585
public function update($lrs_id, $id){
86-
if ($this->client->update($id, Input::all())) {
86+
$data = Input::all();
87+
$authority = [
88+
'name' => $data['name'],
89+
];
90+
91+
switch ($data['ifi']) {
92+
case 'mbox': $authority['mbox'] = 'mailto:'.$data['mbox']; break;
93+
case 'mbox_sha1sum': $authority['mbox_sha1sum'] = $data['mbox_sha1sum']; break;
94+
case 'openid': $authority['openid'] = $data['openid']; break;
95+
case 'account': $authority['account'] = [
96+
'homePage' => $data['account_homePage'],
97+
'name' => $data['account_name']
98+
]; break;
99+
}
100+
101+
$data['authority'] = $authority;
102+
103+
if ($this->client->update($id, $data, ['lrs_id' => $lrs_id])) {
87104
$redirect_url = '/lrs/'.$lrs_id.'/client/manage#'.$id;
88105
return Redirect::to($redirect_url)->with('success', trans('lrs.client.updated'));
89106
}
90107

91108
return Redirect::back()
92109
->withInput()
93-
->withErrors($this->client->errors());
110+
->withErrors(['Error']);
94111
}
95112

96113
/**
@@ -100,7 +117,7 @@ public function update($lrs_id, $id){
100117
* @return View
101118
*/
102119
public function destroy($lrs_id, $id){
103-
if ($this->client->delete($id)) {
120+
if ($this->client->destroy($id, ['lrs_id' => $lrs_id])) {
104121
$message_type = 'success';
105122
$message = trans('lrs.client.delete_client_success');
106123
} else {

app/controllers/ExportingController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ public function __construct(LrsRepo $lrs){
1414
$this->beforeFilter('csrf', array('only' => array('update', 'store', 'destroy')));
1515
}
1616

17-
/**
17+
/**./ve
1818
* Display a listing of the resource.
1919
* @return View
2020
*/
21-
public function index($id){
21+
public function index($lrs_id){
2222
$opts = ['user' => \Auth::user()];
23-
$lrs = $this->lrs->show($id, $opts);
23+
$lrs = $this->lrs->show($lrs_id, $opts);
2424
$lrs_list = $this->lrs->index($opts);
2525
return View::make("{$this->views}.index", [
2626
'lrs' => $lrs,
2727
'list' => $lrs_list,
28-
'exporting_nav' => true
28+
'exporting_nav' => true,
29+
'client' => (new \Client)->where('lrs_id', $lrs_id)->first()
2930
]);
3031
}
3132
}

app/controllers/LrsController.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public function show($lrs_id) {
135135
return View::make('partials.lrs.dashboard', array_merge($this->getLrs($lrs_id), [
136136
'stats' => $dashboard->getStats(),
137137
'graph_data' => $dashboard->getGraphData(),
138-
'dash_nav' => true
138+
'dash_nav' => true,
139+
'client' => (new \Client)->where('lrs_id', $lrs_id)->first()
139140
]));
140141
}
141142

@@ -202,17 +203,6 @@ public function statements($lrs_id){
202203
]));
203204
}
204205

205-
/**
206-
* Display the endpoint view.
207-
* @param String $lrs_id
208-
* @return View
209-
*/
210-
public function endpoint($lrs_id) {
211-
return View::make('partials.lrs.endpoint', array_merge($this->getLrs($lrs_id), [
212-
'endpoint_nav' => true
213-
]));
214-
}
215-
216206
/**
217207
* Display the api view.
218208
* @param String $lrs_id
@@ -224,30 +214,6 @@ public function api($lrs_id) {
224214
]));
225215
}
226216

227-
/**
228-
* Generate a new key and secret for basic auth
229-
*
230-
**/
231-
public function editCredentials( $lrs_id ){
232-
$opts = ['user' => \Auth::user()];
233-
$lrs = $this->lrs->show($lrs_id);
234-
235-
$lrs->api = [
236-
'basic_key' => \Locker\Helpers\Helpers::getRandomValue(),
237-
'basic_secret' => \Locker\Helpers\Helpers::getRandomValue()
238-
];
239-
240-
if ($lrs->save()) {
241-
$message_type = 'success';
242-
$message = trans('update_key');
243-
} else {
244-
$message_type = 'error';
245-
$message = trans('update_key_error');
246-
}
247-
248-
return Redirect::back()->with($message_type, $message);
249-
}
250-
251217
/**
252218
* Display users with access to this lrs.
253219
* @param String $lrs_id

app/controllers/ReportingController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public function index($lrs_id) {
7373
'reporting_nav' => true,
7474
'reports' => $this->report->index([
7575
'lrs_id' => $lrs_id
76-
])
76+
]),
77+
'client' => (new \Client)->where('lrs_id', $lrs_id)->first()
7778
]));
7879
}
7980

app/controllers/xapi/BasicRequestController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace Controllers\xAPI;
22

3-
use Locker\Repository\Client\ClientRepository as Client;
3+
use Locker\Repository\Client\Repository as Client;
44

55
class BasicRequestController extends BaseController {
66

@@ -30,8 +30,8 @@ public function __construct(Client $client){
3030
public function store(){
3131
$content = \LockerRequest::getContent();
3232

33-
$data = ['lrs_id' => $this->lrs->_id];
34-
$client = $this->client->create( $data );
33+
$opts = ['lrs_id' => $this->lrs->_id];
34+
$client = $this->client->store([], $opts);
3535

3636
if($client){
3737
$returnCredentials = array(

app/controllers/xapi/StatementStoreController.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function store($lrs_id) {
6363
throw new Exceptions\Exception('Statement ID parameter is invalid.');
6464
}
6565

66-
return IlluminateResponse::json($this->createStatements($lrs_id), 200, Helpers::getCORSHeaders());
66+
return IlluminateResponse::json($this->createStatements($lrs_id), 200, $this->getCORSHeaders());
6767
}
6868

6969
/**
@@ -85,7 +85,7 @@ public function update($lrs_id) {
8585
return $statements;
8686
});
8787

88-
return IlluminateResponse::make('', 204, Helpers::getCORSHeaders());
88+
return IlluminateResponse::make('', 204, $this->getCORSHeaders());
8989
}
9090

9191
/**
@@ -131,26 +131,28 @@ private function createStatements($lrs_id, Callable $modifier = null) {
131131
}
132132

133133
private function getAuthority() {
134-
$authorization = \LockerRequest::header('Authorization');
135-
if (strpos($authorization, 'Basic') === 0) {
136-
$key = \LockerRequest::getUser();
137-
} else if (strpos($authorization, 'Bearer') === 0) {
138-
$key = Helpers::getClientIdFromOAuth($authorization);
139-
}
140-
141-
$client = (new \Client)
142-
->where('api.basic_key', $key)
143-
->first();
134+
list($username, $password) = Helpers::getUserPassFromAuth();
135+
$client = Helpers::getClient($username, $password);
144136

145-
if ($client != null && isset($client['authority'])) {
146-
return json_decode(json_encode($client['authority']));
147-
} else {
148-
$site = \Site::first();
149-
return (object) [
150-
'name' => $site->name,
151-
'mbox' => 'mailto:' . $site->email,
152-
'objectType' => 'Agent'
153-
];
137+
if ($client === null) {
138+
throw new Exceptions\Exception('No authority.');
154139
}
140+
141+
return json_decode(json_encode($client['authority']));
142+
}
143+
144+
/**
145+
* Gets the CORS headers.
146+
* @return [String => Mixed] CORS headers.
147+
*/
148+
private function getCORSHeaders() {
149+
return [
150+
'Access-Control-Allow-Origin' => \Request::root(),
151+
'Access-Control-Allow-Methods' => 'GET, PUT, POST, DELETE, OPTIONS',
152+
'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Requested-With, X-Experience-API-Version, X-Experience-API-Consistent-Through, Updated',
153+
'Access-Control-Allow-Credentials' => 'true',
154+
'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate(),
155+
'X-Experience-API-Version' => '1.0.1'
156+
];
155157
}
156158
}

app/database/migrations/2015_04_27_091532_add_xapi_scopes.php

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

app/database/migrations/2015_04_30_104958_sync_oauth_clients.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ public function up() {
1515
]);
1616
});
1717
(new \Lrs)->get()->each(function ($lrs) use ($db) {
18-
$db->insert([
19-
'client_id' => $lrs->api['basic_key'],
20-
'client_secret' => $lrs->api['basic_secret'],
21-
'redirect_uri' => 'http://www.example.com/'
22-
]);
18+
if (isset($lrs->api) && isset($lrs->api['basic_key']) && isset($lrs->api['basic_secret'])) {
19+
$db->insert([
20+
'client_id' => $lrs->api['basic_key'],
21+
'client_secret' => $lrs->api['basic_secret'],
22+
'redirect_uri' => 'http://www.example.com/'
23+
]);
24+
}
2325
});
2426
}
2527

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class LrsCredsToClient extends Migration {
7+
8+
public function up() {
9+
(new \Lrs)->get()->each(function ($lrs) {
10+
if (isset($lrs->api) && isset($lrs->api['basic_key']) && isset($lrs->api['basic_secret'])) {
11+
$client = new \Client();
12+
$client->api = $lrs->api;
13+
$client->lrs_id = $lrs->_id;
14+
$client->authority = [
15+
'name' => $lrs->title,
16+
'mbox' => 'mailto:[email protected]'
17+
];
18+
$client->save();
19+
}
20+
});
21+
}
22+
23+
public function down() {
24+
(new \Lrs)->get()->each(function ($lrs) {
25+
if (!isset($lrs->api) || !isset($lrs->api['basic_key']) || !isset($lrs->api['basic_secret'])) {
26+
$client = (new \Client())->where('lrs_id', $lrs->_id)->first();
27+
28+
if ($client !== null) {
29+
$lrs->api = $client->api;
30+
$lrs->save();
31+
}
32+
}
33+
});
34+
}
35+
36+
}

0 commit comments

Comments
 (0)