Exemplo n.º 1
0
        $userData['last_modified'] = PMF_Filter::filterInput(INPUT_POST, 'last_modified', FILTER_SANITIZE_STRING, '');
        $userStatus = PMF_Filter::filterInput(INPUT_POST, 'user_status', FILTER_SANITIZE_STRING, $defaultUserStatus);
        $user = new PMF_User();
        $user->getUserById($userId);
        $stats = $user->getStatus();
        // set new password an send email if user is switched to active
        if ($stats == 'blocked' && $userStatus == 'active') {
            $consonants = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
            $vowels = array("a", "e", "i", "o", "u");
            $newPassword = '';
            srand((double) microtime() * 1000000);
            for ($i = 1; $i <= 4; $i++) {
                $newPassword .= $consonants[rand(0, 19)];
                $newPassword .= $vowels[rand(0, 4)];
            }
            $user->changePassword($newPassword);
            $mail = new PMF_Mail();
            $mail->addTo($userData['email']);
            $mail->subject = '[%sitename%] Username / activation';
            $mail->message = sprintf("\nUsername: %s\nLoginname: %s\nNew Password: %s\n\n", $userData['display_name'], $user->getLogin(), $newPassword);
            $result = $mail->send();
            unset($mail);
        }
        if (!$user->userdata->set(array_keys($userData), array_values($userData)) or !$user->setStatus($userStatus)) {
            $message .= '<p class="error">' . $errorMessages['updateUser'] . '</p>';
        } else {
            $message .= '<p class="success">' . sprintf($successMessages['updateUser'], $user->getLogin()) . '</p>';
            $message .= '<script type="text/javascript">updateUser(' . $userId . ');</script>';
        }
    }
}