forked from 0k/multidomain-sso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
127 lines (99 loc) · 2.61 KB
/
index.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
<?php
require_once "vendor/autoload.php";
require_once "config.php";
require_once "oeauth.php";
$oe = new OEAuth($config["oe"]["url"], $config["oe"]["dbname"]);
$bad_login = False;
$is_auth = $oe->is_auth();
$was_auth = $is_auth;
if ($is_auth) {
if (isset($_REQUEST["action"]) && $_REQUEST["action"] == "logout") {
$oe->deauthenticate();
$is_auth = False;
};
} else {
if (isset($_POST["action"])) {
$oe->authenticate($_POST);
$is_auth = $oe->is_auth();
if (!$is_auth) $bad_login = True;
};
}
$authentication_msg = "<p id='status'>You are " . ($is_auth?"<span class='green'>authentified</span>":"unknown") .
" here, on " . $_SERVER['HTTP_HOST'] ."</p>";
if (!$is_auth) {
// refresh toward a login page/widget
$form_content = "login: <input type='text' name='login' /><br/>";
$form_content .= "password: <input type='text' name='password' /><br/>";
$form_content .= "<input type='submit' name='action' value='login' />";
} else {
$form_content = "<input type='submit' name='action' value='logout' />";
}
/*
* HTML CODE
*/
?><html>
<head>
<title>Serving from <?php echo $_SERVER['HTTP_HOST']; ?></title>
<script src="/lib/jquery/jquery.js" type="text/javascript" > </script>
<style type="text/css">
body, div {
font-family: arial;
padding: 5px;
}
div#domain-list {
float: right;
border: #aaa 1px solid;
padding: 5px;
font-size: 80%;
background-color: #eee;
}
div#session {
float: left;
background-color: #ff8;
}
span.green {
color: green;
}
div.clear {
clear: both;
}
em.bad-login {
font-weight: bold;
color: red;
}
</style>
<?php echo $oe->js_code_for_propagate(); ?>
</head>
<body>
<?php echo $authentication_msg; ?>
<div id="domain-list">These domain shares authentication info:
<?php
foreach($config["urls"] as $url) {
echo "<li><a href='$url'>$url</a></li>";
}
?>
</div>
<div id="session">
<?php if ($bad_login) echo "<em class='bad-login'>Bad login !</em>"; ?>
<form method="post">
<?php echo $form_content; ?>
</form>
</div>
<div class="clear" />
<?php
if ($is_auth) {
echo "Sample OpenERP query which requires login: <pre>";
$partners = $oe->read(array(
'model' => 'res.partner',
'fields' => array('name', 'city'),
));
foreach($partners['records'] as $partner) {
echo "<li>" . $partner["name"] . " - " . $partner["city"] . "</li>";
}
echo "</pre>";
} else {
echo "<em>You are not authorized, you should try to login with 'admin', and 'demo' as password.</em>";
};
?>
</body>
</html>