Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / guest / what-login.php
index 0b6002d9ce7d294b6d4c568aec1dc22ba3fc7047..b3e272c6c57a42851b016cc1ce1bcca3f5351138 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/14/2003 *
- * ===============                              Last change: 04/28/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 10/14/2003 *
+ * ===================                          Last change: 04/28/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-login.php                                   *
  * Kurzbeschreibung  : Loginbereich (leitet an das richtige Lgin-Modul  *
  *                     weiter)                                          *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
 
 // Some security stuff...
 if (!defined('__SECURITY')) {
-       $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
-       require($INC);
-} elseif ((!EXT_IS_ACTIVE("user")) && (!IS_ADMIN())) {
-       addFatalMessage(EXTENSION_PROBLEM_EXT_INACTIVE, "user");
-       return;
+       die();
 }
 
 // Add description as navigation point
-ADD_DESCR("guest", __FILE__);
+addMenuDescription('guest', __FILE__);
 
-global $DATA, $ERROR;
+if ((!isExtensionActive('user')) && (!isAdmin())) {
+       loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
+       return;
+} // END - if
 
 // Initialize variables
-$ERROR = 0;
-$probe_nickname = false;
-$uid = false;
-$hash = "";
-$URL = "";
-$ADD = "";
+$errorCode = '0';
+$userid = false;
+$hash = '';
+$url = '';
+$add = '';
 
 // Already logged in?
-if ((!empty($GLOBALS['userid'])) && (isSessionVariableSet('u_hash'))) {
+if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) {
        // Maybe, then continue with it
-       $uid = $GLOBALS['userid'];
-} elseif ((!empty($_POST['id'])) && (!empty($_POST['password'])) && (isset($_POST['ok']))) {
+       $userid = getMemberId();
+} elseif ((isPostRequestParameterSet('id')) && (isPostRequestParameterSet('password')) && (isFormSent())) {
        // Set userid and crypt password when login data was submitted
-       if ((EXT_IS_ACTIVE("nickname")) && (NICKNAME_PROBE_ON_USERID($_POST['id']))) {
+       if ((isExtensionActive('nickname')) && (isNicknameUsed(postRequestParameter('id')))) {
                // Nickname entered
-               $uid = SQL_ESCAPE($_POST['id']);
+               $userid = SQL_ESCAPE(postRequestParameter('id'));
        } else {
                // Direct userid entered
-               $uid  = bigintval($_POST['id']);
+               $userid  = bigintval(postRequestParameter('id'));
        }
-} elseif (!empty($_POST['new_pass'])) {
+} elseif (isPostRequestParameterSet('new_pass')) {
        // New password requested
-       $uid = 0;
-       if (!empty($_POST['id'])) $uid = $_POST['id'];
+       $userid = '0';
+       if ((isPostRequestParameterSet('id')) && (postRequestParameter('id') > 0)) $userid = bigintval(postRequestParameter('id'));
 } else {
        // Not logged in
-       $uid = 0; $hash = "";
+       $userid = '0'; $hash = '';
 }
 
-// Set unset variables
-if (empty($_POST['new_pass'])) $_POST['new_pass'] = "";
-if (empty($_GET['login']))     $_GET['login']     = "";
-
-if (IS_MEMBER()) {
+if (isMember()) {
        // Login immidiately...
-       $URL = "modules.php?module=login";
-} elseif ((isset($_POST['ok'])) && ("".$uid."" != "".$_POST['id']."")) {
+       $url = 'modules.php?module=login';
+} elseif ((isFormSent()) && ('' . $userid . '' != '' . postRequestParameter('id') . '')) {
        // Invalid input (no nickname extension installed but nickname entered)
-       $ERROR = constant('CODE_EXTENSION_PROBLEM');
-} elseif (isset($_POST['ok'])) {
+       $errorCode = getCode('EXTENSION_PROBLEM');
+} elseif (isFormSent()) {
        // Try the login (see inc/libs/user_functions.php)
-       $URL = USER_DO_LOGIN($_POST['id'], $_POST['password']);
-} elseif ((!empty($_POST['new_pass'])) && (isset($uid))) {
+       $url = doUserLogin(postRequestParameter('id'), postRequestParameter('password'));
+} elseif ((isPostRequestParameterSet('new_pass')) && (isset($userid))) {
        // Try the userid/email lookup (see inc/libs/user_functions.php)
-       $ERROR = USER_DO_NEW_PASSWORD($_POST['email'], $uid);
+       $errorCode = doNewUserPassword(postRequestParameter('email'), $userid);
 }
 
 // Login problems?
-if (!empty($_GET['login'])) {
+if (isGetRequestParameterSet('login')) {
        // Use code from URL
-       $ERROR = SQL_ESCAPE($_GET['login']);
+       $errorCode = getRequestParameter('login');
 } // END  - if
 
+// No problems, no output by detault
+$content['message'] = '';
+
 // Login problems?
-if (!empty($ERROR)) {
-       // Ok, which one now?
-       $MSG = "<tr>
-  <td width=\"10\" class=\"seperator\">&nbsp;</td>
-  <td colspan=\"7\" align=\"center\">
+if (!empty($errorCode)) {
+       // @TODO Move this HTML code into a template
+       $message = "<tr>
+  <td colspan=\"4\" align=\"center\">
     <span class=\"guest_failed\">";
 
-       switch ($ERROR) {
-               case constant('CODE_WRONG_PASS'):
-                       $MSG .= getMessage('LOGIN_WRONG_PASS');
-                       break;
-
-               case constant('CODE_WRONG_ID'):
-                       $MSG .= getMessage('LOGIN_WRONG_ID');
-                       break;
+       // Do we have a userid set?
+       if (isSessionVariableSet('current_userid')) {
+               // Then prefetch data for this account
+               fetchUserData(getSession('current_userid'));
+       } // END - if
 
-               case constant('CODE_ID_LOCKED'):
-                       $MSG .= getMessage('LOGIN_ID_LOCKED');
-                       break;
+       // Convert the code to message
+       $message .= getMessageFromErrorCode($errorCode);
 
-               case constant('CODE_ID_UNCONFIRMED'):
-                       $MSG .= getMessage('LOGIN_ID_UNCONFIRMED');
-                       break;
-
-               case constant('CODE_NO_COOKIES'):
-                       $MSG .= getMessage('LOGIN_NO_COOKIES');
-                       break;
-
-               case constant('CODE_EXTENSION_PROBLEM'):
-                       if (IS_ADMIN()) {
-                               $MSG .= sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), "nickname");
-                       } else {
-                               $MSG .= getMessage('LOGIN_WRONG_ID');
-                       }
-                       break;
-
-               default:
-                       DEBUG_LOG(__FILE__, __LINE__, sprintf("Unhandled error code %s detected.", $ERROR));
-                       $MSG .= getMessage('LOGIN_WRONG_ID');
-                       break;
-               }
-               $MSG .= "</span>
+       // Continue with HTML
+       $message .= "</span>
   </td>
-  <td width=\"10\" class=\"seperator\">&nbsp;</td>
 </tr>\n";
-               define('LOGIN_FAILURE_MSG', $MSG);
-} else {
-       // No problems, no output
-       define('LOGIN_FAILURE_MSG', "");
-}
+       $content['message'] = $message;
+} // END - if
 
 // Display login form with resend-password form
-if (EXT_IS_ACTIVE("nickname")) {
-       LOAD_TEMPLATE("guest_nickname_login");
+if (isExtensionActive('nickname')) {
+       loadTemplate('guest_nickname_login', false, $content);
 } else {
-       LOAD_TEMPLATE("guest_login");
+       loadTemplate('guest_login', false, $content);
 }
 
 // Was an URL constructed?
-if (!empty($URL)) {
+if (!empty($url)) {
        // URL was constructed
-       if (getTotalFatalErrors()) {
-               // Fatal errors!
-               LOAD_INC_ONCE("inc/fatal_errors.php");
+       if (ifFatalErrorsDetected()) {
+               // Handle fatal errors
+               runFilterChain('handle_fatal_errors');
        } else {
                // Load URL
-               LOAD_URL($URL);
+               redirectToUrl($url);
        }
 } // END - if
 
-//
+// [EOF]
 ?>