Заготовка. Авторизация Битрикс. main.auth.form


Вызов компонента

<?$APPLICATION->IncludeComponent("bitrix:main.auth.form", "flat", Array(
    "AUTH_FORGOT_PASSWORD_URL" => "/personal/auth/getpass.php?forgot_password=yes", // Страница для восстановления пароля
        "AUTH_REGISTER_URL" => "/personal/auth/registration.php",   // Страница для регистрации
        "AUTH_SUCCESS_URL" => "/personal/index.php",    // Страница после успешной авторизации
    ),
    false
);?>

template.php

<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) {
    die();
}

use Bitrix\Main\Localization\Loc;

Loc::loadMessages(__FILE__);

if ($arResult['AUTHORIZED']) {
    echo Loc::getMessage('MAIN_AUTH_FORM_SUCCESS');
    return;
}
?>

<div class="auth-form">
    <div class="container">
        <div class="auth-form__inner">
            <div class="auth-form__header d-none">
                <h3 class="auth-form__title"><?=Loc::getMessage('MAIN_AUTH_FORM_HEADER');?></h3>
            </div>

            <? if ($arResult['ERRORS']): ?>
                <div class="auth-form__errors">
                    <? foreach ($arResult['ERRORS'] as $error): ?>
                        <div class="auth-form__error"><?= $error ?></div>
                    <? endforeach; ?>
                </div>
            <? endif; ?>

            <? if ($arResult['AUTH_SERVICES']): ?>
                <div class="auth-form__social">
                    <? $APPLICATION->IncludeComponent(
                        'bitrix:socserv.auth.form',
                        'flat',
                        [
                            'AUTH_SERVICES' => $arResult['AUTH_SERVICES'],
                            'AUTH_URL' => $arResult['CURR_URI'],
                        ],
                        $component,
                        ['HIDE_ICONS' => 'Y']
                    ); ?>
                </div>
                <div class="auth-form__divider">
                    <span class="auth-form__divider-text">или</span>
                </div>
            <? endif ?>

            <form name="<?=$arResult['FORM_ID'];?>" method="post" target="_top" action="<?=POST_FORM_ACTION_URI;?>" class="auth-form__form">

                <div class="auth-form__field form-field">
                    <label class="form-field__label auth-form__label" for="auth_login">
                        <?=Loc::getMessage('MAIN_AUTH_FORM_FIELD_LOGIN');?>
                    </label>
                    <input
                        type="text"
                        id="auth_login"
                        name="<?=$arResult['FIELDS']['login'];?>"
                        maxlength="255"
                        value="<?=\htmlspecialcharsbx($arResult['LAST_LOGIN']);?>"
                        class="form-control auth-form__input"
                        placeholder="Введите логин или email"
                    />
                </div>

                <div class="auth-form__field form-field">
                    <label class="form-field__label auth-form__label" for="auth_password">
                        <?=Loc::getMessage('MAIN_AUTH_FORM_FIELD_PASS');?>
                    </label>
                    <div class="auth-form__password-wrapper">
                        <? if ($arResult['SECURE_AUTH']): ?>
                            <div class="auth-form__secure-note" id="bx_auth_secure" style="display:none">
                                <div class="ui-note">
                                    <span class="auth-form__secure-icon">🔒</span>
                                    <?=Loc::getMessage('MAIN_AUTH_FORM_SECURE_NOTE');?>
                                </div>
                            </div>
                            <script>
                                document.getElementById('bx_auth_secure').style.display = '';
                            </script>
                        <? endif ?>
                        <input
                            type="password"
                            id="auth_password"
                            name="<?=$arResult['FIELDS']['password'];?>"
                            maxlength="255"
                            autocomplete="off"
                            class="form-control auth-form__input"
                            placeholder="Введите пароль"
                        />
                    </div>
                </div>

                <? if ($arResult['CAPTCHA_CODE']): ?>
                    <input type="hidden" name="captcha_sid" value="<?=\htmlspecialcharsbx($arResult['CAPTCHA_CODE']);?>"/>
                    <div class="auth-form__field form-field">
                        <label class="form-field__label auth-form__label" for="captcha_word">
                            <?=Loc::getMessage('MAIN_AUTH_FORM_FIELD_CAPTCHA')?>
                        </label>
                        <div class="auth-form__captcha">
                            <img
                                src="/bitrix/tools/captcha.php?captcha_sid=<?=\htmlspecialcharsbx($arResult['CAPTCHA_CODE']);?>"
                                width="180"
                                height="40"
                                alt="CAPTCHA"
                                class="auth-form__captcha-image"
                            />
                        </div>
                        <input
                            type="text"
                            id="captcha_word"
                            name="captcha_word"
                            maxlength="50"
                            value=""
                            autocomplete="off"
                            class="form-control auth-form__input"
                            placeholder="Введите символы с картинки"
                        />
                    </div>
                <? endif; ?>

                <? if ($arResult['STORE_PASSWORD'] == 'Y'): ?>
                    <div class="auth-form__field form-field auth-form__field form-field--checkbox">
                        <label class="ui-checkbox-label">
                            <input
                                type="checkbox"
                                id="USER_REMEMBER"
                                name="<?=$arResult['FIELDS']['remember'];?>"
                                value="Y"
                            />
                            <span class="ui-checkbox"></span>
                            <span class="ui-checkbox-text"><?=Loc::getMessage('MAIN_AUTH_FORM_FIELD_REMEMBER');?></span>
                        </label>
                    </div>
                <? endif ?>

                <div class="auth-form__submit">
                    <button
                        type="submit"
                        class="btn auth-form__submit-btn"
                    >
                        <?=Loc::getMessage('MAIN_AUTH_FORM_FIELD_SUBMIT');?>
                    </button>
                    <input type="hidden" name="<?= $arResult['FIELDS']['action']?>"
                           value="<?= Loc::getMessage('MAIN_AUTH_FORM_FIELD_SUBMIT')?>" />
                </div>

                <? if ($arResult['AUTH_FORGOT_PASSWORD_URL'] || $arResult['AUTH_REGISTER_URL']): ?>
                    <div class="auth-form__links">
                        <? if ($arResult['AUTH_FORGOT_PASSWORD_URL']): ?>
                            <a href="<?=$arResult['AUTH_FORGOT_PASSWORD_URL'];?>" rel="nofollow" class="btn-link">
                                <?=Loc::getMessage('MAIN_AUTH_FORM_URL_FORGOT_PASSWORD');?>
                            </a>
                        <? endif; ?>
                        <? if ($arResult['AUTH_REGISTER_URL']): ?>
                            <a href="<?=$arResult['AUTH_REGISTER_URL'];?>" rel="nofollow" class="btn-link">
                                <?=Loc::getMessage('MAIN_AUTH_FORM_URL_REGISTER_URL');?>
                            </a>
                        <? endif; ?>
                    </div>
                <? endif; ?>
            </form>
        </div>
    </div>
</div>

<script>
    <?if ($arResult['LAST_LOGIN'] != ''):?>
    try {
        document.getElementById('auth_password').focus();
    } catch (e) {
    }
    <?else:?>
    try {
        document.getElementById('auth_login').focus();
    } catch (e) {
    }
    <?endif?>
</script>

style.css

Стили закинул до кучи, не проверяя. Каждый под себя уже допилит.

/* ОБЩИЕ СТИЛИ */
/* Form fields */
.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-field__checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0;
}

.form-field__label {
    font-weight: 500;
    color: var(--gray-80);
    font-size: 14px;
}

.form-field__input {
    min-height: 44px;
    padding: 12px 16px;
}

/* Form control */
.form-control {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--gray-40);
    border-radius: 6px;
    background-color: var(--white);
    transition: var(--tr25);
    line-height: 1;
}

.form-field .form-control {
    min-height: 42px;
}

.form-control:hover {
    /* border-color: var(--black); */
    border-color: var(--gray-40);
}

.form-control:focus {
    box-shadow: var(--box-shadow-focus);
    outline: none;
}

.form-control::placeholder {
    font-size: 16px;
    font-weight: 400;
    opacity: 1;
    /* color: var(--gray-70); */
    color: var(--gray-50);
    transition: var(--tr25);
}

.form-control:hover::placeholder {
    color: var(--black);
}

.form-control:focus::placeholder {
    font-size: 0;
    opacity: 0;
}

.form-control.error {
    border-color: var(--red);
}

.ui-field-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ui-field-container label {
    flex-shrink: 0;
}

.ui-checkbox-label:has(.error) {
    color: var(--red);
}

/* Form checkbox */
.ui-checkbox {
    display: flex;
    flex-shrink: 0;
    height: 18px;
    width: 18px;
    background: #fff;
    border: 1px solid var(--gray-50);
    border-radius: 4px;
    transition: var(--tr25);
    position: relative;
}

@media (hover: hover) {
    *:hover > .ui-checkbox {
        border-color: var(--black);
    }
}

input:checked + .ui-checkbox {
    border: 1px solid var(--primary);
}

input:checked + .ui-checkbox:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 7px;
    height: 7px;
    background: var(--primary);
}

.ui-checkbox-label input {
    display: none;
}

.ui-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.ui-checkbox-text {
    line-height: 1;
}

/* Form note */
.ui-note,
.note {
    background-color: var(--gray-10);
    border-radius: 6px;
    border: 1px solid var(--gray-20);
    padding: 10px 20px;
    margin: 1em 0;
}
.ui-note {
    display: flex;
    align-items: center;
}

.note p {
    margin-bottom: 5px;
}

/* СТИЛИ КОМПОНЕНТА */
.auth-form__inner {
    max-width: 380px;
}

.auth-form__header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-form__title {
    color: var(--primary);
    margin-bottom: 0;
    font-family: var(--extra-font), sans-serif;
    font-weight: 700;
}

.auth-form__errors {
    margin-bottom: 20px;
}

.auth-form__error {
    background-color: rgba(209, 92, 92, 0.1);
    border: 1px solid var(--red);
    border-radius: 6px;
    padding: 12px 16px;
    color: var(--red);
    font-size: 14px;
    margin-bottom: 8px;
}

.auth-form__error:last-child {
    margin-bottom: 0;
}

.auth-form__social {
    margin-bottom: 20px;
}

.auth-form__divider {
    position: relative;
    text-align: center;
    margin: 30px 0;
}

.auth-form__divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background-color: var(--gray-30);
}

.auth-form__divider-text {
    background-color: var(--white);
    padding: 0 16px;
    color: var(--gray-60);
    font-size: 14px;
    position: relative;
    z-index: 1;
}

.auth-form__form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-form__password-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-form__secure-note {
    order: -1;
}

.auth-form__secure-note .ui-note {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    background-color: rgba(74, 157, 126, 0.1);
    border-color: var(--green);
    color: var(--green-active);
}

.auth-form__secure-icon {
    font-size: 16px;
}

.auth-form__captcha {
    margin-bottom: 8px;
}

.auth-form__captcha-image {
    border-radius: 6px;
    border: 1px solid var(--gray-30);
}

.auth-form__submit {
    margin-top: 10px;
}

.auth-form__submit-btn {
    width: 100%;
    min-height: 48px;
    font-weight: 600;
    font-size: 16px;
}

.auth-form__links {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-20);
}

@media (max-width: 768px) {
    .auth-form {
        padding: 40px 0;
    }

    .auth-form__inner {
        margin: 0 20px;
        padding: 30px 20px;
    }

    .auth-form__links {
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .auth-form__inner {
        margin: 0 10px;
        padding: 24px 16px;
    }

    .auth-form__title {
        font-size: 20px;
    }
}

.auth-form .ui-checkbox-label {
    margin-top: 4px;
}

.auth-form__submit-btn._loader {
    background-color: var(--primary-light);
}

.auth-form__submit-btn._loader:after {
    border-color: rgba(255, 255, 255, 0.3);
    border-bottom-color: var(--white);
}