forked from hypercities/hypercities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticateCollection.php
More file actions
88 lines (80 loc) · 2.9 KB
/
authenticateCollection.php
File metadata and controls
88 lines (80 loc) · 2.9 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
<?php
/**
* Verify that a user is able to see a collection when it's loaded as the base
* collection. Used for Moodle integration.
*
* 1. When a user arrives at index.php, if $_SESSION['baseCollection'] is set, and
* $_SESSION['baseCollectionAuthenticated'] is not set, or is false, they are
* redirected to authenticateCollection.php.
* 2. authenticateCollection.php authenticates by checking Moodle (or another remote
* server). If authentication is successful
* a. set $_SESSION["baseCollectionAuthenticated"] to true
* b. redirect to index.php.
* c. If authentication fails, redirect to authFailure.php?reason=notEnrolled
* 3. When index.php checks if baseCollectionAuthenticated is set, and it is,
* it sets a javascript variable, which loads HyperCities at that collection.
*/
namespace HyperCities\Provider\Authentication;
\ini_set ("display_errors", 1);
require_once "includes/serverSession.inc";
require_once "includes/database.inc";
require_once "provider/core/Exception.inc";
require_once "provider/authentication/Encryptor.php";
//require_once "provider/core/Log.inc";
require_once "provider/core/DelayedLogger.inc";
require_once "provider/core/Message.php";
require_once "provider/authentication/AuthenticationManager.inc";
require_once "provider/authentication/Exceptions.inc";
require_once "provider/authentication/Messages.inc";
require_once "provider/authentication/PermissionSet.inc";
require_once "provider/authentication/User.inc";
use \cServerSession;
use \database;
use HyperCities\Provider\Log;
use HyperCities\Provider\RemoteConnectionFailure;
Log::start();
function redirect($url) {
Log::store();
header('Location: '.$url);
die();
}
$baseCollection = \cServerSession::getVar("baseCollection");
if ($baseCollection) {
Log::write("Base Collection set: $baseCollection");
$user = new User(\cServerSession::getUserId());
// print_r ($user);
// print "\nBase Collection: ";
// print $baseCollection;
try {
$permissions = AuthenticationManager::checkExternalCollection($baseCollection, $user);
if ($permissions === TRUE) {
cServerSession::setVar('baseCollectionAuthenticated', TRUE);
//header("Location: index.php?");
//die();
redirect("index.php?");
}
if ($permissions->view) {
cServerSession::setVar('baseCollectionAuthenticated', TRUE);
//header("Location: index.php?collections/$baseCollection");
//die();
redirect("index.php?collections/$baseCollection");
} else {
cServerSession::unsetVar('baseCollection');
//print_r ($permissions);
//die();
redirect("authFailure.php?reason=notEnrolled");
//die();
}
} catch (RemoteConnectionFailure $ex) {
//print_r ($ex);
Log::write(print_r ($ex, TRUE));
//print "There was a problem trying to authenticate you.";
//die();
//Log::store();
redirect ("authFailure.php?reason=remoteConnectionFailure");
//die();
}
} else {
Log::write("No base collection set.");
}
?>