Installation improved, first login:
[mailer.git] / inc / modules / admin.php
index 806035c..8b22bcb 100644 (file)
@@ -53,13 +53,13 @@ $ret = 'init';
 // Is no admin registered?
 if (!isAdminRegistered()) {
        // Admin is not registered so we have to inform the user
-       if ((isFormSent()) && ((!isPostRequestElementSet('login')) || (!isPostRequestElementSet('pass')) || (strlen(postRequestElement('pass')) < 4))) {
+       if ((isFormSent()) && ((!isPostRequestElementSet('login')) || (!isPostRequestElementSet('pass1')) || (strlen(postRequestElement('pass1')) < 4) || (!isPostRequestElementSet('pass2')) || (strlen(postRequestElement('pass2')) < 4) || (postRequestElement('pass1') != postRequestElement('pass2')))) {
                setRequestPostElement('ok', '***');
        } // END - if
 
        if ((isFormSent()) && (postRequestElement('ok') != '***')) {
                // Hash the password with the old function because we are here in install mode
-               $hashedPass = md5(postRequestElement('pass'));
+               $hashedPass = md5(postRequestElement('pass1'));
 
                // Kill maybe existing session variables
                destroyAdminSession(false);
@@ -79,37 +79,24 @@ if (!isAdminRegistered()) {
                                }
                                break;
 
-                       case 'failed':
+                       case 'failed': // Registration has failed
                                $ret = getMessage('ADMIN_REGISTER_FAILED');
                                break;
 
-                       case 'already':
-                       default:
-                               if ($ret == 'already') {
-                                       // Admin does already exists!
-                                       $ret = getMessage('ADMIN_LOGIN_ALREADY_REG');
-                               } else {
-                                       // Any other kind will be logged and interpreted as 'done'
-                                       logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminLoginDataIsValid() and interpreted as 'done'!", $ret));
-                                       // @TODO Why is this set to 'done'?
-                                       $ret = 'done';
-                               }
-
-                               // Admin still not registered?
-                               if (!isAdminRegistered()) {
-                                       // Write to config that registration is done
-                                       changeDataInFile(getConfig('CACHE_PATH') . 'config-local.php', 'ADMIN-SETUP', "setConfigEntry('ADMIN_REGISTERED', '", "');", 'Y', 0);
+                       case 'already': // Admin does already exists!
+                               $ret = getMessage('ADMIN_LOGIN_ALREADY_REG');
+                               break;
 
-                                       // Load URL for login
-                                       redirectToUrl('admin.php');
-                               } // END - if
+                       default:
+                               // Any other kind will be logged
+                               logDebugMessage(__FILE__, __LINE__, sprintf("Unknown return code %s from ifAdminLoginDataIsValid().", $ret));
                                break;
                } // END - switch
-       }
+       } // END - if
 
        // Whas that action okay?
        if ($ret != 'done') {
-               // Fixes another notice
+               // Init login name
                $content['login'] = '';
                if (isPostRequestElementSet('login')) {
                        $content['login'] = postRequestElement('login');
@@ -117,28 +104,41 @@ if (!isAdminRegistered()) {
 
                // Init array elements
                $content['login_message']   = '';
-               $content['pass_message']    = '';
+               $content['pass1_message']    = '';
+               $content['pass2_message']    = '';
 
                // Yet-another notice-fix
                if ((isFormSent()) && (postRequestElement('ok') == '***')) {
+                       // Init variables
+                       $loginMessage = '';
+                       $pass1Message = '';
+                       $pass2Message = '';
+
                        // No login entered?
-                       if (!isPostRequestElementSet('login')) $loginMessage = getMessage('ADMIN_NO_LOGIN');
+                       if (empty($content['login'])) $loginMessage = getMessage('ADMIN_NO_LOGIN');
 
                        // An error comes back from registration?
-                       if (!empty($ret)) $loginMessage = $ret;
+                       if ((!empty($ret)) && ($ret != 'init')) $loginMessage = $ret;
 
-                       // No password entered?
-                       if (!isPostRequestElementSet('pass')) $passwdMessage = getMessage('ADMIN_NO_PASS');
+                       // No password 1 entered or to short?
+                       if (!isPostRequestElementSet('pass1')) $pass1Message = getMessage('ADMIN_NO_PASS1');
+                        elseif (strlen(postRequestElement('pass1')) < 4) $pass1Message = getMessage('ADMIN_SHORT_PASS1');
 
-                       // Or password too short?
-                       if (strlen(postRequestElement('pass')) < 4) $passwdMessage = getMessage('ADMIN_SHORT_PASS');
+                       // No password 2 entered or to short?
+                       if (!isPostRequestElementSet('pass2')) $pass2Message = getMessage('ADMIN_NO_PASS2');
+                        elseif (strlen(postRequestElement('pass2')) < 4) $pass2Message = getMessage('ADMIN_SHORT_PASS2');
+
+                       // Both didn't match?
+                       if (postRequestElement('pass1') != postRequestElement('pass2')) {
+                               // No match
+                               if (empty($pass1Message)) $pass1Message = getMessage('ADMIN_PASS1_MISMATCH');
+                               if (empty($pass2Message)) $pass2Message = getMessage('ADMIN_PASS2_MISMATCH');
+                       } // END - if
 
                        // Output error messages
                        $content['login_message'] = loadTemplate('admin_login_msg', true, $loginMessage);
-                       $content['pass_message']  = loadTemplate('admin_login_msg', true, $passwdMessage);
-
-                       // Reset variables
-                       $loginMessage = ''; $passwdMessage = '';
+                       $content['pass1_message'] = loadTemplate('admin_login_msg', true, $pass1Message);
+                       $content['pass2_message'] = loadTemplate('admin_login_msg', true, $pass2Message);
                } // END - if
 
                // Output message in seperate template