Huge rewrite of default parameters, ext-network continued:
[mailer.git] / inc / modules / guest / what-login.php
index c0f493ff823eb197e41efa43566c637860984017..901f7b8c69dfadb4dd53372f62ab0634abd85b58 100644 (file)
@@ -18,7 +18,7 @@
  * 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                           *
  * 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(__FILE__, __LINE__, sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), 'user'));
-       return;
+       die();
 }
 
 // Add description as navigation point
-ADD_DESCR('guest', __FILE__);
+addMenuDescription('guest', __FILE__);
 
-global $DATA;
+if ((!isExtensionActive('user')) && (!isAdmin())) {
+       loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
+       return;
+} // END - if
 
 // Initialize variables
-$errorCode = 0;
-$probe_nickname = false;
-$uid = false;
+$errorCode = '0';
+$userid = false;
 $hash = '';
 $URL = '';
 $add = '';
 
 // Already logged in?
-if ((isUserIdSet()) && (isSessionVariableSet('u_hash'))) {
+if ((isMemberIdSet()) && (isSessionVariableSet('u_hash'))) {
        // Maybe, then continue with it
-       $uid = getUserId();
-} elseif ((REQUEST_ISSET_POST('id')) && (REQUEST_ISSET_POST(('password'))) && (IS_FORM_SENT())) {
+       $userid = getMemberId();
+} elseif ((isPostRequestElementSet('id')) && (isPostRequestElementSet('password')) && (isFormSent())) {
        // Set userid and crypt password when login data was submitted
-       if ((EXT_IS_ACTIVE('nickname')) && (NICKNAME_PROBE_ON_USERID(REQUEST_POST('id')))) {
+       if ((isExtensionActive('nickname')) && (isNicknameOrUserid(postRequestElement('id')))) {
                // Nickname entered
-               $uid = SQL_ESCAPE(REQUEST_POST('id'));
+               $userid = SQL_ESCAPE(postRequestElement('id'));
        } else {
                // Direct userid entered
-               $uid  = bigintval(REQUEST_POST('id'));
+               $userid  = bigintval(postRequestElement('id'));
        }
-} elseif (REQUEST_ISSET_POST(('new_pass'))) {
+} elseif (isPostRequestElementSet('new_pass')) {
        // New password requested
-       $uid = 0;
-       if (REQUEST_ISSET_POST('id')) $uid = REQUEST_POST('id');
+       $userid = '0';
+       if (isPostRequestElementSet('id')) $userid = bigintval(postRequestElement('id'));
 } else {
        // Not logged in
-       $uid = 0; $hash = '';
+       $userid = '0'; $hash = '';
 }
 
-// Set unset variables
-if (!REQUEST_ISSET_POST(('new_pass'))) REQUEST_SET_POST('new_pass', '');
-if (!REQUEST_ISSET_GET(('login')))     REQUEST_SET_GET('login'    , '');
-
-if (IS_MEMBER()) {
+if (isMember()) {
        // Login immidiately...
        $URL = 'modules.php?module=login';
-} elseif ((IS_FORM_SENT()) && (''.$uid.'' != ''.REQUEST_POST('id') . '')) {
+} elseif ((isFormSent()) && ('' . $userid . '' != '' . postRequestElement('id') . '')) {
        // Invalid input (no nickname extension installed but nickname entered)
        $errorCode = getCode('EXTENSION_PROBLEM');
-} elseif (IS_FORM_SENT()) {
+} elseif (isFormSent()) {
        // Try the login (see inc/libs/user_functions.php)
-       $URL = USER_DO_LOGIN(REQUEST_POST('id'), REQUEST_POST('password'));
-} elseif ((REQUEST_ISSET_POST(('new_pass'))) && (isset($uid))) {
+       $URL = doUserLogin(postRequestElement('id'), postRequestElement('password'));
+} elseif ((isPostRequestElementSet('new_pass')) && (isset($userid))) {
        // Try the userid/email lookup (see inc/libs/user_functions.php)
-       $errorCode = USER_DO_NEW_PASSWORD(REQUEST_POST('email'), $uid);
+       $errorCode = doNewUserPassword(postRequestElement('email'), $userid);
 }
 
 // Login problems?
-if (REQUEST_ISSET_GET(('login'))) {
+if (isGetRequestElementSet('login')) {
        // Use code from URL
-       $errorCode = REQUEST_GET(('login'));
+       $errorCode = getRequestElement('login');
 } // END  - if
 
+// No problems, no output by detault
+$content['message'] = '';
+
 // Login problems?
 if (!empty($errorCode)) {
-       // Ok, which one now?
+       // @TODO Move this HTML code into a template
        $message = "<tr>
   <td width=\"10\" class=\"seperator\">&nbsp;</td>
   <td colspan=\"7\" align=\"center\">
     <span class=\"guest_failed\">";
 
-       switch ($errorCode) {
-               case getCode('WRONG_PASS'):
-                       $message .= getMessage('LOGIN_WRONG_PASS');
-                       break;
-
-               case getCode('WRONG_ID'):
-                       $message .= getMessage('LOGIN_WRONG_ID');
-                       break;
-
-               case getCode('ID_LOCKED'):
-                       $message .= getMessage('LOGIN_ID_LOCKED');
-                       break;
+       // Convert the code to message
+       $message .= getMessageFromErrorCode($errorCode);
 
-               case getCode('ID_UNCONFIRMED'):
-                       $message .= getMessage('LOGIN_ID_UNCONFIRMED');
-                       break;
-
-               case getCode('NO_COOKIES'):
-                       $message .= getMessage('LOGIN_NO_COOKIES');
-                       break;
-
-               case getCode('EXTENSION_PROBLEM'):
-                       if (IS_ADMIN()) {
-                               $message .= sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'nickname');
-                       } else {
-                               $message .= getMessage('LOGIN_WRONG_ID');
-                       }
-                       break;
-
-               default:
-                       DEBUG_LOG(__FILE__, __LINE__, sprintf("Unhandled error code %s detected.", $errorCode));
-                       $message .= getMessage('LOGIN_WRONG_ID');
-                       break;
-               }
-               $message .= "</span>
+       // Continue with HTML
+       $message .= "</span>
   </td>
   <td width=\"10\" class=\"seperator\">&nbsp;</td>
 </tr>\n";
-               define('LOGIN_FAILURE_MSG', $message);
-} 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)) {
        // URL was constructed
-       if (getTotalFatalErrors()) {
-               // Fatal errors!
-               loadIncludeOnce('inc/fatal_errors.php');
+       if (getTotalFatalErrors() > 0) {
+               // Handle fatal errors
+               runFilterChain('handle_fatal_errors');
        } else {
                // Load URL
                redirectToUrl($URL);
        }
 } // END - if
 
-//
+// [EOF]
 ?>