2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
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
25 class block_login
extends block_base
{
27 $this->title
= get_string('pluginname', 'block_login');
30 function applicable_formats() {
31 return array('site' => true);
34 function get_content () {
35 global $USER, $CFG, $SESSION;
39 if ($this->content
!== NULL) {
40 return $this->content
;
43 if (empty($CFG->loginhttps
)) {
44 $wwwroot = $CFG->wwwroot
;
46 // This actually is not so secure ;-), 'cause we're
47 // in unencrypted connection...
48 $wwwroot = str_replace("http://", "https://", $CFG->wwwroot
);
51 if (!empty($CFG->registerauth
)) {
52 $authplugin = get_auth_plugin($CFG->registerauth
);
53 if ($authplugin->can_signup()) {
54 $signup = $wwwroot . '/login/signup.php';
57 // TODO: now that we have multiauth it is hard to find out if there is a way to change password
58 $forgot = $wwwroot . '/login/forgot_password.php';
60 if (!empty($CFG->loginpasswordautocomplete
)) {
61 $autocomplete = 'autocomplete="off"';
66 $username = get_moodle_cookie();
68 $this->content
= new stdClass();
69 $this->content
->footer
= '';
70 $this->content
->text
= '';
72 if (!isloggedin() or isguestuser()) { // Show the block
73 if (empty($CFG->authloginviaemail
)) {
74 $strusername = get_string('username');
76 $strusername = get_string('usernameemail');
79 $this->content
->text
.= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'" '.$autocomplete.'>';
81 $this->content
->text
.= '<div class="c1 fld username"><label for="login_username">'.$strusername.'</label>';
82 $this->content
->text
.= '<input type="text" name="username" id="login_username" value="'.s($username).'" /></div>';
84 $this->content
->text
.= '<div class="c1 fld password"><label for="login_password">'.get_string('password').'</label>';
86 $this->content
->text
.= '<input type="password" name="password" id="login_password" value="" '.$autocomplete.' /></div>';
88 if (isset($CFG->rememberusername
) and $CFG->rememberusername
== 2) {
89 $checked = $username ?
'checked="checked"' : '';
90 $this->content
->text
.= '<div class="c1 rememberusername"><input type="checkbox" name="rememberusername" id="rememberusername" value="1" '.$checked.'/>';
91 $this->content
->text
.= ' <label for="rememberusername">'.get_string('rememberusername', 'admin').'</label></div>';
94 $this->content
->text
.= '<div class="c1 btn"><input type="submit" value="'.get_string('login').'" /></div>';
96 $this->content
->text
.= "</form>\n";
98 if (!empty($signup)) {
99 $this->content
->footer
.= '<div><a href="'.$signup.'">'.get_string('startsignup').'</a></div>';
101 if (!empty($forgot)) {
102 $this->content
->footer
.= '<div><a href="'.$forgot.'">'.get_string('forgotaccount').'</a></div>';
106 return $this->content
;