Commit | Line | Data |
---|---|---|
4ca6cfbf | 1 | <?php |
f25a6839 SH |
2 | // This file is part of Moodle - http://moodle.org/ |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * Login block | |
19 | * | |
20 | * @package block_login | |
21 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
284dc1a1 | 24 | |
e89d741a | 25 | class block_login extends block_base { |
9b4b78fd | 26 | function init() { |
2de43a56 | 27 | $this->title = get_string('pluginname', 'block_login'); |
284dc1a1 | 28 | } |
29 | ||
30 | function applicable_formats() { | |
2b0d60ec | 31 | return array('site' => true); |
284dc1a1 | 32 | } |
33 | ||
34 | function get_content () { | |
3e82b7ac | 35 | global $USER, $CFG, $SESSION, $OUTPUT; |
813320fb JL |
36 | require_once($CFG->libdir . '/authlib.php'); |
37 | ||
284dc1a1 | 38 | $wwwroot = ''; |
39 | $signup = ''; | |
40 | ||
41 | if ($this->content !== NULL) { | |
42 | return $this->content; | |
43 | } | |
44 | ||
b58764ff | 45 | $wwwroot = $CFG->wwwroot; |
4ca6cfbf | 46 | |
813320fb JL |
47 | if (signup_is_enabled()) { |
48 | $signup = $wwwroot . '/login/signup.php'; | |
284dc1a1 | 49 | } |
16ce6c0d | 50 | // TODO: now that we have multiauth it is hard to find out if there is a way to change password |
51 | $forgot = $wwwroot . '/login/forgot_password.php'; | |
284dc1a1 | 52 | |
4eaee2c8 | 53 | |
8a8f1c7c | 54 | $username = get_moodle_cookie(); |
792197b0 | 55 | |
b85b25eb | 56 | $this->content = new stdClass(); |
c009421c | 57 | $this->content->footer = ''; |
58 | $this->content->text = ''; | |
59 | ||
083c3743 | 60 | if (!isloggedin() or isguestuser()) { // Show the block |
1f5be49d PS |
61 | if (empty($CFG->authloginviaemail)) { |
62 | $strusername = get_string('username'); | |
63 | } else { | |
64 | $strusername = get_string('usernameemail'); | |
65 | } | |
c009421c | 66 | |
83806582 | 67 | $this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'">'; |
c009421c | 68 | |
3d977703 DW |
69 | $this->content->text .= '<div class="form-group">'; |
70 | $this->content->text .= '<label for="login_username">'.$strusername.'</label>'; | |
71 | $this->content->text .= '<input type="text" name="username" id="login_username" '; | |
72 | $this->content->text .= ' class="form-control" value="'.s($username).'" autocomplete="username"/></div>'; | |
c009421c | 73 | |
1efacd2b | 74 | $this->content->text .= '<div class="form-group"><label for="login_password">'.get_string('password').'</label>'; |
aa30d3e8 | 75 | |
3d977703 DW |
76 | $this->content->text .= '<input type="password" name="password" id="login_password" '; |
77 | $this->content->text .= ' class="form-control" value="" autocomplete="current-password"/>'; | |
78 | $this->content->text .= '</div>'; | |
c009421c | 79 | |
0342fc36 PS |
80 | if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) { |
81 | $checked = $username ? 'checked="checked"' : ''; | |
7508e218 SL |
82 | $this->content->text .= '<div class="form-check">'; |
83 | $this->content->text .= '<label class="form-check-label">'; | |
84 | $this->content->text .= '<input type="checkbox" name="rememberusername" id="rememberusername" | |
85 | class="form-check-input" value="1" '.$checked.'/> '; | |
86 | $this->content->text .= get_string('rememberusername', 'admin').'</label>'; | |
1efacd2b | 87 | $this->content->text .= '</div>'; |
0342fc36 PS |
88 | } |
89 | ||
1efacd2b | 90 | $this->content->text .= '<div class="form-group">'; |
6dc4c68e | 91 | $this->content->text .= '<input type="submit" class="btn btn-primary btn-block" value="'.get_string('login').'" />'; |
1efacd2b | 92 | $this->content->text .= '</div>'; |
6dfe4283 | 93 | $this->content->text .= '<input type="hidden" name="logintoken" value="'.s(\core\session\manager::get_login_token()).'" />'; |
808c2a69 | 94 | |
95 | $this->content->text .= "</form>\n"; | |
c009421c | 96 | |
284dc1a1 | 97 | if (!empty($signup)) { |
3e82b7ac | 98 | $this->content->text .= '<div><a href="'.$signup.'">'.get_string('startsignup').'</a></div>'; |
c009421c | 99 | } |
100 | if (!empty($forgot)) { | |
3e82b7ac RK |
101 | $this->content->text .= '<div><a href="'.$forgot.'">'.get_string('forgotaccount').'</a></div>'; |
102 | } | |
103 | ||
104 | $authsequence = get_enabled_auth_plugins(true); // Get all auths, in sequence. | |
105 | $potentialidps = array(); | |
106 | foreach ($authsequence as $authname) { | |
107 | $authplugin = get_auth_plugin($authname); | |
876fc282 | 108 | $potentialidps = array_merge($potentialidps, $authplugin->loginpage_idp_list($this->page->url->out(false))); |
3e82b7ac RK |
109 | } |
110 | ||
111 | if (!empty($potentialidps)) { | |
112 | $this->content->text .= '<div class="potentialidps">'; | |
113 | $this->content->text .= '<h6>' . get_string('potentialidps', 'auth') . '</h6>'; | |
114 | $this->content->text .= '<div class="potentialidplist">'; | |
115 | foreach ($potentialidps as $idp) { | |
f59d81f4 | 116 | $this->content->text .= '<div class="potentialidp">'; |
29551c4b | 117 | $this->content->text .= '<a class="btn btn-secondary btn-block" '; |
f59d81f4 DW |
118 | $this->content->text .= 'href="' . $idp['url']->out() . '" title="' . s($idp['name']) . '">'; |
119 | if (!empty($idp['iconurl'])) { | |
120 | $this->content->text .= '<img src="' . s($idp['iconurl']) . '" width="24" height="24" class="m-r-1"/>'; | |
121 | } | |
122 | $this->content->text .= s($idp['name']) . '</a></div>'; | |
3e82b7ac RK |
123 | } |
124 | $this->content->text .= '</div>'; | |
125 | $this->content->text .= '</div>'; | |
284dc1a1 | 126 | } |
284dc1a1 | 127 | } |
c009421c | 128 | |
284dc1a1 | 129 | return $this->content; |
130 | } | |
131 | } |