Форуми / National / Russian / Тех. поддержка / Запросы документации

Принимаем вопросы от населения

Kopusha
#46734 30.05.2023 09:32

1. в users/inc/ создаем users.ajax.php
 

PHP
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
<?php
defined('COT_CODE') or die('Wrong URL');
global $db_users, $db;
include_once cot_incfile("users", "module");
$a = cot_import('a', 'G', 'TXT');
$m = cot_import("m", "G", "TXT");
$login = cot_import("login", "G", "TXT");
$email = cot_import("email", "G", "TXT");
$data["success"] = false;
 
if ($a == "checklogin") {
    $user_exists = (bool)cot::$db->query("SELECT user_id FROM ".cot::$db->users." WHERE user_name = ? LIMIT 1",
        array($login))->fetch();
    $data["text"] = //как отработать оповещение, у каждого свое
    $data["user_exists"] = $user_exists;
    print json_encode($data);
}
 
if ($a == "checkemail") {
    $email_exists = (bool)cot::$db->query("SELECT user_id FROM ".cot::$db->users." WHERE user_email = ? LIMIT 1",
        array($email))->fetch();
    $data["text"] = //как отработать оповещение, у каждого свое
    $data["email_exists"] = $email_exists;
    print json_encode($data);
}

в корне users - users.rc.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
/* ====================
  [BEGIN_COT_EXT]
  Hooks=rc
  Order=9999
  [END_COT_EXT]
  ==================== */
 
defined('COT_CODE') or die('Wrong URL');
 
if ($usr['id'] > 0) {
}
else
{
    if ($_GET['e'] == 'users' && $_GET['m'] == 'register') {
        cot_rc_link_footer("modules/users/js/users.js");
    }
}

Далее users/js/users.js

JavaScript
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
$(function () {
        $('#form input:text[name="rusername"]').blur(function() {
                if($(this).val().length>=2)
                {
                    $login = $(this).val();
                    $.ajax({
                        url: 'index.php?e=users&m=ajax&a=checklogin&login=' + $login,
                        method: "GET",
                    }).done(function (h) {
                        d = $.parseJSON(h);
                         
                        if (d.user_exists) {
                            //тут как фронэнд отработает код ошибки
}
                    });
                    return false;
                }
        });
        $('#useremail').blur(function() {
                if($(this).val().length>=2)
                {
                    $email = $(this).val();
                    $.ajax({
                        url: 'index.php?e=users&m=ajax&a=checkemail&email=' + $email,
                        method: "GET",
                    }).done(function (h) {
                        d = $.parseJSON(h);
                         
                        if (d.email_exists) {
                            //тут как фронэнд отработает код ошибки
                            $('.email input').parent().removeClass('success');
                        }
                        else
                        {
                            //email validation
                            var regex = new RegExp(
                                '^(([^<>()[\\]\\\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\"]+)*)|' +
                                '(\\".+\\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])' +
                                '|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$'
                            );
                            $('.email input').on('keyup', function(e) {
                                $(this).parent().toggleClass('success', regex.test($(this).val()));
                            });
}
});
                    return false;
                }
        });
});

вроде бы все, выдирал с рабочего проекта где много другого, может что и забыл

модуль есесно обновить