-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock_openid.php
More file actions
160 lines (137 loc) · 5.8 KB
/
block_openid.php
File metadata and controls
160 lines (137 loc) · 5.8 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
<?php
/**
* OpenID block
*
* This block provides a simple login form for your site's side bars. It
* displays content appropriate for the user's state so, for example, it will
* direct the user the the actions.php script if they are logged in and allowed
* to amend their account or the login form if they aren't logged in.
*
* @author Brent Boghosian <brent.boghosian@remote-learner.net>
* @copyright Copyright (c) 2011 Remote-Learner
* @author Stuart Metcalfe <info@pdl.uk.com>
* @copyright Copyright (c) 2007 Canonical
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package openid
**/
require_once("{$CFG->dirroot}/auth/openid/locallib.php");
class block_openid extends block_base {
function init() {
$this->title = get_string('pluginname','block_openid');
$this->version = 2013022014;
}
function applicable_formats() {
return array('site' => true);
}
function get_content() {
global $USER, $CFG, $DB, $OUTPUT;
// We don't want to show this block if OpenID auth isn't enabled
if (!is_enabled_auth('openid')) {
return '';
}
$config = get_config('auth/openid');
$user_is_openid = isset($USER->auth) && ($USER->auth == 'openid');
$user_loggedin = !user_not_loggedin();
// Check to see if the box should be displayed to a logged in user
if ($user_loggedin) {
// We don't want to allow admin users to be changed
if (is_siteadmin($USER->id)) {
return '';
}
if (!isset($config->auth_openid_allow_account_change)) {
$config->auth_openid_allow_account_change='true';
}
if (!isset($config->auth_openid_allow_multiple)) {
$config->auth_openid_allow_multiple='true';
}
$allow_change = ($config->auth_openid_allow_account_change == 'true');
$allow_append = ($config->auth_openid_allow_multiple == 'true');
if (($user_is_openid && !$allow_append) || (!$user_is_openid && !$allow_change)) {
return '';
}
}
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->footer = ''; // too much space using this for change pwd
$this->content->text = '';
$username = (get_moodle_cookie() === 'nobody')
? '' : get_moodle_cookie();
$user = get_complete_user_data('username', $username);
if (empty($user) || $user->auth != 'openid' || $user_loggedin) {
$username='';
}
if ($user_loggedin) {
$endpoint = $CFG->wwwroot.'/auth/openid/actions.php';
} else {
$endpoint = $CFG->wwwroot.'/login/index.php';
}
$this->content->text .= '
<style type="text/css">
input.openid_login {
background: url('.$CFG->wwwroot.'/auth/openid/icon.gif) no-repeat;
background-color: #fff;
background-position: 0 50%;
color: #000;
padding-left: 18px;
}
</style>
<form class="loginform" name="login" method="post" action="'.$endpoint.'" onsubmit="if (document.login.openid_url.value == \'\') return false;" >
<table align="center" cellpadding="2" cellspacing="0" class="logintable">
';
if ($user_loggedin) {
$this->content->text .= '<tr><td class="c0 r0" colspan="2"><small>';
if ($user_is_openid) {
$this->content->text .= '<input type="hidden" name="openid_action" value="append" />';
$this->content->text .= get_string('append_text',
'block_openid');
} else {
$this->content->text .= '<input type="hidden" name="openid_action" value="change" />';
$this->content->text .= get_string('change_text',
'block_openid');
}
$this->content->text .= ':</small></td></tr>';
}
$this->content->text .= '
<tr>
<td class="c0 r1" colspan="2">
<input class="openid_login" type="text" name="openid_url" size="15" value="" />
</td>
</tr>
';
$this->content->text .=
'<tr>
<td class="c0 r2" align="left">
<a href="http://openid.net/" target="newWindow"><small>'.get_string('whats_this', 'auth_openid').'</small></a>
</td>
<td class="c1 r2" align="center">
<input type="submit" value="'.get_string('login').'" />
</td>
</tr>
';
$authplugin = get_auth_plugin('openid');
if (!$user_loggedin || $authplugin->can_change_password()) {
$this->content->text .=
'<tr>
<td colspan="2" class="c1 r3" align="center">';
if (!$user_loggedin) {
$this->content->text .=
'<a href="'.$CFG->wwwroot.'/auth/openid/fallback.php"><small>'.get_string('provider_offline', 'auth_openid')."</small></a>\n";
}
if ($authplugin->can_change_password()) {
$this->content->text .=
'<a href="'.$authplugin->change_password_url().'"><small>'. get_string('openid_manage', 'auth_openid') ."</small></a>\n";
}
$this->content->text .=
'</td>
</tr>
';
}
$this->content->text .=
'</table>
</form>
';
return $this->content;
}
}