source: branches/2.2/mobile/login.php @ 3553

Revision 3553, 5.6 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1404 - Criada a página de login do Expresso Mini.

Line 
1<?php
2        //TODO: Trocar name="login" para name="user" no campo username
3
4        $phpgw_info = array();
5        $submit = False;
6
7        $GLOBALS['phpgw_info']['flags'] = array(
8                'disable_Template_class' => True,
9                'login'                  => True,
10                'currentapp'             => 'login',
11                'currentdir'             => '/mobile',
12                'noheader'               => True
13        );
14
15        include('../header.inc.php');
16        include('./mobile_header.inc.php');
17        $GLOBALS['sessionid'] = @$_GET['sessionid'] ? $_GET['sessionid'] : @$_COOKIE['sessionid'];
18
19        if(isset($GLOBALS['sessionid']) && $_GET['cd'] != 10 && $_GET['cd'] != 1)
20                start_prefered_app();
21               
22        if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)  {
23                if ($_SERVER['HTTPS'] != 'on') {
24                        $proxies=explode(',',$_SERVER['HTTP_X_FORWARDED_HOST']);
25            $fwConstruct = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $proxies[0] : $_SERVER['HTTP_HOST'];
26                        Header('Location: https://' . $fwConstruct . '/' . $_SERVER['REQUEST_URI']);
27                        exit;
28                }
29        }
30
31        $GLOBALS['phpgw']->session = CreateObject('phpgwapi.sessions');
32        $GLOBALS['phpgw_info']['server']['template_dir'] = PHPGW_SERVER_ROOT.$GLOBALS['phpgw_info']['flags']['currentdir'].'/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'];
33        $tmpl = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
34        $GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] = $GLOBALS['phpgw_info']['login_template_set'];
35        $tmpl->set_file(array('login_form' => 'login.tpl'));
36        $tmpl->set_block('login_form','page');
37        $tmpl->set_block('login_form','success_message');
38        $tmpl->set_block('login_form','error_message');
39       
40        //verificando a mensagem erro ou sucesso
41        $cd = check_logoutcode($_GET['cd']);
42        $tmpl->set_var('cd', $cd);
43       
44        if(trim($cd) != "")
45                $tmpl->parse('message_box', (($_GET['cd'] == 1) ? 'success_message' : 'error_message') ,True);
46       
47        $tmpl->set_var('css',CreateObject("mobile.mobiletemplate")->get_mobile_css());
48
49        function check_logoutcode($code) {
50                switch($code) {
51                        case 1:
52                                logout();
53                                return lang('You have been successfully logged out');
54                        case 2:
55                                return lang('Sorry, your login has expired');
56                        case 4:
57                                return lang('Cookies are required to login to this site.');
58                        case 5:
59                                return lang('Bad login or password');
60                        case 6:
61                                return lang('Your password has expired, and you do not have access to change it');
62                        case 98:
63                                return lang('Account is expired');
64                        case 99:
65                                return lang('Blocked, too many attempts');
66                        case 10:
67                                $GLOBALS['phpgw']->session->phpgw_setcookie('sessionid');
68                                $GLOBALS['phpgw']->session->phpgw_setcookie('kp3');
69                                $GLOBALS['phpgw']->session->phpgw_setcookie('domain');
70                                if($GLOBALS['phpgw_info']['server']['sessions_type'] == 'php4') {
71                                        $GLOBALS['phpgw']->session->phpgw_setcookie(PHPGW_PHPSESSID);
72                                }
73                                return lang('Your session could not be verified.');
74                        default:
75                                return '';
76                }
77        }
78
79        if($GLOBALS['phpgw_info']['server']['auth_type'] == 'http' && isset($_SERVER['PHP_AUTH_USER'])) {
80                $submit = True;
81                $login  = $_SERVER['PHP_AUTH_USER'];
82                $passwd = $_SERVER['PHP_AUTH_PW'];
83                $passwd_type = 'text';
84        }
85        else {
86                $passwd = $_POST['passwd'];
87                $passwd_type = $_POST['passwd_type'];
88        }
89
90        if(isset($passwd_type) || $_POST['submitit_x'] || $_POST['submitit_y'] || $submit) {
91                if(getenv('REQUEST_METHOD') != 'POST' && $_SERVER['REQUEST_METHOD'] != 'POST' &&
92                        !isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['SSL_CLIENT_S_DN'])){
93                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link($GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php','cd=5'));
94                }
95
96                if(!$submit)
97                        $login = $_POST['login'];
98
99                $GLOBALS['sessionid'] = $GLOBALS['phpgw']->session->create(strtolower($login),$passwd,$passwd_type,'u');
100
101                if(!isset($GLOBALS['sessionid']) || ! $GLOBALS['sessionid']){
102                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw_info']['server']['webserver_url'] .$GLOBALS['phpgw_info']['flags']['currentdir'].'/login.php?cd=' . $GLOBALS['phpgw']->session->cd_reason);
103                }
104                else{
105                        start_prefered_app();
106                }
107        }
108        elseif ($_GET['lang'])  {
109                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $_GET['lang'];
110        }
111        elseif(!isset($_COOKIE['last_loginid']) || !$prefs->account_id) {
112                list($lang) = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
113                $GLOBALS['phpgw_info']['user']['preferences']['common']['lang'] = $lang;
114        }
115
116        $tmpl->set_var('charset',$GLOBALS['phpgw']->translation->charset());
117        $tmpl->set_var('cookie',$last_loginid);
118        $tmpl->set_var('lang_username', lang('username'));
119        $tmpl->set_var('lang_password', lang('password'));
120        $tmpl->set_var('lang_login', lang('login'));
121        $tmpl->set_var('lang_notices', lang('notices'));
122        $tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
123        $tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
124        $tmpl->set_var('language_select','');
125        $tmpl->set_var($var);
126        $tmpl->set_block('login_form','language_select');
127        $tmpl->pfp('loginout','page');
128
129        function logout(){
130                $verified = $GLOBALS['phpgw']->session->verify();
131                if ($verified)
132                {
133                        if (file_exists($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']))
134                        {
135                                $dh = opendir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']);
136                                while ($file = readdir($dh))
137                                {
138                                        if ($file != '.' && $file != '..')
139                                        {
140                                                unlink($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid'] . SEP . $file);
141                                        }
142                                }
143                                rmdir($GLOBALS['phpgw_info']['server']['temp_dir'] . SEP . $GLOBALS['sessionid']);
144                        }
145                        $GLOBALS['phpgw']->hooks->process('logout');
146                        $GLOBALS['phpgw']->session->destroy($GLOBALS['sessionid'],$GLOBALS['kp3']);
147                }
148        }
149?>
Note: See TracBrowser for help on using the repository browser.