~automne-team/automne/4.2

« back to all changes in this revision

Viewing changes to automne/admin/login.php

  • Committer: sebastien
  • Date: 2008-11-26 17:12:36 UTC
  • Revision ID: sebastien_sebastien-20081126171236-16r3kxfuz2kmq2qe
Tags: V4_0_0a0
4.0.0a0 :
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
 
3
// +----------------------------------------------------------------------+
 
4
// | Automne (TM)                                                                                                                 |
 
5
// +----------------------------------------------------------------------+
 
6
// | Copyright (c) 2000-2009 WS Interactive                                                               |
 
7
// +----------------------------------------------------------------------+
 
8
// | Automne is subject to version 2.0 or above of the GPL license.               |
 
9
// | The license text is bundled with this package in the file                    |
 
10
// | LICENSE-GPL, and is available through the world-wide-web at                  |
 
11
// | http://www.gnu.org/copyleft/gpl.html.                                                                |
 
12
// +----------------------------------------------------------------------+
 
13
// | Author: S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>      |
 
14
// +----------------------------------------------------------------------+
 
15
//
 
16
// $Id: login.php,v 1.1.1.1 2008/11/26 17:12:05 sebastien Exp $
 
17
 
 
18
/**
 
19
  * PHP page : Login
 
20
  * Manages the login of users. Creates login window.
 
21
  *
 
22
  * @package CMS
 
23
  * @subpackage admin
 
24
  * @author S�bastien Pauchet <sebastien.pauchet@ws-interactive.fr>
 
25
  */
 
26
 
 
27
require_once($_SERVER["DOCUMENT_ROOT"]."/cms_rc_frontend.php");
 
28
 
 
29
define("MESSAGE_PAGE_LOGIN", 54);
 
30
define("MESSAGE_PAGE_PASSWORD", 55);
 
31
define("MESSAGE_PAGE_REMEMBER_ME", 1218);
 
32
define("MESSAGE_BUTTON_VALIDATE", 56);
 
33
define("MESSAGE_BUTTON_CANCEL", 180);
 
34
define("MESSAGE_PAGE_TITLE", 51);
 
35
define("MESSAGE_ERROR_LOGIN_INCORRECT", 50);
 
36
define("MESSAGE_ERROR_TITLE", 301);
 
37
define("MESSAGE_PAGE_LOGIN_IN_PROGRESS", 302);
 
38
define("MESSAGE_PAGE_REQUIRED_FIELD", 1239);
 
39
define("MESSAGE_ERROR_REQUIRED_FIELD", 303);
 
40
define("MESSAGE_PAGE_USER_WELCOME", 314);
 
41
define("MESSAGE_PAGE_USER_NOVALIDATION", 1113);
 
42
define("MESSAGE_PAGE_USER_VALIDATIONS", 315);
 
43
 
 
44
//load language object
 
45
$language = CMS_languagesCatalog::getDefaultLanguage(true);
 
46
//load interface instance
 
47
$view = CMS_view::getInstance();
 
48
//var used to display error of login
 
49
$loginError = '';
 
50
 
 
51
//Action management     
 
52
switch (isset($_POST["cms_action"])) {
 
53
case "login":
 
54
        $permanent = isset($_POST["permanent"]) ? $_POST["permanent"] : 0;
 
55
        $cms_context = new CMS_context($_POST["login"], $_POST["pass"], $permanent);
 
56
        if (!$cms_context->hasError()) {
 
57
                @session_start();
 
58
                $_SESSION["cms_context"] = $cms_context;
 
59
                $cms_user = $_SESSION["cms_context"]->getUser();
 
60
                //launch the daily routine in case it's not in the cron
 
61
                CMS_module_standard::processDailyRoutine();
 
62
                $userSessionsInfos = CMS_context::getSessionInfos();
 
63
                
 
64
                //welcome message
 
65
                $welcome = $language->getJsMessage(MESSAGE_PAGE_USER_WELCOME, array($userSessionsInfos['fullname']));
 
66
                if ($userSessionsInfos['hasValidations']) {
 
67
                        $welcome .= '<br /><br />'.(($userSessionsInfos['awaitingValidation']) ? $language->getJsMessage(MESSAGE_PAGE_USER_VALIDATIONS, array($userSessionsInfos['awaitingValidation'])) : $language->getJsMessage(MESSAGE_PAGE_USER_NOVALIDATION));
 
68
                }
 
69
                if (SYSTEM_DEBUG && $cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
 
70
                        $welcome .= '<br /><br /><span class="atm-red">Attention, le debuggage est actif.</span> Pressez F2 pour voir la fen�tre de log.';
 
71
                }
 
72
                
 
73
                //then set context, remove login window and load Automne interface
 
74
                $jscontent = '
 
75
                //set user context
 
76
                Automne.context = '.sensitiveIO::jsonEncode($userSessionsInfos).';
 
77
                //remove event closeAndBack on window
 
78
                Ext.WindowMgr.get(\'loginWindow\').un(\'close\', Ext.WindowMgr.get(\'loginWindow\').closeAndBack);
 
79
                //add event to load Automne interface after close
 
80
                Ext.WindowMgr.get(\'loginWindow\').on(\'close\', Automne.load);
 
81
                //display welcome message
 
82
                Automne.message.show(\''.sensitiveIO::sanitizeJSString($welcome).'\');
 
83
                if (Ext.Element.cache[\'loginField\']) {delete Ext.Element.cache[\'loginField\']};
 
84
                ';
 
85
                //add all JS locales
 
86
                $jscontent .= CMS_context::getJSLocales();
 
87
                $jscontent .= '
 
88
                //close login window
 
89
                Ext.WindowMgr.get(\'loginWindow\').close();';
 
90
                //eval content into parent
 
91
                $jscontent = '
 
92
                if (parent.Ext.Element.cache[\'loginField\']) {delete parent.Ext.Element.cache[\'loginField\']};
 
93
                parent.eval(\''.sensitiveIO::sanitizeJSString($jscontent, true).'\');';
 
94
                $view->addJavascript($jscontent);
 
95
                $view->show(CMS_view::SHOW_HTML);
 
96
        } else {
 
97
                //display error login window on top of login form
 
98
                $loginError = "
 
99
                parent.Automne.message.popup({
 
100
                        title: '{$language->getJsMessage(MESSAGE_ERROR_TITLE)}',
 
101
                        msg: '{$language->getJsMessage(MESSAGE_ERROR_LOGIN_INCORRECT)}',
 
102
                        buttons: Ext.MessageBox.OK,
 
103
                        icon: Ext.MessageBox.ERROR,
 
104
                        fn:function() {
 
105
                                Ext.fly('loginField').dom.select();
 
106
                        }
 
107
                });";
 
108
        }
 
109
        break;
 
110
default:
 
111
        // First attempt to obtain $_COOKIE information from domain
 
112
        if ((!isset($_REQUEST["cms_action"]) || $_REQUEST["cms_action"] != 'logout') && CMS_context::autoLoginSucceeded()) {
 
113
                $cms_user = $_SESSION["cms_context"]->getUser();
 
114
                //launch the daily routine incase it's not in the cron
 
115
                CMS_module_standard::processDailyRoutine();
 
116
                //then set context and load Automne interface
 
117
                $userSessionsInfos = CMS_context::getSessionInfos();
 
118
                //welcome message
 
119
                $welcome = $language->getJsMessage(MESSAGE_PAGE_USER_WELCOME, array($userSessionsInfos['fullname']));
 
120
                if ($userSessionsInfos['hasValidations']) {
 
121
                        $welcome .= '<br /><br />'.(($userSessionsInfos['awaitingValidation']) ? $language->getJsMessage(MESSAGE_PAGE_USER_VALIDATIONS, array($userSessionsInfos['awaitingValidation'])) : $language->getJsMessage(MESSAGE_PAGE_USER_NOVALIDATION));
 
122
                }
 
123
                if (SYSTEM_DEBUG && $cms_user->hasAdminClearance(CLEARANCE_ADMINISTRATION_EDITVALIDATEALL)) {
 
124
                        $welcome .= '<br /><br /><span class="atm-red">Attention, le debuggage est actif.</span> Pressez F2 pour voir la fen�tre de log.';
 
125
                }
 
126
                $jscontent = '
 
127
                //set user context
 
128
                Automne.context = '.sensitiveIO::jsonEncode($userSessionsInfos).';
 
129
                //load interface
 
130
                Automne.load();
 
131
                //display welcome message
 
132
                Automne.message.show(\''.sensitiveIO::sanitizeJSString($welcome).'\');
 
133
                ';
 
134
                //add all JS locales
 
135
                $jscontent .= CMS_context::getJSLocales();
 
136
                $view->addJavascript($jscontent);
 
137
                $view->show(CMS_view::SHOW_RAW);
 
138
        }
 
139
        // Reset cookie
 
140
        CMS_context::resetSessionCookies();
 
141
        break;
 
142
}
 
143
 
 
144
if (!isset($_GET['loginform'])) {
 
145
        //Send Login form window
 
146
        
 
147
        $applicationLabel = addcslashes(APPLICATION_LABEL, "'");
 
148
        $htmlForm = '<iframe id="formframe" width="100%" height="100%" frameborder="0" src="'.$_SERVER['SCRIPT_NAME'].'?loginform=true">&nbsp;</iframe>';
 
149
        $jscontent = 
 
150
<<<END
 
151
        var loginWindow = new Ext.Window({
 
152
                title:          '{$language->getJsMessage(MESSAGE_PAGE_TITLE, array($applicationLabel))}',
 
153
                id:                     'loginWindow',
 
154
                iconCls:        'atm-pic-logo',
 
155
                width:          400,
 
156
                height:         218,
 
157
                resizable:      false,
 
158
                modal:          true,
 
159
                layout:         'fit',
 
160
                plain:          true,
 
161
                bodyStyle:      'padding:5px;',
 
162
                buttonAlign:'center',
 
163
                html: '{$htmlForm}'
 
164
        });
 
165
        loginWindow.closeAndBack = function() {
 
166
                document.location.replace('/');
 
167
        };
 
168
        loginWindow.on('close', loginWindow.closeAndBack);
 
169
        loginWindow.show();
 
170
END;
 
171
        //send content
 
172
        $view->addJavascript($jscontent);
 
173
        $view->show(CMS_view::SHOW_RAW);
 
174
        
 
175
} else {
 
176
        //Send Login form frame window (in which login form is displayed)
 
177
        $view->addJSFile('ext');
 
178
        $view->addCSSFile('ext');
 
179
        
 
180
        $jscontent = 
 
181
<<<END
 
182
        Ext.onReady(function() {
 
183
                // turn on validation errors beside the field globally
 
184
                Ext.form.Field.prototype.msgTarget = 'under';
 
185
                var loginField = new Ext.form.TextField({
 
186
                        allowBlank:     false,
 
187
                        blankText:      '{$language->getJsMessage(MESSAGE_PAGE_REQUIRED_FIELD)}',
 
188
                        applyTo:        'loginField'
 
189
                });
 
190
                var passField = new Ext.form.TextField({
 
191
                        allowBlank:     false,
 
192
                        inputType:      'password',
 
193
                        blankText:      '{$language->getJsMessage(MESSAGE_PAGE_REQUIRED_FIELD)}',
 
194
                        applyTo:        'passField'
 
195
                });
 
196
                var cancelButton = new Ext.Button({
 
197
                        text:           '{$language->getJsMessage(MESSAGE_BUTTON_CANCEL)}',
 
198
                        handler:        function() {if (parent) {parent.Ext.WindowMgr.get('loginWindow').close();}},
 
199
                        applyTo:        'cancelButton'
 
200
                });
 
201
                var submitButton = new Ext.Button({
 
202
                        text:           '{$language->getJsMessage(MESSAGE_BUTTON_VALIDATE)}',
 
203
                        handler:        function() {loginForm.doSubmit();},
 
204
                        applyTo:        'submitButton'
 
205
                });
 
206
                var loginForm = new Ext.form.BasicForm("loginForm", {
 
207
                doSubmit:function(){
 
208
                                if (Ext.fly('loginField').dom.value && Ext.fly('passField').dom.value) {
 
209
                                        this.getEl().dom.submit();
 
210
                                } else {
 
211
                                        Ext.MessageBox.show({
 
212
                                                title: '{$language->getJsMessage(MESSAGE_ERROR_TITLE)}',
 
213
                                                msg: '{$language->getJsMessage(MESSAGE_ERROR_REQUIRED_FIELD)}',
 
214
                                                buttons: Ext.MessageBox.OK,
 
215
                                                icon: Ext.MessageBox.ERROR,
 
216
                                                fn:function() {
 
217
                                                        Ext.fly('loginField').dom.select();
 
218
                                                }
 
219
                                        });
 
220
                                }
 
221
                        }
 
222
            });
 
223
                //set enter keymap
 
224
                var map = new Ext.KeyMap("loginForm", {
 
225
                    key:                Ext.EventObject.ENTER,
 
226
                    fn:                 loginForm.doSubmit,
 
227
                        scope:          loginForm
 
228
                });
 
229
                //put focus on the first login field
 
230
                //if (Ext.get('loginField').dom.value){ alert('select');Ext.get('loginField').dom.select(); } else { alert('focus');Ext.get('loginField').focus();}
 
231
                //display login error window if any
 
232
                {$loginError}
 
233
        });
 
234
END;
 
235
        $view->addJavascript($jscontent);
 
236
        //set form HTML
 
237
        $content = '
 
238
        <div class="x-panel x-form-label-left" style="width: 374px;">
 
239
                <div class="x-panel-tl">
 
240
                        <div class="x-panel-tr">
 
241
                                <div class="x-panel-tc"></div>
 
242
                        </div>
 
243
                </div>
 
244
                <div class="x-panel-bwrap">
 
245
                        <div class="x-panel-ml">
 
246
                                <div class="x-panel-mr">
 
247
                                        <div class="x-panel-mc">
 
248
                                                <div style="width: 362px; height: 126px;" class="x-panel-body">
 
249
                                                        <form id="loginForm" class="x-form" method="post" action="login.php?loginform=true">
 
250
                                                                <input value="login" class="x-form-hidden x-form-field" size="20" autocomplete="on" name="cms_action" type="hidden" />
 
251
                                                                        <div class="x-form-item" tabindex="-1">
 
252
                                                                                <label for="loginField" style="width: 90px;" class="x-form-item-label">'.$language->getMessage(MESSAGE_PAGE_LOGIN).':</label>
 
253
                                                                                <div class="x-form-element" style="padding-left: 95px;">
 
254
                                                                                        <input style="width: 240px;" class="x-form-text x-form-field" autocomplete="on" id="loginField" name="login" type="text" value="'.(isset($_POST['login']) ? htmlspecialchars($_POST['login']) : '').'" />
 
255
                                                                                </div>
 
256
                                                                                <div class="x-form-clear-left"></div>
 
257
                                                                        </div>
 
258
                                                                        <div class="x-form-item" tabindex="-1">
 
259
                                                                                <label for="passField" style="width: 90px;" class="x-form-item-label">'.$language->getMessage(MESSAGE_PAGE_PASSWORD).':</label>
 
260
                                                                                <div class="x-form-element" style="padding-left: 95px;">
 
261
                                                                                        <input style="width: 240px;" class="x-form-text x-form-field" autocomplete="on" id="passField" name="pass" type="password" value="'.(isset($_POST['pass']) ? htmlspecialchars($_POST['pass']) : '').'" />
 
262
                                                                                </div>
 
263
                                                                                <div class="x-form-clear-left"></div>
 
264
                                                                        </div>
 
265
                                                                        <div class="x-form-item" tabindex="-1">
 
266
                                                                                <div class="x-form-element" style="padding-left: 95px;">
 
267
                                                                                        <label for="rememberField" class="x-form-item-label" style="width: 240px;">
 
268
                                                                                                <input value="1" class="x-form-checkbox x-form-field" size="20" autocomplete="on" id="rememberField" name="permanent" type="checkbox" />
 
269
                                                                                                '.$language->getMessage(MESSAGE_PAGE_REMEMBER_ME).'
 
270
                                                                                        </label>
 
271
                                                                                </div>
 
272
                                                                                <div class="x-form-clear-left"></div>
 
273
                                                                        </div>
 
274
                                                        </form>
 
275
                                                </div>
 
276
                                        </div>
 
277
                                </div>
 
278
                        </div>
 
279
                        <div class="x-panel-bl">
 
280
                                <div class="x-panel-br">
 
281
                                        <div class="x-panel-bc">
 
282
                                                <div class="x-panel-footer">
 
283
                                                        <div class="x-panel-btns-ct">
 
284
                                                                <div class="x-panel-btns x-panel-btns-center" id="formsButton">
 
285
                                                                        <table cellspacing="0">
 
286
                                                                                <tbody>
 
287
                                                                                        <tr>
 
288
                                                                                                <td class="x-panel-btn-td">
 
289
                                                                                                        <div id="submitButton"></div>
 
290
                                                                                                </td>
 
291
                                                                                                <td class="x-panel-btn-td">
 
292
                                                                                                        <div id="cancelButton"></div>
 
293
                                                                                                </td>
 
294
                                                                                        </tr>
 
295
                                                                                </tbody>
 
296
                                                                        </table>
 
297
                                                                        <div class="x-clear"></div>
 
298
                                                                </div>
 
299
                                                        </div>
 
300
                                                </div>
 
301
                                        </div>
 
302
                                </div>
 
303
                        </div>
 
304
                </div>
 
305
        </div>';
 
306
        //send content
 
307
        $view->setContent($content);
 
308
        $view->show(CMS_view::SHOW_HTML);
 
309
}
 
310
?>
 
 
b'\\ No newline at end of file'