Skip to content

Commit 29657b4

Browse files
committed
Adição de bloco para login e logout
1 parent 5943cbf commit 29657b4

File tree

6 files changed

+190
-0
lines changed

6 files changed

+190
-0
lines changed
+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
class block_login_logout extends block_base {
4+
public function init() {
5+
$this->title = get_string('pluginname', 'block_login_logout');
6+
}
7+
8+
public function applicable_formats() {
9+
return array('all' => true);
10+
}
11+
12+
public function specialization() {
13+
if (!isloggedin() or isguestuser()) {
14+
$this->title = get_string('login');
15+
} else {
16+
$utz = timezone_offset_get(); //get_user_timezone_offset();
17+
if ($utz == 99) {
18+
$ut = (date('G')*3600 + date('i')*60 + date('s'))/3600;
19+
} else {
20+
$ut = ((gmdate('G') + timezone_offset_get() /*get_user_timezone_offset()*/ )*3600 + gmdate('i')*60 + gmdate('s'))/3600;
21+
If ($ut <= 0) { $ut = 24 + $ut; }
22+
If ($ut > 24) { $ut = $ut - 24; }
23+
}
24+
if ($ut < 12) {
25+
$this->title = get_string('morning_greeting', 'block_login_logout');
26+
} elseif (($ut >=12 ) and ($ut < 19 )) {
27+
$this->title = get_string('afternoon_greeting', 'block_login_logout');
28+
} else {
29+
$this->title = get_string('night_greeting', 'block_login_logout');
30+
}
31+
}
32+
}
33+
34+
public function get_content () {
35+
global $USER, $CFG, $OUTPUT, $SESSION, $COURSE;
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+
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
47+
}
48+
49+
if (!empty($CFG->registerauth)) {
50+
$authplugin = get_auth_plugin($CFG->registerauth);
51+
if ($authplugin->can_signup()) {
52+
$signup = $wwwroot . '/login/signup.php';
53+
}
54+
}
55+
$forgot = $wwwroot . '/login/forgot_password.php';
56+
57+
$username = get_moodle_cookie();
58+
59+
$this->content->footer = '';
60+
$this->content->text = '';
61+
62+
if (!isloggedin() or isguestuser()) {
63+
64+
$this->content->text .= html_writer::start_tag('form', array('class'=>'loginform', 'id'=>'login', 'method'=>'post', 'action'=>get_login_url()));
65+
$this->content->text .= html_writer::start_tag('div', array('class'=>'c1 fld username'));
66+
$this->content->text .= html_writer::tag('label', get_string('username'), array('for'=>'login_username'));
67+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>'username', 'id'=>'login_username', 'value'=>s($username)));
68+
$this->content->text .= html_writer::end_tag('div');
69+
$this->content->text .= html_writer::start_tag('div', array('class'=>'c1 fld password'));
70+
$this->content->text .= html_writer::tag('label', get_string('password'), array('for'=>'login_password'));
71+
72+
if (!empty($CFG->loginpasswordautocomplete)) {
73+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'password', 'name'=>'password', 'id'=>'login_password', 'value'=>'', 'autocomplete'=>'off'));
74+
} else {
75+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'password', 'name'=>'password', 'id'=>'login_password', 'value'=>''));
76+
}
77+
78+
$this->content->text .= html_writer::end_tag('div');
79+
80+
if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) {
81+
$this->content->text .= html_writer::start_tag('div', array('class'=>'c1 rememberusername'));
82+
if ($username) {
83+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'rememberusername', 'id'=>'rememberusername', 'value'=>'1', 'checked'=>'checked'));
84+
} else {
85+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'checkbox', 'name'=>'rememberusername', 'id'=>'rememberusername', 'value'=>'1'));
86+
}
87+
$label_rememberusername = ' '.get_string('rememberusername', 'admin');
88+
$this->content->text .= html_writer::tag('label', $label_rememberusername, array('for'=>'rememberusername'));
89+
$this->content->text .= html_writer::end_tag('div');
90+
}
91+
92+
$this->content->text .= html_writer::start_tag('div', array('class'=>'c1 btn'));
93+
$this->content->text .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('login')));
94+
$this->content->text .= html_writer::end_tag('div');
95+
$this->content->text .= html_writer::end_tag('form');
96+
97+
if (!empty($signup)) {
98+
$this->content->footer .= html_writer::start_tag('div');
99+
$this->content->footer .= html_writer::link(new moodle_url($signup), get_string('startsignup'));
100+
$this->content->footer .= html_writer::end_tag('div');
101+
}
102+
if (!empty($forgot)) {
103+
$this->content->footer .= html_writer::start_tag('div');
104+
$this->content->footer .= html_writer::link(new moodle_url($forgot), get_string('forgotaccount'));
105+
$this->content->footer .= html_writer::end_tag('div');
106+
}
107+
108+
} else {
109+
110+
$this->content->text .= html_writer::start_tag('div', array('class'=>'logoutusername'));
111+
$this->content->text .= html_writer::link(new moodle_url('/user/profile.php', array('id'=>$USER->id)), fullname($USER));
112+
$this->content->text .= html_writer::end_tag('div');
113+
$this->content->text .= html_writer::tag('div', $OUTPUT->user_picture($USER, array('size'=>90, 'class'=>'profilepicture')), array('class'=>'logoutuserimg'));
114+
$this->content->text .= html_writer::start_tag('div', array('class'=>'logoutbtn'));
115+
$this->content->text .= html_writer::link(new moodle_url('/login/logout.php', array('sesskey'=>sesskey())), html_writer::tag('button', get_string('logout'), array('type'=>'button')));
116+
$this->content->text .= html_writer::end_tag('div');
117+
$this->content->text .= html_writer::start_tag('div', array('class'=>'logoutfooter'));
118+
$this->content->text .= html_writer::link(new moodle_url('/user/editadvanced.php', array('id'=>$USER->id)), get_string('updatemyprofile'));
119+
$this->content->text .= html_writer::end_tag('div');
120+
if($USER->lastlogin){
121+
$logout_footer = get_string('lastlogin').'<br>'.userdate($USER->lastlogin, get_string('strftimerecentfull')).'<br> ('.format_time(time() - $USER->lastlogin).')';
122+
$this->content->text .= html_writer::tag('div', $logout_footer, array('class'=>'logoutfooter'));
123+
}
124+
}
125+
126+
return $this->content;
127+
}
128+
}
129+
130+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$string['pluginname'] = 'Login/Logout';
4+
$string['morning_greeting'] = 'Good Morning';
5+
$string['afternoon_greeting'] = 'Good Afternoon';
6+
$string['night_greeting'] = 'Good Evening';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$string['pluginname'] = 'Entrar/Salir';
4+
$string['morning_greeting'] = 'Buenos D&iacute;as';
5+
$string['afternoon_greeting'] = 'Buenas Tardes';
6+
$string['night_greeting'] = 'Buenas Noches';

blocks/login_logout/readme.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
According to Arthur Andersen, "ease of use"/navigation is the first reason (74%) what makes a person want to come back after to use a website. User should easily find options for login and logout a website. Most sites use the same module to enter and exit. Login block of moodle dissapears after user is logged.
2+
3+
I built a block that provides login and logout options. It has two views: first is like to standard login block and changes to the second view when user is logged, showing the following information:
4+
�Greeting: Good Morning, Good Afternoon or Good Evening is displayed in block header. It is shown according to user's timezone.
5+
�User full Name: linked to user's profile.
6+
�User's image: linked to user's profile.
7+
�Logout Button: click to exit moodle.
8+
�Update Profile: linked to user data in advanced edit mode.
9+
�Last login: shows date and time of the last user login.
10+
11+
How to install
12+
13+
� Download and unzip login_logout.zip file
14+
� Copy login_logout folder to /blocks folder of your moodle installation
15+
� Login as Administrator, if plugin check page is displayed, click upgrade button, otherwise go to Notifications page.
16+
� Click on "Turn editing on"
17+
� Add "Login/Logout" block in your frontpage (if standard login block is added, remove it). It can be added in others moodle areas too (mymoodle, courses, etc.)
18+
� Select a good position for your new block and move it
19+
� It has two language files: english and spanish. Other language users can make a copy of the folder /login_logout/lang/en, rename it and translate strings in the file block_login_logout.php
20+
21+
That's all.
22+
Enjoy!
23+
24+
Luis De Sousa
25+
IMYCA - Facultad de Ingenier�a
26+
Universidad de Carabobo
27+
Venezuela

blocks/login_logout/styles.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.block_login_logout .loginform .c1 {font-size:12px; margin:0px 2px 4px 0px;text-align:right;}
2+
.block_login_logout .loginform .c1.fld input {width:5em;}
3+
.block_login_logout .loginform .c1.fld label {padding-right:3px;}
4+
.block_login_logout .loginform .c1.btn {text-align:center;}
5+
.block_login_logout .loginform .c1.btn input {padding:2px 10px 2px 10px;}
6+
7+
.block_login_logout .logoutusername, .logoutuserimg {text-align:center; font-size:10pt; padding:2px;}
8+
.block_login_logout .logoutbtn {text-align:center; font-size:10pt;}
9+
.block_login_logout .logoutbtn button {padding:2px 10px 2px 10px;}
10+
.block_login_logout .logoutfooter {text-align:center; font-size:8pt; padding:2px;}
11+
12+

blocks/login_logout/version.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
defined('MOODLE_INTERNAL') || die();
4+
5+
$plugin->version = 2012032422; // The current plugin version (Date: YYYYMMDDXX)
6+
$plugin->requires = 2011120100; // Requires this Moodle version
7+
$plugin->component = 'block_login_logout'; // Full name of the plugin (used for diagnostics)
8+
$plugin->maturity = MATURITY_STABLE;
9+
$plugin->release = '2.0 (Build: 2012032422)';

0 commit comments

Comments
 (0)