|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class block_login extends block_base { 00004 function init() { 00005 $this->title = get_string('pluginname', 'block_login'); 00006 } 00007 00008 function applicable_formats() { 00009 return array('site' => true); 00010 } 00011 00012 function get_content () { 00013 global $USER, $CFG, $SESSION; 00014 $wwwroot = ''; 00015 $signup = ''; 00016 00017 if ($this->content !== NULL) { 00018 return $this->content; 00019 } 00020 00021 if (empty($CFG->loginhttps)) { 00022 $wwwroot = $CFG->wwwroot; 00023 } else { 00024 // This actually is not so secure ;-), 'cause we're 00025 // in unencrypted connection... 00026 $wwwroot = str_replace("http://", "https://", $CFG->wwwroot); 00027 } 00028 00029 if (!empty($CFG->registerauth)) { 00030 $authplugin = get_auth_plugin($CFG->registerauth); 00031 if ($authplugin->can_signup()) { 00032 $signup = $wwwroot . '/login/signup.php'; 00033 } 00034 } 00035 // TODO: now that we have multiauth it is hard to find out if there is a way to change password 00036 $forgot = $wwwroot . '/login/forgot_password.php'; 00037 00038 if (empty($CFG->xmlstrictheaders) and !empty($CFG->loginpasswordautocomplete)) { 00039 $autocomplete = 'autocomplete="off"'; 00040 } else { 00041 $autocomplete = ''; 00042 } 00043 00044 $username = get_moodle_cookie(); 00045 00046 $this->content = new stdClass(); 00047 $this->content->footer = ''; 00048 $this->content->text = ''; 00049 00050 if (!isloggedin() or isguestuser()) { // Show the block 00051 00052 $this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'" '.$autocomplete.'>'; 00053 00054 $this->content->text .= '<div class="c1 fld username"><label for="login_username">'.get_string('username').'</label>'; 00055 $this->content->text .= '<input type="text" name="username" id="login_username" value="'.s($username).'" /></div>'; 00056 00057 $this->content->text .= '<div class="c1 fld password"><label for="login_password">'.get_string('password').'</label>'; 00058 00059 $this->content->text .= '<input type="password" name="password" id="login_password" value="" '.$autocomplete.' /></div>'; 00060 00061 if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) { 00062 $checked = $username ? 'checked="checked"' : ''; 00063 $this->content->text .= '<div class="c1 rememberusername"><input type="checkbox" name="rememberusername" id="rememberusername" value="1" '.$checked.'/>'; 00064 $this->content->text .= ' <label for="rememberusername">'.get_string('rememberusername', 'admin').'</label></div>'; 00065 } 00066 00067 $this->content->text .= '<div class="c1 btn"><input type="submit" value="'.get_string('login').'" /></div>'; 00068 00069 $this->content->text .= "</form>\n"; 00070 00071 if (!empty($signup)) { 00072 $this->content->footer .= '<div><a href="'.$signup.'">'.get_string('startsignup').'</a></div>'; 00073 } 00074 if (!empty($forgot)) { 00075 $this->content->footer .= '<div><a href="'.$forgot.'">'.get_string('forgotaccount').'</a></div>'; 00076 } 00077 } 00078 00079 return $this->content; 00080 } 00081 } 00082 00083