[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/blocks/login/ -> block_login.php (source)

   1  <?php
   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   */
  24  
  25  class block_login extends block_base {
  26      function init() {
  27          $this->title = get_string('pluginname', 'block_login');
  28      }
  29  
  30      function applicable_formats() {
  31          return array('site' => true);
  32      }
  33  
  34      function get_content () {
  35          global $USER, $CFG, $SESSION;
  36          $wwwroot = '';
  37          $signup = '';
  38  
  39          if ($this->content !== NULL) {
  40              return $this->content;
  41          }
  42  
  43          if (empty($CFG->loginhttps)) {
  44              $wwwroot = $CFG->wwwroot;
  45          } else {
  46              // This actually is not so secure ;-), 'cause we're
  47              // in unencrypted connection...
  48              $wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
  49          }
  50  
  51          if (!empty($CFG->registerauth)) {
  52              $authplugin = get_auth_plugin($CFG->registerauth);
  53              if ($authplugin->can_signup()) {
  54                  $signup = $wwwroot . '/login/signup.php';
  55              }
  56          }
  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';
  59  
  60          if (!empty($CFG->loginpasswordautocomplete)) {
  61              $autocomplete = 'autocomplete="off"';
  62          } else {
  63              $autocomplete = '';
  64          }
  65  
  66          $username = get_moodle_cookie();
  67  
  68          $this->content = new stdClass();
  69          $this->content->footer = '';
  70          $this->content->text = '';
  71  
  72          if (!isloggedin() or isguestuser()) {   // Show the block
  73              if (empty($CFG->authloginviaemail)) {
  74                  $strusername = get_string('username');
  75              } else {
  76                  $strusername = get_string('usernameemail');
  77              }
  78  
  79              $this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'" '.$autocomplete.'>';
  80  
  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>';
  83  
  84              $this->content->text .= '<div class="c1 fld password"><label for="login_password">'.get_string('password').'</label>';
  85  
  86              $this->content->text .= '<input type="password" name="password" id="login_password" value="" '.$autocomplete.' /></div>';
  87  
  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>';
  92              }
  93  
  94              $this->content->text .= '<div class="c1 btn"><input type="submit" value="'.get_string('login').'" /></div>';
  95  
  96              $this->content->text .= "</form>\n";
  97  
  98              if (!empty($signup)) {
  99                  $this->content->footer .= '<div><a href="'.$signup.'">'.get_string('startsignup').'</a></div>';
 100              }
 101              if (!empty($forgot)) {
 102                  $this->content->footer .= '<div><a href="'.$forgot.'">'.get_string('forgotaccount').'</a></div>';
 103              }
 104          }
 105  
 106          return $this->content;
 107      }
 108  }
 109  
 110  


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1