1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 
<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines http://www.simplemachines.org
 * @copyright 2019 Simple Machines and individual contributors
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.1 RC1
 */

/**
 * This is just the basic "login" form.
 */
function template_login()
{
    global $context, $settings, $scripturl, $modSettings, $txt;

    echo '
        <div class="login">
            <div class="cat_bar">
                <h3 class="catbg">
                    <img src="', $settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> ', $txt['login'], '
                </h3>
            </div>
            <div class="roundframe">
                <form class="login" action="', $context['login_url'], '" name="frmLogin" id="frmLogin" method="post" accept-charset="', $context['character_set'], '">';

    // Did they make a mistake last time?
    if (!empty($context['login_errors']))
        echo '
                    <div class="errorbox">', implode('<br>', $context['login_errors']), '</div>
                    <br>';

    // Or perhaps there's some special description for this time?
    if (isset($context['description']))
        echo '
                    <div class="information">', $context['description'], '</div>';

    // Now just get the basic information - username, password, etc.
    echo '
                    <dl>
                        <dt>', $txt['username'], ':</dt>
                        <dd>
                            <input type="text" id="', !empty($context['from_ajax']) ? 'ajax_' : '', 'loginuser" name="user" size="20" value="', $context['default_username'], '">
                        </dd>
                        <dt>', $txt['password'], ':</dt>
                        <dd>
                            <input type="password" id="', !empty($context['from_ajax']) ? 'ajax_' : '', 'loginpass" name="passwrd" value="', $context['default_password'], '" size="20">
                        </dd>
                    </dl>
                    <dl>
                        <dt>', $txt['time_logged_in'], ':</dt>
                        <dd>
                            <select name="cookielength" id="cookielength">';

    foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
        echo '
                                <option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

    echo '
                            </select>
                        </dd>';

    // If they have deleted their account, give them a chance to change their mind.
    if (isset($context['login_show_undelete']))
        echo '
                        <dt class="alert">', $txt['undelete_account'], ':</dt>
                        <dd><input type="checkbox" name="undelete"></dd>';

    echo '
                    </dl>
                    <p>
                        <input type="submit" value="', $txt['login'], '" class="button">
                    </p>
                    <p class="smalltext">
                        <a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a>
                    </p>
                    <input type="hidden" name="hash_passwrd" value="">
                    <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
                    <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
                    <script>
                        setTimeout(function() {
                            document.getElementById("', !empty($context['from_ajax']) ? 'ajax_' : '', isset($context['default_username']) && $context['default_username'] != '' ? 'loginpass' : 'loginuser', '").focus();
                        }, 150);';

    if (!empty($context['from_ajax']))
        echo '
                        form = $("#frmLogin");
                        form.submit(function(e) {
                            e.preventDefault();
                            e.stopPropagation();

                            $.ajax({
                                url: form.prop("action"),
                                method: "POST",
                                data: form.serialize(),
                                success: function(data) {
                                    if (data.indexOf("<bo" + "dy") > -1) {
                                        document.open();
                                        document.write(data);
                                        document.close();
                                    }
                                    else
                                        form.parent().html($(data).find(".roundframe").html());
                                },
                                error: function(xhr) {
                                    var data = xhr.responseText;
                                    if (data.indexOf("<bo" + "dy") > -1) {
                                        document.open();
                                        document.write(data);
                                        document.close();
                                    }
                                    else
                                        form.parent().html($(data).filter("#fatal_error").html());
                                }
                            });

                            return false;
                        });';

    echo '
                    </script>
                </form>';

    // It is a long story as to why we have this when we're clearly not going to use it.
    if (!empty($context['from_ajax']))
        echo '
                <br>
                <a href="javascript:self.close();"></a>';

    echo '
            </div><!-- .roundframe -->
        </div><!-- .login -->';
}

/**
 * TFA authentication form
 */
function template_login_tfa()
{
    global $context, $scripturl, $txt;

    echo '
        <div class="login">
            <div class="cat_bar">
                <h3 class="catbg">
                    ', $txt['tfa_profile_label'], '
                </h3>
            </div>
            <div class="roundframe">';

    if (!empty($context['tfa_error']) || !empty($context['tfa_backup_error']))
        echo '
                <div class="error">
                    ', $txt['tfa_' . (!empty($context['tfa_error']) ? 'code_' : 'backup_') . 'invalid'], '
                </div>';

    echo '
                <form action="', $context['tfa_url'], '" method="post" id="frmTfa">
                    <div id="tfaCode">
                        <p style="margin-bottom: 0.5em">', $txt['tfa_login_desc'], '</p>
                        <div class="centertext">
                            <strong>', $txt['tfa_code'], ':</strong>
                            <input type="text" name="tfa_code" value="', !empty($context['tfa_value']) ? $context['tfa_value'] : '', '">
                            <input type="submit" class="button" name="submit" value="', $txt['login'], '">
                        </div>
                        <hr>
                        <div class="centertext">
                            <input type="button" class="button" name="backup" value="', $txt['tfa_backup'], '">
                        </div>
                    </div>
                    <div id="tfaBackup" style="display: none;">
                        <p style="margin-bottom: 0.5em">', $txt['tfa_backup_desc'], '</p>
                        <div class="centertext">
                            <strong>', $txt['tfa_backup_code'], ': </strong>
                            <input type="text" name="tfa_backup" value="', !empty($context['tfa_backup']) ? $context['tfa_backup'] : '', '">
                            <input type="submit" class="button" name="submit" value="', $txt['login'], '">
                        </div>
                    </div>
                </form>
                <script>
                    form = $("#frmTfa");';

    if (!empty($context['from_ajax']))
        echo '
                    form.submit(function(e) {
                        // If we are submitting backup code, let normal workflow follow since it redirects a couple times into a different page
                        if (form.find("input[name=tfa_backup]:first").val().length > 0)
                            return true;

                        e.preventDefault();
                        e.stopPropagation();

                        $.post(form.prop("action"), form.serialize(), function(data) {
                            if (data.indexOf("<bo" + "dy") > -1)
                                document.location = ', JavaScriptEscape(!empty($_SESSION['login_url']) ? $_SESSION['login_url'] : $scripturl), ';
                            else {
                                form.parent().html($(data).find(".roundframe").html());
                            }
                        });

                        return false;
                    });';

    echo '
                    form.find("input[name=backup]").click(function(e) {
                        $("#tfaBackup").show();
                        $("#tfaCode").hide();
                    });
                </script>
            </div><!-- .roundframe -->
        </div><!-- .login -->';
}

/**
 * Tell a guest to get lost or login!
 */
function template_kick_guest()
{
    global $context, $settings, $scripturl, $modSettings, $txt;

    // This isn't that much... just like normal login but with a message at the top.
    echo '
    <form action="', $context['login_url'], '" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin">
        <div class="login">
            <div class="cat_bar">
                <h3 class="catbg">', $txt['warning'], '</h3>
            </div>';

    // Show the message or default message.
    echo '
            <p class="information centertext">
                ', empty($context['kick_message']) ? $txt['only_members_can_access'] : $context['kick_message'], '<br>';

    if ($context['can_register'])
        echo sprintf($txt['login_below_or_register'], $scripturl . '?action=signup', $context['forum_name_html_safe']);
    else
        echo $txt['login_below'];

    // And now the login information.
    echo '
            <div class="cat_bar">
                <h3 class="catbg">
                    <img src="', $settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> ', $txt['login'], '
                </h3>
            </div>
            <div class="roundframe">
                <dl>
                    <dt>', $txt['username'], ':</dt>
                    <dd><input type="text" name="user" size="20"></dd>
                    <dt>', $txt['password'], ':</dt>
                    <dd><input type="password" name="passwrd" size="20"></dd>
                    <dt>', $txt['time_logged_in'], ':</dt>
                    <dd>
                            <select name="cookielength" id="cookielength">';

    foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
        echo '
                                <option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

    echo '
                            </select>
                    </dd>
                </dl>
                <p class="centertext">
                    <input type="submit" value="', $txt['login'], '" class="button">
                </p>
                <p class="centertext smalltext">
                    <a href="', $scripturl, '?action=reminder">', $txt['forgot_your_password'], '</a>
                </p>
            </div>
            <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
            <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
            <input type="hidden" name="hash_passwrd" value="">
        </div><!-- .login -->
    </form>';

    // Do the focus thing...
    echo '
    <script>
        document.forms.frmLogin.user.focus();
    </script>';
}

/**
 * This is for maintenance mode.
 */
function template_maintenance()
{
    global $context, $settings, $txt, $modSettings;

    // Display the administrator's message at the top.
    echo '
    <form action="', $context['login_url'], '" method="post" accept-charset="', $context['character_set'], '">
        <div class="login" id="maintenance_mode">
            <div class="cat_bar">
                <h3 class="catbg">', $context['title'], '</h3>
            </div>
            <div class="information">
                <img class="floatleft" src="', $settings['images_url'], '/construction.png" width="40" height="40" alt="', $txt['in_maintain_mode'], '">
                ', $context['description'], '<br class="clear">
            </div>
            <div class="title_bar">
                <h4 class="titlebg">', $txt['admin_login'], '</h4>
            </div>
            <div class="roundframe">
                <dl>
                    <dt>', $txt['username'], ':</dt>
                    <dd><input type="text" name="user" size="20"></dd>
                    <dt>', $txt['password'], ':</dt>
                    <dd><input type="password" name="passwrd" size="20"></dd>
                    <dt>', $txt['time_logged_in'], ':</dt>
                    <dd>
                            <select name="cookielength" id="cookielength">';

    foreach ($context['login_cookie_times'] as $cookie_time => $cookie_txt)
        echo '
                                <option value="', $cookie_time, '"', $modSettings['cookieTime'] == $cookie_time ? ' selected' : '', '>', $txt[$cookie_txt], '</option>';

    echo '
                            </select>
                    </dd>
                </dl>
                <input type="submit" value="', $txt['login'], '" class="button">
                <br class="clear">
            </div>
            <input type="hidden" name="hash_passwrd" value="">
            <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
            <input type="hidden" name="', $context['login_token_var'], '" value="', $context['login_token'], '">
        </div><!-- #maintenance_mode -->
    </form>';
}

/**
 * This is for the security stuff - makes administrators login every so often.
 */
function template_admin_login()
{
    global $context, $settings, $scripturl, $txt, $modSettings;

    // Since this should redirect to whatever they were doing, send all the get data.
    echo '
    <form action="', !empty($modSettings['force_ssl']) ? strtr($scripturl, array('http://' => 'https://')) : $scripturl, $context['get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="frmLogin" id="frmLogin">
        <div class="login" id="admin_login">
            <div class="cat_bar">
                <h3 class="catbg">
                    <img src="', $settings['images_url'], '/icons/login_hd.png" alt="" class="icon"> ', $txt['login'], '
                </h3>
            </div>
            <div class="roundframe centertext">';

    if (!empty($context['incorrect_password']))
        echo '
                <div class="error">', $txt['admin_incorrect_password'], '</div>';

    echo '
                <strong>', $txt['password'], ':</strong>
                <input type="password" name="', $context['sessionCheckType'], '_pass" size="24">
                <a href="', $scripturl, '?action=helpadmin;help=securityDisable_why" onclick="return reqOverlayDiv(this.href);" class="help"><span class="main_icons help" title="', $txt['help'], '"></span></a><br>
                <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '">
                <input type="hidden" name="', $context['admin-login_token_var'], '" value="', $context['admin-login_token'], '">
                <input type="submit" value="', $txt['login'], '" class="button">';

    // Make sure to output all the old post data.
    echo $context['post_data'], '
            </div><!-- .roundframe -->
        </div><!-- #admin_login -->
        <input type="hidden" name="', $context['sessionCheckType'], '_hash_pass" value="">
    </form>';

    // Focus on the password box.
    echo '
    <script>
        document.forms.frmLogin.', $context['sessionCheckType'], '_pass.focus();
    </script>';
}

/**
 * Activate your account manually?
 */
function template_retry_activate()
{
    global $context, $txt, $scripturl;

    // Just ask them for their code so they can try it again...
    echo '
        <form action="', $scripturl, '?action=activate;u=', $context['member_id'], '" method="post" accept-charset="', $context['character_set'], '">
            <div class="title_bar">
                <h3 class="titlebg">', $context['page_title'], '</h3>
            </div>
            <div class="roundframe">
                <dl>';

    // You didn't even have an ID?
    if (empty($context['member_id']))
        echo '
                    <dt>', $txt['invalid_activation_username'], ':</dt>
                    <dd><input type="text" name="user" size="30"></dd>';

    echo '
                    <dt>', $txt['invalid_activation_retry'], ':</dt>
                    <dd><input type="text" name="code" size="30"></dd>
                </dl>
                <p><input type="submit" value="', $txt['invalid_activation_submit'], '" class="button"></p>
            </div>
        </form>';
}

/**
 * The form for resending the activation code.
 */
function template_resend()
{
    global $context, $txt, $scripturl;

    // Just ask them for their code so they can try it again...
    echo '
        <form action="', $scripturl, '?action=activate;sa=resend" method="post" accept-charset="', $context['character_set'], '">
            <div class="title_bar">
                <h3 class="titlebg">', $context['page_title'], '</h3>
            </div>
            <div class="roundframe">
                <dl>
                    <dt>', $txt['invalid_activation_username'], ':</dt>
                    <dd><input type="text" name="user" size="40" value="', $context['default_username'], '"></dd>
                </dl>
                <p>', $txt['invalid_activation_new'], '</p>
                <dl>
                    <dt>', $txt['invalid_activation_new_email'], ':</dt>
                    <dd><input type="text" name="new_email" size="40"></dd>
                    <dt>', $txt['invalid_activation_password'], ':</dt>
                    <dd><input type="password" name="passwd" size="30"></dd>
                </dl>';

    if ($context['can_activate'])
        echo '
                <p>', $txt['invalid_activation_known'], '</p>
                <dl>
                    <dt>', $txt['invalid_activation_retry'], ':</dt>
                    <dd><input type="text" name="code" size="30"></dd>
                </dl>';

    echo '
                <p><input type="submit" value="', $txt['invalid_activation_resend'], '" class="button"></p>
            </div><!-- .roundframe -->
        </form>';
}

?>