Dotclear

source: admin/auth.php @ 27:3bde88e1fff6

Revision 27:3bde88e1fff6, 10.7 KB checked in by kozlika, 13 years ago (diff)

Message de connexion, ajustements css

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15# If we have a session cookie, go to index.php
16if (isset($_SESSION['sess_user_id']))
17{
18     http::redirect('index.php');
19}
20
21# Loading locales for detected language
22# That's a tricky hack but it works ;)
23$dlang = http::getAcceptLanguage();
24if ($dlang != 'en')
25{
26     l10n::set(dirname(__FILE__).'/../locales/'.$dlang.'/main');
27}
28
29$page_url = http::getHost().$_SERVER['REQUEST_URI'];
30
31$change_pwd = $core->auth->allowPassChange() && isset($_POST['new_pwd']) && isset($_POST['new_pwd_c']) && isset($_POST['login_data']);
32$login_data = !empty($_POST['login_data']) ? $_POST['login_data'] : null;
33$recover = $core->auth->allowPassChange() && !empty($_REQUEST['recover']);
34$akey = $core->auth->allowPassChange() && !empty($_GET['akey']) ? $_GET['akey'] : null;
35$user_id = $user_pwd = $user_key = $user_email = null;
36$err = $msg = null;
37
38# Auto upgrade
39if (empty($_GET) && empty($_POST)) {
40     require dirname(__FILE__).'/../inc/dbschema/upgrade.php';
41     try {
42          if (($changes = dotclearUpgrade($core)) !== false) {
43               $msg = __('Dotclear has been upgraded.').'<!-- '.$changes.' -->';
44          }
45     } catch (Exception $e) {
46          $err = $e->getMessage();
47     }
48}
49
50# If we have POST login informations, go throug auth process
51if (!empty($_POST['user_id']) && !empty($_POST['user_pwd']))
52{
53     $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
54     $user_pwd = !empty($_POST['user_pwd']) ? $_POST['user_pwd'] : null;
55}
56# If we have COOKIE login informations, go throug auth process
57elseif (isset($_COOKIE['dc_admin']) && strlen($_COOKIE['dc_admin']) == 104)
58{
59     # If we have a remember cookie, go through auth process with user_key
60     $user_id = substr($_COOKIE['dc_admin'],40);
61     $user_id = @unpack('a32',@pack('H*',$user_id));
62     if (is_array($user_id))
63     {
64          $user_id = $user_id[1];
65          $user_key = substr($_COOKIE['dc_admin'],0,40);
66          $user_pwd = null;
67     }
68     else
69     {
70          $user_id = null;
71     }
72}
73
74# Recover password
75if ($recover && !empty($_POST['user_id']) && !empty($_POST['user_email']))
76{
77     $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
78     $user_email = !empty($_POST['user_email']) ? $_POST['user_email'] : '';
79     try
80     {
81          $recover_key = $core->auth->setRecoverKey($user_id,$user_email);
82         
83          $subject = mail::B64Header('DotClear '.__('Password reset'));
84          $message =
85          __('Someone has requested to reset the password for the following site and username.')."\n\n".
86          $page_url."\n".__('Username:').' '.$user_id."\n\n".
87          __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.')."\n".
88          $page_url.'?akey='.$recover_key;
89         
90          $headers[] = 'From: dotclear@'.$_SERVER['HTTP_HOST'];
91          $headers[] = 'Content-Type: text/plain; charset=UTF-8;';
92         
93          mail::sendMail($user_email,$subject,$message,$headers);
94          $msg = sprintf(__('The e-mail was sent successfully to %s.'),$user_email);
95     }
96     catch (Exception $e)
97     {
98          $err = $e->getMessage();
99     }
100}
101# Send new password
102elseif ($akey)
103{
104     try
105     {
106          $recover_res = $core->auth->recoverUserPassword($akey);
107         
108          $subject = mb_encode_mimeheader('DotClear '.__('Your new password'),'UTF-8','B');
109          $message =
110          __('Username:').' '.$recover_res['user_id']."\n".
111          __('Password:').' '.$recover_res['new_pass']."\n\n".
112          preg_replace('/\?(.*)$/','',$page_url);
113         
114          $headers[] = 'From: dotclear@'.$_SERVER['HTTP_HOST'];
115          $headers[] = 'Content-Type: text/plain; charset=UTF-8;';
116         
117          mail::sendMail($recover_res['user_email'],$subject,$message,$headers);
118          $msg = __('Your new password is in your mailbox.');
119     }
120     catch (Exception $e)
121     {
122          $err = $e->getMessage();
123     }
124}
125# Change password and retry to log
126elseif ($change_pwd and $data = unserialize(base64_decode($_POST['login_data'])))
127{
128     # Check login informations
129     $check_user = false;
130     if (isset($data['cookie_admin']) && strlen($data['cookie_admin']) == 104)
131     {
132          $user_id = substr($data['cookie_admin'],40);
133          $user_id = @unpack('a32',@pack('H*',$user_id));
134          if (is_array($user_id))
135          {
136               $user_id = $user_id[1];
137               $user_key = substr($data['cookie_admin'],0,40);
138               $check_user = $core->auth->checkUser($user_id,null,$user_key) === true;
139          }
140     }
141     
142     try
143     {
144          if (!$core->auth->allowPassChange() || !$check_user) {
145               $change_pwd = false;
146               throw new Exception();
147          }
148         
149          if ($_POST['new_pwd'] != $_POST['new_pwd_c']) {
150               throw new Exception(__("Passwords don't match"));
151          }
152         
153          if ($core->auth->checkUser($user_id,$_POST['new_pwd']) === true) {
154               throw new Exception(__("You didn't change your password."));
155          }
156         
157          $cur = $core->con->openCursor($core->prefix.'user');
158          $cur->user_change_pwd = 0;
159          $cur->user_pwd = $_POST['new_pwd'];
160          $core->updUser($core->auth->userID(),$cur);
161         
162          $core->session->start();
163          $_SESSION['sess_user_id'] = $user_id;
164          $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY);
165         
166          if (!empty($data['blog_id'])) {
167               $_SESSION['sess_blog_id'] = $data['blog_id'];
168          }
169         
170          if (!empty($data['user_remember']))
171          {
172               setcookie('dc_admin',$data['cookie_admin'],strtotime('+15 days'),'','',DC_ADMIN_SSL);
173          }
174         
175          http::redirect('index.php');
176     }
177     catch (Exception $e)
178     {
179          $err = $e->getMessage();
180     }
181}
182# Try to log
183elseif ($user_id !== null && ($user_pwd !== null || $user_key !== null))
184{
185     # We check the user
186     $check_user = $core->auth->checkUser($user_id,$user_pwd,$user_key) === true;
187     
188     $cookie_admin = http::browserUID(DC_MASTER_KEY.$user_id.
189          crypt::hmac(DC_MASTER_KEY,$user_pwd)).bin2hex(pack('a32',$user_id));
190     
191     if ($check_user && $core->auth->mustChangePassword())
192     {
193          $login_data = base64_encode(serialize(array(
194               'user_id'=>$user_id,
195               'cookie_admin'=>$cookie_admin,
196               'blog_id'=>(!empty($_POST['blog']) ? $_POST['blog'] : ''),
197               'user_remember'=>!empty($_POST['user_remember'])
198          )));
199         
200          if (!$core->auth->allowPassChange()) {
201               $err = __('You have to change your password before you can login.');
202          } else {
203               $err = __('In order to login, you have to change your password now.');
204               $change_pwd = true;
205          }
206     }
207     elseif ($check_user)
208     {
209          $core->session->start();
210          $_SESSION['sess_user_id'] = $user_id;
211          $_SESSION['sess_browser_uid'] = http::browserUID(DC_MASTER_KEY);
212         
213          if (!empty($_POST['blog'])) {
214               $_SESSION['sess_blog_id'] = $_POST['blog'];
215          }
216         
217          if (!empty($_POST['user_remember'])) {
218               setcookie('dc_admin',$cookie_admin,strtotime('+15 days'),'','',DC_ADMIN_SSL);
219          }
220         
221          http::redirect('index.php');
222     }
223     else
224     {
225          if (isset($_COOKIE['dc_admin'])) {
226               unset($_COOKIE['dc_admin']);
227               setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL);
228          }
229          $err = __('Wrong username or password');
230     }
231}
232
233if (isset($_GET['user'])) {
234     $user_id = $_GET['user'];
235}
236
237header('Content-Type: text/html; charset=UTF-8');
238?>
239<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
240<html xmlns="http://www.w3.org/1999/xhtml"
241xml:lang="en" lang="en">
242<head>
243  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
244  <meta http-equiv="Content-Script-Type" content="text/javascript" />
245  <meta http-equiv="Content-Style-Type" content="text/css" />
246  <meta http-equiv="Content-Language" content="en" />
247  <meta name="MSSmartTagsPreventParsing" content="TRUE" />
248  <meta name="ROBOTS" content="NOARCHIVE,NOINDEX,NOFOLLOW" />
249  <meta name="GOOGLEBOT" content="NOSNIPPET" />
250  <title><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></title>
251 
252<?php
253echo dcPage::jsLoadIE7();
254echo dcPage::jsCommon();
255?>
256 
257  <style type="text/css">
258  @import url(style/default.css);
259  </style>
260  <?php
261  # --BEHAVIOR-- loginPageHTMLHead
262  $core->callBehavior('loginPageHTMLHead');
263  ?>
264 
265  <script type="text/javascript">
266  //<![CDATA[
267  $(window).load(function() {
268    var uid = $('input[name=user_id]');
269    var upw = $('input[name=user_pwd]');
270    uid.focus();
271   
272    if (upw.length == 0) { return; }
273   
274    if ($.browser.mozilla) {
275      uid.keypress(processKey);
276    } else {
277      uid.keydown(processKey);
278    }
279    function processKey(evt) {
280      if (evt.keyCode == 13 && upw.val() == '') {
281         upw.focus();
282         return false;
283      }
284      return true;
285    };
286  });
287  //]]>
288  </script>
289</head>
290
291<body id="dotclear-admin" class="auth">
292
293<form action="auth.php" method="post" id="login-screen">
294<h1><?php echo html::escapeHTML(DC_VENDOR_NAME); ?></h1>
295
296<?php
297if ($err) {
298     echo '<div class="error">'.$err.'</div>';
299}
300if ($msg) {
301     echo '<p class="message">'.$msg.'</p>';
302}
303
304if ($akey)
305{
306     echo '<p><a href="auth.php">'.__('Back to login screen').'</a></p>';
307}
308elseif ($recover)
309{
310     echo
311     '<fieldset><legend>'.__('Request a new password').'</legend>'.
312     '<p><label for="user_id">'.__('Username:').' '.
313     form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id),'',1).'</label></p>'.
314     
315     '<p><label for="user_email">'.__('Email:').' '.
316     form::field(array('user_email','user_email'),20,255,html::escapeHTML($user_email),'',2).'</label></p>'.
317     
318     '<p><input type="submit" value="'.__('recover').'" tabindex="3" />'.
319     form::hidden(array('recover'),1).'</p>'.
320     '</fieldset>'.
321     
322     '<p><a href="auth.php">'.__('Back to login screen').'</a></p>';
323}
324elseif ($change_pwd)
325{
326     echo
327     '<fieldset><legend>'.__('Change your password').'</legend>'.
328     '<p><label for="new_pwd">'.__('New password:').' '.
329     form::password(array('new_pwd','new_pwd'),20,255,'','',1).'</label></p>'.
330     
331     '<p><label for="new_pwd_c">'.__('Confirm password:').' '.
332     form::password(array('new_pwd_c','new_pwd_c'),20,255,'','',2).'</label></p>'.
333     '</fielset>'.
334     
335     '<p><input type="submit" value="'.__('change').'" />'.
336     form::hidden('login_data',$login_data).'</p>';
337}
338else
339{
340     if (is_callable(array($core->auth,'authForm')))
341     {
342          echo $core->auth->authForm($user_id);
343     }
344     else
345     {
346          echo
347          '<fieldset>';
348          echo
349          '<p><label for="user_id">'.__('Username:').' '.
350          form::field(array('user_id','user_id'),20,32,html::escapeHTML($user_id),'',1).'</label></p>'.
351         
352          '<p><label for="user_pwd">'.__('Password:').' '.
353          form::password(array('user_pwd','user_pwd'),20,255,'','',2).'</label></p>'.
354         
355          '<p><label class="classic">'.
356          '<p><label for="user_remember" class="classic">'.
357          form::checkbox(array('user_remember','user_remember'),1,'','',3).' '.
358          __('Remember my ID on this computer').'</label></p>'.
359         
360          '<p><input type="submit" value="'.__('log in').'" tabindex="4" /></p>';
361         
362          if (!empty($_REQUEST['blog'])) {
363               echo form::hidden('blog',html::escapeHTML($_REQUEST['blog']));
364          }
365         
366          echo
367          '</fieldset>'.
368         
369          '<p>'.__('You must accept cookies in order to use the private area.').'</p>';
370         
371          if ($core->auth->allowPassChange()) {
372               echo '<p><a href="auth.php?recover=1">'.__('I forgot my password').'</a></p>';
373          }
374     }
375}
376?>
377</form>
378</body>
379</html>
Note: See TracBrowser for help on using the repository browser.

Sites map